gokitty1199 225 Posted May 18, 2018 i have a global variable called award created in the initPlayerLocal and the player earns awards for a certain task(think of it as money). when the player is killed i want it to drop money on the dead players location and give that money an addAction for others players to take. when another player clicks the addAction i want the player that clicked it to gain the award money that the dead player dropped. pretty much like in life servers how the money on a player drops when he is killed and others can take it. it throws a unknown variable error(which i know why but cant figure out how to get around it). ive never used set/getVariable before so im unsure if that would be of use? i need to learn it, heres my onPlayerKilled.sqf _unit = (_this select 0); _amount = award; _money = "Land_Money_F"; _pos = getPos _unit; removeAllWeapons _unit; removeAllItems _unit; removeBackpack _unit; _handle = _money createVehicle [0, 0, 0]; _handle setPos _pos; [_handle, ["Take Award", {award = award + _amount; hint format["You have found %1 dollars", _amount]; deleteVehicle (_this select 0)}, [], 6, false, true, "(side player == RESISTANCE", "_this distance _target < 2.5"]] remoteExec ["addAction", 0, true]; [_handle, ["Take Money To Evidence", {deleteVehicle (_this select 0)}, [], 6, false, true, "(side player == WEST", "_this distance _target < 2.5"]] remoteExec ["addAction", 0, true]; Share this post Link to post Share on other sites
KC Grimes 79 Posted May 18, 2018 Use setVariable and getVariable, and have public set to "true". This will not only fix your current issue, but also give you more leg room going forward (doing pretty much anything between machines involving this award money). 1 1 Share this post Link to post Share on other sites
gokitty1199 225 Posted May 18, 2018 29 minutes ago, KC Grimes said: Use setVariable and getVariable, and have public set to "true". This will not only fix your current issue, but also give you more leg room going forward (doing pretty much anything between machines involving this award money). thank you, right after posted i looked up get/set variable and came up with this _unit = (_this select 0); _money = "Land_Money_F"; _pos = getPos _unit; removeAllWeapons _unit; removeAllItems _unit; removeBackpack _unit; _handle = _money createVehicle [0, 0, 0]; _handle setPos _pos; _handle setVariable ["amount", award]; [_handle, ["Take Award", {_amount = (_this select 0) getVariable "amount"; award = award + _amount; hint format["You have found %1 dollars", _amount]; deleteVehicle (_this select 0)}, [], 6, false, true, "(side player == RESISTANCE", "_this distance _target < 2.5"]] remoteExec ["addAction", 0, true]; [_handle, ["Take Money To Evidence", {deleteVehicle (_this select 0)}, [], 6, false, true, "(side player == WEST", "_this distance _target < 2.5"]] remoteExec ["addAction", 0, true]; it works, seems very useful as you said. please tell me if i am understanding this right. it sets a variable that is local to _handle/the money object's namespace, then when someone presses the addAction it gets the variable from the _handle/money object's namespace and stores it in a local variable that can be accessed by the player to use in the rest of the script inside of the addAction? Share this post Link to post Share on other sites
Grumpy Old Man 3546 Posted May 18, 2018 _handle is just a variable that points towards the spawned money object. It can be named _myMoneyPile, _madStacks or whatever you want, it just serves readability, doesn't have to be named _handle. setVariable/getVariable are incredibly powerful commands, they can be used to save variables inside objects, like on your spawned money pile, or save variables into specific namespaces (missionNamespace being the most commonly used one) and broadcast these values using the last parameter set to true. You can also use those commands on groups, tasks, UI controls/displays, locations and whatnot. Another positive aspect of those commands is that getVariable can return a default if the variable doesn't yet exist on the object/namespace, as showcased on the wiki page. As a general advice it's good practice to stick to your own naming conventions, especially for global variables, something like "award" could conflict with third party scripts or scripts required by mods, so it's best to use something like GOK_int_award, so you can see at first glance what kind of value this variable is holding (int) and what it's used for (award). Definitely helps others to go through your scripts if you need help, also if you come back to a project after a prolonged break. As to your random question, try this: [_handle, ["Take Award", {_amount = (_this select 0) getVariable "amount"; award = award + _amount; hint format["You have found %1 dollars", _amount]; deleteVehicle (_this select 0)}, [], 6, false, true,"", "side player == RESISTANCE AND _this distance _target < 2.5"]] remoteExec ["addAction", 0, true]; [_handle, ["Take Money To Evidence", {deleteVehicle (_this select 0)}, [], 6, false, true,"", "side player == WEST AND _this distance _target < 2.5"]] remoteExec ["addAction", 0, true]; Your addAction condition parameter was in the spot of the shortcut parameter. Cheers 2 Share this post Link to post Share on other sites
gokitty1199 225 Posted May 18, 2018 2 minutes ago, Grumpy Old Man said: _handle is just a variable that points towards the spawned money object. It can be named _myMoneyPile, _madStacks or whatever you want, it just serves readability, doesn't have to be named _handle. setVariable/getVariable are incredibly powerful commands, they can be used to save variables inside objects, like on your spawned money pile, or save variables into specific namespaces (missionNamespace being the most commonly used one) and broadcast these values using the last parameter set to true. You can also use those commands on groups, tasks, UI controls/displays, locations and whatnot. Another positive aspect of those commands is that getVariable can return a default if the variable doesn't yet exist on the object/namespace, as showcased on the wiki page. As a general advice it's good practice to stick to your own naming conventions, especially for global variables, something like "award" could conflict with third party scripts or scripts required by mods, so it's best to use something like GOK_int_award, so you can see at first glance what kind of value this variable is holding (int) and what it's used for (award). Definitely helps others to go through your scripts if you need help, also if you come back to a project after a prolonged break. Cheers yea _handle was just used since its such a small script, so in arma it acts like a pointer in c++. get/setVariable go way beyond what i thought they did when i first looked at them a year ago, will be giving them a closer look for sure. thank you 1 Share this post Link to post Share on other sites
Grumpy Old Man 3546 Posted May 18, 2018 2 minutes ago, gokitty1199 said: yea _handle was just used since its such a small script, so in arma it acts like a pointer in c++. get/setVariable go way beyond what i thought they did when i first looked at them a year ago, will be giving them a closer look for sure. thank you For some commands it's worth giving them a closer look, especially alternative syntax. select and apply can do pretty neat things. Cheers Share this post Link to post Share on other sites