Jump to content
y-shin

Need help with scripting (problem with setting variables)

Recommended Posts

Hi,
I'm trying to create script that make players gain/leave access to Zeus on the go, but I'm struggling with a variable.
What I'm trying to do with the code below is to have a player a scroll menu option to gain access to / leave Zeus. When I try to select the scroll menu in-game, an error comes up saying "Undefined variable in expression: _mycuratorplayer".
 

Spoiler

 


private ["_myCuratorPlayer","_myModuleGroup","_myCuratorModule","_myCuratorPosition"];


_myCuratorPlayer = player;

_myModuleGroup = createGroup sideLogic;

_myCuratorModule = "ModuleCurator_F" createUnit [

    getPosATL player,

    _myModuleGroup,

    "this setVariable ['BIS_fnc_initModules_disableAutoActivation', false, true];"

    ]; // Creating Zeus module on the map at player's position.


myfnc_addZeus = {

    [_myCuratorPlayer, _myCuratorModule] remoteExec ["assignCurator",2];

    systemChat "You have gained access to Zeus. Press Y to access Zeus.";

};


myfnc_removeZeus = {

    [_myCuratorPlayer] remoteExec ["unassignCurator",2];

    systemChat "You have lost access to Zeus. To gain access to Zeus, select Become Curator from scroll menu."

};


_myCuratorPlayer addAction ["Become Curator", {call myfnc_addZeus}];

_myCuratorPlayer addAction ["Leave Curator", {call myfnc_removeZeus}];

 

 

 

 

I'm guessing this is the wrong part: _myCuratorPlayer = player; but I don't have enough knowledge what exactly is wrong. Can anyone please guide me what I should do?

 

(Sidenote: I posted pretty much the same thing on reddit but the answers people gave me was to use already existing addons, which will also work. However I want to make my own addon for the community I'm in as my small contribution to it, and that is why I also posted here to get help.)

Share this post


Link to post
Share on other sites
myCuratorModule = "ModuleCurator_F" createUnit [ //Save the module in a global variable known to the client

    getPosATL player,
    createGroup sideLogic,
    "this setVariable ['BIS_fnc_initModules_disableAutoActivation', false, true];"
    ]; // Creating Zeus module on the map at player's position.

myfnc_addZeus = {
    params ["_player"];
    [_player, myCuratorModule] remoteExec ["assignCurator",2];
    systemChat "You have gained access to Zeus. Press Y to access Zeus.";
};


myfnc_removeZeus = {
    params ["_player"];
    [_player] remoteExec ["unassignCurator",2];
    systemChat "You have lost access to Zeus. To gain access to Zeus, select Become Curator from scroll menu."
};


_myCuratorPlayer addAction ["Become Curator", {_this select 1 call myfnc_addZeus}];
_myCuratorPlayer addAction ["Leave Curator", {_this select 1 call myfnc_removeZeus}]; //This select 1 is the player who activates the action

 

  • Like 1

Share this post


Link to post
Share on other sites

Thank you for the reply!

I'm trying your code now but it doesn't seem to work. Maybe because I'm not on dedi server? (I haven't installed dedi server on my PC yet)

Also, the first 3 lines that I wrote above are needed on top of your code? I tried so and it works halfway (there are the scroll menu). The problem is the game seems failing to refer to myCuratorModule. It says 'Undefined variable in expression: mycuratormodule'.

Here's the code I tried, which I copy-pasta your code.
 

Spoiler



private ["_myCuratorPlayer","_myModuleGroup","_myCuratorPosition"];

_myCuratorPlayer = player;
_myModuleGroup = createGroup sideLogic;
myCuratorModule = "ModuleCurator_F" createUnit [ //Save the module in a global variable known to the client
    getPosATL player,
    createGroup sideLogic,
    "this setVariable ['BIS_fnc_initModules_disableAutoActivation', false, true];"
    ]; // Creating Zeus module on the map at player's position.

