Search the Community
Showing results for tags 'deadunits'.
Found 1 result
-
Question about Multi-dimensional arrays #2
Prectatorium posted a topic in ARMA 3 - MISSION EDITING & SCRIPTING
Hey guys, Same old, same old, yet another noob looking for clarification. The objective of the script is to: a) after loading map, go through all units, verify which are dead (cuz yeh, in SP you get this, in fact you get units that kill themselves as soon as the map loads, nothing you don't already know), and place a marker on the map. b) every time something is killed, well place a marker on the map. Why? Because reasons... I kid, you all know the camo in this game is too good. Ever spent a couple of minutes looking for a corps to loot that you killed at I don't how many hundreds of meters? Thing is, and as you all know, a dead body is a CIV body. Is this an issue? No, but yes. The issue arises when I attempt to get a color from a unit side, to make the marker that color. It's always "ColorCIV". Closes I've got was this. My approach is to create an array with all units, containing netId and side, them when the EventHandler for "EntityKilled" is triggered, get the id from the unit, cross reference it with the array created at map loading time, to get the side the unit was once apart of. The code is as follows // Create the array of the not yet dead I hope, and each not dead has an array with [ID,SIDE] _unitSidesWhenAlive = []; { _unitSidesWhenAlive set [_forEachIndex, [_x call BIS_fnc_netId, side _x]]; } forEach allUnits; // Create EH to take care of marking for all killed during gameplay addMissionEventHandler ["EntityKilled", { params ["_unit", "_killer", "_instigator"]; if (isNull _instigator) then { _instigator = UAVControl vehicle _killer select 0 }; // UAV/UGV player operated road kill if (isNull _instigator) then { _instigator = _killer }; // player driven vehicle road kill _markerName = str(format ["%1 killed by %2",name _unit, name _killer]); // _sideColor = [side _unit, true] call BIS_fnc_sideColor; // My difficulties start here // An array within an array, attempting to get the index of the array, that contains the array with the units ID and SIDE // That is provided I'm actually contructing the array correctly. _unitNetId = _unit call BIS_fnc_netId; // The ID of unit that triggered "EntityKilled" _unitNetId_Index; // Were I hopefully am able to store the element of the unit's array, within the array contructed at the beginning { _unitNetId_Index = _x findIf { _unitNetId }; // Returns index of the unit's array I hope if (!isnil _unitNetId_Index) exitWith {}; // If the above is right, and we have an index, go no further. Boy does this scripting language } forEach _unitSidesWhenAlive; // have a learning curve // Create a new array to be able to get SIDE from ID _unit_Array = _unitSidesWhenAlive select _unitNetId_Index; // Set the damn color, that of the SIDE the unit used to belong to before it hit the dust _sideColor = [_unit_Array select 1, true] call BIS_fnc_sideColor; _marker = createMarkerLocal [_markerName, position _unit, playerSide call BIS_fnc_sideID, player]; _marker setMarkerAlphaLocal 1; _marker setMarkerColorLocal _sideColor; _marker setMarkerDirLocal (direction _unit); _marker setMarkerShadowLocal false; _marker setMarkerShapeLocal "ICON"; _marker setMarkerSizeLocal [1,1]; _marker setMarkerTextLocal _markerName; _marker setMarkerTypeLocal "hd_dot"; systemChat format ["%1 has been killed by %2", name _unit, name _killer]; // Extract from the log // I guess "_unit_Array select 1" does not return a SIDE? // Error in expression <e _unit, name _killer, side _unit_Array select 1, _sideColor]; // }]; // // { // _kind = ""> // 14:18:54 Error position: <select 1, _sideColor]; // }]; // // { // _kind = ""> // 14:18:54 Error select: Type Side, expected Array,String,Config entry // 14:18:54 File TGF_Init\functions\fn_markOnMapUnitKilled.sqf..., line 33 hint format ["%1 has been killed by %2. %3 color %4", name _unit, name _killer, side _unit_Array select 1, _sideColor]; // line 33 }]; // Mark all the dead after map has loaded // This actually works :) { _kind = ""; switch (true) do { case (_x isKindOf "Car"): {_kind = "Car"}; case (_x isKindOf "Tank"): {_kind = "Tank"}; case (_x isKindOf "Ship"): {_kind = "Ship"}; case (_x isKindOf "Helicopter"): {_kind = "Helicopter"}; case (_x isKindOf "Plane"): {_kind = "Plane"}; default {_kind = ""}; }; _text = ""; _markerType = ""; if (_kind == "") then { _text = "already dead"; _markerType = "KIA"; } else { _text = "already destroyed"; _markerType = "loc_destroy"; }; _markerName = str(format ["%1 " + _text, name _x]); _sideColor = [side _x, true] call BIS_fnc_sideColor; // This here, observation: // Syntax: createMarkerLocal [name, position, channel, creator] // I thought by providing "creator", I would have the ability to remove the markers, but not the case _marker = createMarkerLocal [_markerName, position _x, playerSide call BIS_fnc_sideID, player]; _marker setMarkerAlphaLocal 1; _marker setMarkerColorLocal _sideColor; _marker setMarkerDirLocal (direction _x); _marker setMarkerShadowLocal false; _marker setMarkerShapeLocal "ICON"; _marker setMarkerSizeLocal [1,1]; _marker setMarkerTextLocal _markerName; _marker setMarkerTypeLocal _markerType; systemChat format ["%1 " + _text, name _x]; hint format ["%1 " + _text + "." + "Side %2, color %3", name _x, side _x, _sideColor]; } forEach allDead; So, referencing data that resides in an array, itself in an array is my issue at the moment. Disclaimer: If you say I'm doing it wrong, to me, that much is a given. If you say this is pointless, hey, you clicked the link, you read the post, you know were I'm going with this. I very much do not enjoy this scripting language, the learning curve is... it's $@#% up. I guess until you get to know it... still $@#% up. Thank you.