iV - Ghost 50 Posted October 2, 2017 I try to delete the weapons and items from a faction member (IND_F) after he get killed. I'm using the follow script for deleting by side: // DELETE ALL WEAPONS & AMMO (EAST) if ((side _this == east) and (!isPlayer _this)) then { _this addEventHandler ["Killed", { _this = _this select 0; removeAllWeapons _this; removeAllItems _this; removeAllAssignedItems _this; deleteVehicle (nearestObject [_this, "WeaponHolderSimulated"]); }]; }; I've tried to change side into faction but it won't work: // DELETE ALL WEAPONS & AMMO (IND_F) if ((faction _this == IND_F) and (!isPlayer _this)) then { _this addEventHandler ["Killed", { _this = _this select 0; removeAllWeapons _this; removeAllItems _this; removeAllAssignedItems _this; deleteVehicle (nearestObject [_this, "WeaponHolderSimulated"]); }]; }; Any ideas how it will work? Share this post Link to post Share on other sites
Tajin 349 Posted October 2, 2017 Yes, the factions have to be strings. ---> faction _this == "IND_F" Also, instead of adding eventhandlers to all units you're better off using a mission eventhandler: addMissionEventHandler ["EntityKilled", { params ["_killed", "_killer", "_instigator"]; if (isPlayer _killed) exitWith {}; if (faction _killed == "IND_F") then { removeAllWeapons _killed; removeAllItems _killed; removeAllAssignedItems _killed; deleteVehicle (nearestObject [_killed, "WeaponHolderSimulated"]); }; }]; That way it works for all units in the mission even if they get added afterwards. 1 Share this post Link to post Share on other sites
iV - Ghost 50 Posted October 2, 2017 OK thanks a lot. Is this ok? // DELETE ALL WEAPONS & AMMO addMissionEventHandler ["EntityKilled", { params ["_killed", "_killer", "_instigator"]; if (isPlayer _killed) exitWith {}; // HANDLE AAF if (faction _killed == "IND_F") then { removeAllWeapons _killed; removeAllItems _killed; removeAllAssignedItems _killed; deleteVehicle (nearestObject [_killed, "WeaponHolderSimulated"]); }; // HANDLE CSAT if (faction _killed == "OPF_F") then { removeAllWeapons _killed; removeAllItems _killed; removeAllAssignedItems _killed; deleteVehicle (nearestObject [_killed, "WeaponHolderSimulated"]); }; // HANDLE CSAT PACIFIC if (faction _killed == "OPF_T_F") then { removeAllWeapons _killed; removeAllItems _killed; removeAllAssignedItems _killed; deleteVehicle (nearestObject [_killed, "WeaponHolderSimulated"]); }; // HANDLE NATO if (faction _killed == "BLU_F") then { removeAllWeapons _killed; removeAllItems _killed; removeAllAssignedItems _killed; deleteVehicle (nearestObject [_killed, "WeaponHolderSimulated"]); }; // HANDLE NATO PACIFIC if (faction _killed == "BLU_T_F") then { removeAllWeapons _killed; removeAllItems _killed; removeAllAssignedItems _killed; deleteVehicle (nearestObject [_killed, "WeaponHolderSimulated"]); }; }]; And for what are the params _killer and _instigator? Share this post Link to post Share on other sites
Tajin 349 Posted October 2, 2017 (edited) Oh, I almost forgot you should probably also add this line after the "isPlayer" check: if !(_killed isKindOf "Man") exitWith {}; Just to make sure the EH does not mess around with destroyed vehicles. _killer and _instigator are variables passed by the EH which tell you who killed that entity. https://community.bistudio.com/wiki/Arma_3:_Event_Handlers/addMissionEventHandler#EntityKilled Edited October 4, 2017 by Tajin fixed 1 Share this post Link to post Share on other sites
iV - Ghost 50 Posted October 2, 2017 I get an error and the script will not work. Error !:Type Object, expected Bool Error in expression: if (isPlayer _killed) exitWith {}; if (!_killed isKindOf "Man") exitWith {}; Error position: !_killed isKindOf "Man") exitWith {}; I activate the script in the description.ext: // LOADOUT MANAGEMENT class Extended_Init_EventHandlers { class Man { init = "_this call (compile preprocessFileLineNumbers 'scripts\misc\HandleAi.sqf')"; }; }; So maybe I don't need this? if (!_killed isKindOf "Man") exitWith {}; Share this post Link to post Share on other sites
Lucullus 71 Posted October 2, 2017 change 5 hours ago, iV - Ghost said: if (!_killed isKindOf "Man") exitWith {}; to if !(_killed isKindOf "Man") exitWith {}; 2 Share this post Link to post Share on other sites
Tajin 349 Posted October 4, 2017 woops ;) Oh and be careful there. IF you use my version of the script with the missionEventhandler, then make sure you run it only once from your init (on the server only) and NOT for every unit. You could get massive performance problems otherwise. Share this post Link to post Share on other sites
iV - Ghost 50 Posted October 4, 2017 I activate the script in the description.ext. description.ext // LOADOUT MANAGEMENT class Extended_Init_EventHandlers { class Man { init = "_this call (compile preprocessFileLineNumbers 'scripts\misc\HandleAi.sqf')"; }; }; And this is the script I call HanldeAi.sqf: /* * * Filename: HandleAi.sqf * Description: Forced units to use flashlight, delete weapons and ammo from killed units & reduce the spotting range by night * */ private "_this"; _this = _this select 0; // REMOVE NVG & ADD FLASHLIGHT & REDUCE SPOTTING RANGE (EAST) if ((side _this == east) and (!isPlayer _this)) then { _this unassignItem "NVGoggles_OPFOR"; _this removeItem "NVGoggles_OPFOR"; _this addPrimaryWeaponItem "acc_flashlight"; _this assignItem "acc_flashlight"; _this enableGunLights "ForceOn"; // REDUCE SPOTTING RANGE BY NIGHT _isNight = sunOrMoon; if (_isNight < 1) then { _this setskill ["spotDistance", 0.10]; _this setskill ["spotTime", 0.15]; } }; // ADD FLASHLIGHT & REDUCE SPOTTING RANGE (GUER) if ((side _this == guer) and (!isPlayer _this)) then { _this addPrimaryWeaponItem "acc_flashlight"; _this assignItem "acc_flashlight"; _this enableGunLights "ForceOn"; // REDUCE SPOTTING RANGE BY NIGHT _isNight = sunOrMoon; if (_isNight < 1) then { _this setskill ["spotDistance", 0.10]; _this setskill ["spotTime", 0.15]; } }; // DELETE ALL WEAPONS & AMMO addMissionEventHandler ["EntityKilled", { params ["_killed", "_killer", "_instigator"]; if (isPlayer _killed) exitWith {}; // HANDLE AAF if (faction _killed == "IND_F") then { removeAllWeapons _killed; removeAllItems _killed; removeAllAssignedItems _killed; deleteVehicle (nearestObject [_killed, "WeaponHolderSimulated"]); }; // HANDLE CSAT if (faction _killed == "OPF_F") then { removeAllWeapons _killed; removeAllItems _killed; removeAllAssignedItems _killed; deleteVehicle (nearestObject [_killed, "WeaponHolderSimulated"]); }; // HANDLE CSAT PACIFIC if (faction _killed == "OPF_T_F") then { removeAllWeapons _killed; removeAllItems _killed; removeAllAssignedItems _killed; deleteVehicle (nearestObject [_killed, "WeaponHolderSimulated"]); }; // HANDLE NATO if (faction _killed == "BLU_F") then { removeAllWeapons _killed; removeAllItems _killed; removeAllAssignedItems _killed; deleteVehicle (nearestObject [_killed, "WeaponHolderSimulated"]); }; // HANDLE NATO PACIFIC if (faction _killed == "BLU_T_F") then { removeAllWeapons _killed; removeAllItems _killed; removeAllAssignedItems _killed; deleteVehicle (nearestObject [_killed, "WeaponHolderSimulated"]); }; // HANDLE CIV if (faction _killed == "CIV_F") then { hint format ["%1 tötete einen Zivilisten!", name _killer]; }; }]; Is this OK or should I use the init.sqf for activating? And will it work with ALiVE because the units spawning not all on server start? Share this post Link to post Share on other sites
Tajin 349 Posted October 4, 2017 addMissionEventHandler ["EntityKilled", { This should NEVER go in the init of a unit. It's a global eventhandler that fires for all entitys that get killed. You only need to add this eventhandler once (and normally only on the server itself) !!! If you add it to every unit, then it will fire multiple times which can quickly become really bad for performance. Anyway, in your OT you didn't mention that you use extended EHs to run your code for all spawned units. Therefor you can just as easily use ur original solution instead of mine. Share this post Link to post Share on other sites
iV - Ghost 50 Posted October 4, 2017 Then better make 2 scripts of this (HandleAi.sqf & LootStop.sqf) and activate it seperate? The upper part called HandleAi.sqf in the description.ext and your part called LootStop.sqf in the init.sqf? OK. Now I've making 2 scripts. I can't see any problems with the performance. But one thing I don't understand. In the last part of the script I tried to report killing civs. But everytime I kill a civillian I get another name in the hint and not my own. Starting this script in the init.sqf on my server. /* * * Filename: LootStop.sqf * Description: Delete weapons and ammo from killed units & report killing civ's * */ // DELETE ALL WEAPONS & AMMO addMissionEventHandler ["EntityKilled", { params ["_killed", "_killer", "_instigator"]; if (isPlayer _killed) exitWith {}; if !(_killed isKindOf "Man") exitWith {}; ... // HANDLE CIV if (faction _killed == "CIV_F") then { hint format ["%1 tötete einen Zivilisten!", name _killer]; }; }]; Share this post Link to post Share on other sites