SelfAction Disable/Enable grass need help

herculys

Member
i'm tring do anything like that in self action, but cant get it work.

Code:
    //Desativar grama
    if (s_player_grama < 0) then {
        s_player_grama = player addaction[("<t color=""#007F0E"">" + ("Desativar grama") +"</t>"),"custom\grama.sqf","",5,false,true,"", ""];
    } else {
        player removeAction s_player_grama;
        s_player_grama = -1;
    };
       
    if (s_player_grama2 < 0) then {
        s_player_grama2 = player addaction[("<t color=""#007F0E"">" + ("Reativar grama") +"</t>"),"custom\grama2.sqf","",5,false,true,"", ""];
    } else {
        player removeAction s_player_grama2;
        s_player_grama2 = -1;
    };


custom\grama.sqf
Code:
player removeAction s_player_grama;
setterraingrid 50;

custom\grama2.sqf
Code:
player removeAction s_player_grama2;
setterraingrid 25;
 
if (s_player_grama < 0) then {
in the top line of your fn_selfactions. Where do you assign s_player_grama to ANY value that can be compared to a number? If you look at the variables.sqf you will see that when the server starts, it loads all those fn_selfaction variables into memory with an initial value. Add yours to that list.
Pj1Uvwq.png
 
after adding "s_player_grama = -1;" and "s_player_grama2 = -1;" in variables, I see the flashing grass menus.
any tip?

 
looking at your code you have
if (s_player_grama < 0) then {

so we are setting it to -1 to begin with in variables, so this is always true and the menu is displayed.

Here is the study body code, compare to yours and see if you can get it straightened out. There is an extra variable at the top which uses the environment variables to decide whether we can show this menu or not. there is a logic error in your code that its showing the menu, then hiding the menu each frame.

Code:
// Study Body
    if (_player_studybody) then {
        if (s_player_studybody < 0) then {
            s_player_studybody = player addAction [localize "str_action_studybody", "\z\addons\dayz_code\actions\study_body.sqf",_cursorTarget, 0, false, true, "",""];
        };
    } else {
        player removeAction s_player_studybody;
        s_player_studybody = -1;
    };

at the bottom of fn_selfactions is this to remove the menu
player removeAction s_player_studybody;
s_player_studybody = -1;

and in the variables.sqf is this
s_player_studybody = -1;


so .... do some copy/replace/paste putting your code into the study body code.
 
Last edited:
nah i really dont know how to get this working, already trying for 5 hours..

fn_selfactions:
Code:
//-----------------------------------------------------------------------------------------

// GRAMA

if (s_player_grama < 0) then {
if (s_player_graminha < 0) then {
    s_player_graminha = player addAction [("<t color=""#00FF21"">" + ("Desativar grama") +"</t>"),"custom\grama.sqf","", 0, false, true, "",""];
};
if (s_player_graminha2 < 0) then {
    s_player_graminha2 = player addAction [("<t color=""#00FF21"">" + ("Ativar grama") +"</t>"),"custom\grama2.sqf","", 0, false, true, "",""];
};

else {
    player removeAction s_player_graminha;
    s_player_graminha = -1;
    player removeAction s_player_graminha2;
    s_player_graminha2 = -1;
    };
};
//-----------------------------------------------------------------------------------------



variables.sqf
Code:
.................
.............
....
    s_player_grama = -1;
    s_player_graminha = -1;
    s_player_graminha2 = -1;
  
};

grama.sqf
Code:
setterraingrid 50;

grama2.sqf
Code:
setterraingrid 25;

and i cant see the menu in game.
 
Your code appears to be stand alone. Usually there is a pre "if" something "then do" something that then defines the next bit. Your script doesn't do this so when you preset the variable to be -1 then its always on but doesn't know what to do. You need to show us what it is looking at there doesn't appear to be a trigger i.e a cursorTarget. I changed your code:
Code:
  //Desativar grama
  _cursorTarget = //something?
    if (s_player_grama < 0) then {
        s_player_grama = player addAction["<t color='#007F0E'>Desativar grama</t>","custom\grama.sqf",_cursorTarget,5,false,true,"", ""];
    } else {
        player removeAction s_player_grama;
        s_player_grama = -1;
    };
    
    if (s_player_grama2 < 0) then {
        s_player_grama2 = player addAction["<t color='#007F0E'>Reativar grama</t>","custom\grama2.sqf",_cursorTarget,5,false,true,"", ""];
    } else {
        player removeAction s_player_grama2;
        s_player_grama2 = -1;
    };
I assume that you want it to trigger the menu when you point at something? add whatever that is where it says: _cursorTarget = //something?
 
I will get this going for you. BSR is correct though, it appears to be more of a standalone script than one that belongs in the selfactions sqf file since it doesnt rely on any environment inputs like cursortarget .. or does it? You are just allowing players to enable/disable grass right? So either there should be an option to enable grass or disable grass at all times. Correct?
 
yes, this is so hard..
for me was more easy do a right click option:
pksOuty.png
Probably the easieist way to do it. For reference my code would look like this:
Code:
//Desativar grama
  _Grass = cursortarget isKindOf "Notebook";
    if (s_player_grama < 0)&& _Grass && (player distance cursorTarget < 5) then {
        s_player_grama = player addAction["<t color='#007F0E'>Desativar grama</t>","custom\grama.sqf", cursortarget,5,false,true,"", ""];
        };
    if (s_player_grama2 < 0)&& _Grass && (player distance cursorTarget < 5) then {
        s_player_grama2 = player addAction["<t color='#007F0E'>Reativar grama</t>","custom\grama2.sqf", cursortarget,5,false,true,"", ""];
        };
    } else {
        player removeAction s_player_grama;
        player removeAction s_player_grama2;
        s_player_grama = -1;
        s_player_grama2 = -1;
    };
You can obviously change the "notebook" to anything you want as long as its an item in the game.
 
Back
Top