Chuggacharles 7 Posted October 19, 2023 Hello! I'm working on a rather large scale mission that requires the generation of a large number of civilians that are persistent throughout the mission, i've achieved this by storing all the information I need for each civilian in arrays stored as global variables and spawning the civilians dynamicall. One of the values stored in the array is the varName of the unit that is being spawned. For example civ11 would be: _var = ["civ11Unit",[1511.24,5700.52,3.22975],"CUP_C_TK_Man_04_Waist","marker_13","Dave","Civilian"]; //global variable = civ11 Where civ11Unit is the desired varName of the unit whhich would be set by setVehicleVarName after the unit is spawned with createVehicle like so: _civUnit = _grp createUnit [_classname, _pos, [], 0, "NONE"]; _civUnit setVehicleVarName _identifier; The problem i'm encountering is that the varNames of the units when spawned seems to be very inconsistent, most units will return something along these lines C Bravo 4-2:1 And when this happens, all my scripts function perfectly fine, and i can set a custom varName using setVehicleVarName. However some of the units spawned will return as some kind of default like so: bis_o17 Interactions with these objects seems to be very inconsistent but setVehicleVarName no longer works at all and i have instead resorted to using setVariable to establish a global variable with the correct name. This works for most applications but it causes problems when the only reference to the unit is the variable name, for example from an event handler. For example: addMissionEventHandler ["EntityKilled", {params ["_unit", "_killer", "_instigator"]; [_unit, _killer, _instigator] call CH_fnc_entityKilled}]; _unit only references bis_oxx. I'm now quite stuck on how to work around this as the only solution i can think of is to check every global variable set with a civxxunit name and check if it returns the unit, which feels like a bit of a heavy handed solution. I'm wondering if i'm missing something here or if any of you have encountered this problem before and might have some sort of work around? Share this post Link to post Share on other sites
_foley 192 Posted October 19, 2023 Hey If you need to get a name of given unit, you can first set it with _unit setVariable ["name", "civ11Unit"]; and later retrieve it with _unit getVariable "name"; If you need to get a unit given a name, you can maintain a hashmap of all your units _hashMap set ["civ11Unit", _unit]; and later retrieve it with _hashMap get "civ11Unit"; This covers lookup in both directions. 1 1 Share this post Link to post Share on other sites
Chuggacharles 7 Posted October 19, 2023 I was not aware of hashmaps that is an excellent solution thank you! Share this post Link to post Share on other sites
Larrow 2822 Posted October 19, 2023 7 hours ago, Chuggacharles said: setVehicleVarName no longer works at all and i have instead resorted to using setVariable to establish a global variable with the correct name. setVehicleVarName does NOT create a global variable, or allow you to reference said unit by the given name. You also have to setup said global variable. _civUnit = _grp createUnit [_classname, _pos, [], 0, "NONE"]; _civUnit setVehicleVarName _identifier; missionNamespace setVariable[ _identifier, _civUnit, true ]; //OR _civUnit = _grp createUnit [_classname, _pos, [], 0, "NONE"]; _civUnit setVehicleVarName _identifier; [ _civUnit ] call BIS_fnc_objectVar; 2 Share this post Link to post Share on other sites