atmo 29 Posted July 8, 2016 Hi guys, What would be the best way to create a player specific variable at runtime? It might be better if I explain better like so; I want to spawn a "Land_BagFence_Short_F" for the player to rest his weapon on when in a building so that he can stand back from a window and shoot through a 'bolt hole' but I only want to spawn one, and each time he spawns another the previous one will get deleted. (He can also move it around and place it at will). So was thinking in multiplayer I would have to have a unique name for each player's sandbag. eg Player1Bag, Player2Bag... but obviously depends on the ID of the player... the script essentially is (from an addaction) deletevehicle bag; // delete the previous one dropped bag = "Land_BagFence_Short_F" createVehicle position player; bag attachto [player, [0, 1, 0.5]]; bag setVectorDirAndUp [ [1,0,0],[0,0,1] ]; detach bag; I want to initialize 'bag' to be unique for each player... bagplayer1. How do I do this? Or is there a much easier way I completely missing? Also; how do I make it just an outline of a bag until he drops it - therefore not being a mobile shield! Atmo Share this post Link to post Share on other sites
kylania 568 Posted July 8, 2016 initPlayerLocal.sqf: // Declare function for bag deployment fnc_deployBag = { // Check the value of any previous bag, if none default to objNull _previousBag = player getVariable ["atmo_sniperBag", objNull]; // If the previous bag exists, delete it. if (!isNull _previousBag) then {deletevehicle _previousBag}; // Spawn new bag _bag = "Land_BagFence_Short_F" createVehicle [0,0,0]; _bag attachto [player, [0, 1, 0.5]]; _bag setVectorDirAndUp [ [1,0,0],[0,0,1] ]; detach _bag; // Record it's object on the player's variable player setVariable ["atmo_sniperBag", _bag]; }; // Start the game with no bag player setVariable ["atmo_sniperBag", objNull]; // Add the addAction to the player, last on the list no constant title text. player addAction ["Deploy Sniper Bag", {player call fnc_deployBag}, [], 0, false]; Share this post Link to post Share on other sites
atmo 29 Posted July 8, 2016 Ahhh, genius. Thanks dude.. Atmo Share this post Link to post Share on other sites
jshock 513 Posted July 8, 2016 fn_createBagFence = { _newBag = "Land_BagFence_Short_F" createVehicle position player; _newBag attachto [player, [0, 1, 0.5]]; _newBag setVectorDirAndUp [ [1,0,0],[0,0,1] ]; detach _newBag; player setVariable ["playerBag",_newBag]; }; _bag = player getVariable ["playerBag",nil]; if (isNil "_bag") then { [] call fn_createBagFence; } else { deleteVehicle _bag; [] call fn_createBagFence; }; EDIT: Ninja'd :P Share this post Link to post Share on other sites
pawelisus 1 Posted July 12, 2022 How long variables assigned to players are existing. I mean do they get removed when player leaves or they are stored to the momment when server restarts? Share this post Link to post Share on other sites
sarogahtyp 1109 Posted July 12, 2022 Until the player object gets deleted. when this happens depends on garbage collection. Mostly those variables get useless when player dies and have to get reassigned to the new player object after respawning. Share this post Link to post Share on other sites
pawelisus 1 Posted July 13, 2022 Ohhh, that makes a lot of sense, Thanks for the response sarogahtyp. Is there a way to store some data for example integers to user that wont get deleted until server restart? Share this post Link to post Share on other sites
sarogahtyp 1109 Posted July 13, 2022 What you are asking for is not specific enough to help effectively. Just describe your actual mission editing situation, what you want to achieve, what did u try and what problems do u have with it. Also open a new topic for it! Share this post Link to post Share on other sites
pawelisus 1 Posted July 13, 2022 Okay thanks, I've done it here's my topic Share this post Link to post Share on other sites