myfnc_addZeus = {
    params ["_player"];
    [_player, myCuratorModule] remoteExec ["assignCurator",2];
    systemChat "You have gained access to Zeus. Press Y to access Zeus.";
};

myfnc_removeZeus = {
    params ["_player"];
    [_player] remoteExec ["unassignCurator",2];
    systemChat "You have lost access to Zeus. To gain access to Zeus, select Become Curator from scroll menu."
};

_myCuratorPlayer addAction ["Become Curator", {_this select 1 call myfnc_addZeus}];
_myCuratorPlayer addAction ["Leave Curator", {_this select 1 call myfnc_removeZeus}]; //This select 1 is the player who activates the action


 

 

Share this post


Link to post
Share on other sites
5 hours ago, y-shin said:

Thank you for the reply!

I'm trying your code now but it doesn't seem to work. Maybe because I'm not on dedi server? (I haven't installed dedi server on my PC yet)

Also, the first 3 lines that I wrote above are needed on top of your code? I tried so and it works halfway (there are the scroll menu). The problem is the game seems failing to refer to myCuratorModule. It says 'Undefined variable in expression: mycuratormodule'.

Here's the code I tried, which I copy-pasta your code.
 

  Reveal hidden contents

 



private ["_myCuratorPlayer","_myModuleGroup","_myCuratorPosition"];

_myCuratorPlayer = player;
_myModuleGroup = createGroup sideLogic;
myCuratorModule = "ModuleCurator_F" createUnit [ //Save the module in a global variable known to the client
    getPosATL player,
    createGroup sideLogic,
    "this setVariable ['BIS_fnc_initModules_disableAutoActivation', false, true];"
    ]; // Creating Zeus module on the map at player's position.

myfnc_addZeus = {
    params ["_player"];
    [_player, myCuratorModule] remoteExec ["assignCurator",2];
    systemChat "You have gained access to Zeus. Press Y to access Zeus.";
};

myfnc_removeZeus = {
    params ["_player"];
    [_player] remoteExec ["unassignCurator",2];
    systemChat "You have lost access to Zeus. To gain access to Zeus, select Become Curator from scroll menu."
};

_myCuratorPlayer addAction ["Become Curator", {_this select 1 call myfnc_addZeus}];
_myCuratorPlayer addAction ["Leave Curator", {_this select 1 call myfnc_removeZeus}]; //This select 1 is the player who activates the action

 

 

 

 

 

"ModuleCurator_F" createUnit [ //Save the module in a global variable known to the client

    getPosATL player,
    createGroup sideLogic,
    "myCuratorModule = this; this setVariable ['BIS_fnc_initModules_disableAutoActivation', false, true];" //We assign the module to a variable via its init
    ]; // Creating Zeus module on the map at player's position.

myfnc_addZeus = {
    params ["_player"];
    [_player, myCuratorModule] remoteExec ["assignCurator",2];
    systemChat "You have gained access to Zeus. Press Y to access Zeus.";
};


myfnc_removeZeus = {
    params ["_player"];
    [_player] remoteExec ["unassignCurator",2];
    systemChat "You have lost access to Zeus. To gain access to Zeus, select Become Curator from scroll menu."
};


player addAction ["Become Curator", {_this select 1 call myfnc_addZeus}];
player addAction ["Leave Curator", {_this select 1 call myfnc_removeZeus}]; //This select 1 is the player who activates the action

Issue fixed. You were using the createUnit syntax that does not the created unit/object. I am assigning the module to a variable now via its init.

  • Like 1

Share this post


Link to post
Share on other sites

Player has no sense on dedicated. Replace this command by playable units' names.

  • Like 1

Share this post


Link to post
Share on other sites

It worked! Thank you, R3vo!

Though I still don't know what I did wrong lol. I'll keep studying.

 

On 10/5/2021 at 4:13 AM, pierremgi said:

Player has no sense on dedicated. Replace this command by playable units' names.

I want every player on server to be able to have that scroll menu so I guess I'll start digging. Thank you for the advice!

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×