//Example 0 //Each time the player reloads their weapon, a random unit within 50m dies (includes player) player addEventHandler [ "Reloaded", { ((player nearEntities [["Man"], 50]) call bis_fnc_selectRandom) setDamage 1; } ]; // Example 1 //Each time the player reloads their weapon, a message appears player addEventHandler [ "Reloaded", { systemChat "Weapon reloaded!" } ]; // Example 2 //Every time the player enters a vehicle, a message appears player addEventHandler [ "GetInMan", { systemChat format ["Player %1 entered a vehicle.",name player]; } ]; // Example 3 //Every time the player enters a vehicle, a message appears player addEventHandler [ "GetInMan", { systemChat format ["Player %1 entered a vehicle as %2",name (_this select 0), (_this select 1)] } ]; // Example 4 //Every time the player fires their weapon, a message appears (counting bullets fired) counter = 0; player addEventHandler [ "Fired", { counter = counter + 1; _myStr = format ["EH Fired. ID: %1 Called for %2. time.",_thisEventHandler, counter]; systemChat _myStr; } ]; // Example 5 //Every time the player fires their weapon, a message appears (displaying bullet velocity) player addEventHandler [ "Fired", { _myStr = format ["EH Fired. ID: %1 Bullet traveling at %2 km/h.",_thisEventHandler, speed (_this select 6)]; systemChat _myStr; } ]; //Example 6 - should be added to a vehicle's init //Every time the engine changes state, a message appears this addEventHandler [ "engine", { _state = ""; if (_this select 1) then { _state = "on" } else { _state = "off" }; systemChat format ["%1 engine %2",typeof (_this select 0), _state]; } ]; //Example 7 - should be added to a vehicle's init //Every time the engine changes state, a message appears (more user-friendly name) this addEventHandler [ "engine", { _state = ""; if (_this select 1) then { _state = "on" } else { _state = "off" }; systemChat format ["%1 engine %2", getText((configFile >> "CfgVehicles" >> typeof (_this select 0)) >> "displayName"), _state]; } ]; //Example 8 //Every time the player's rating changes (after killing a unit / vehicle), a script is called player addEventHandler [ "HandleRating", { _0 = _this execVM "myScript.sqf" } ]; /******* myScript.sqf contents - part of Example 8 _unit = _this select 0; _rating = _this select 1; systemChat format ["myScript.sqf called. Unit %1 rating changed by %2.",_unit, _rating]; *******/ //Example 9 //Every time the player's rating changes (after killing a unit / vehicle), if the rating is negative, discard it player addEventHandler [ "HandleRating", { _returnValue = (_this select 1); if (_returnValue < 0) then { _returnValue = 0; }; _returnValue } ]; //Example 10 //Every time the player's rating changes (after killing a unit / vehicle), if the rating is negative, throw player in the air player addEventHandler [ "HandleRating", { _returnValue = (_this select 1); if (_returnValue < -400) then { (_this select 0) setVelocity [0,0,100]; hint "You are being punished for killing friendlies" }; _returnValue } ]; //Example 11 /********** Disables friendly fire from player. Handles only rifle / pistol / rocket launcher damage. Player can still kill by indirect damage, such as explosions or grenade use. Player can still kill friendly units while in vehicle by running them over. Player can kill friendly units with a vehicle gun by indirect damage, or if the gun aims slightly off (most tank machine guns) How it works: - when the player shoots a weapon, the game checks for the object he's aiming at. - if the object is the same side as player, it's considered friendly fire and the bullet is deleted. - in other cases EH has no effect. The issues start when you're not aiming directly at the other unit. In all those cases the game can't recognize your target, and won't delete the bullet. All other types than shooting are unaffected. **********/ if (!isNull player) then { _unit = player; _unit addEventHandler ["FiredMan", { if (!isNull cursorTarget) then { if (side cursorTarget == side player) then { deleteVehicle (_this select 6); } } } ]; }; //Example 12 /*********** Disables friendly fire from player / other units. Handles rifles, pistols, rocket launchers, grenades and most explosives. Does not handle vehicles very well. Player can still run over friendly units and kill them, or shoot them with a vehicle gun. Best suited for infantry missions and for missions with one small team working together. If player kills enough civilians / other friendly units, he may be able to friendly fire. How it works: - whenever the unit is damaged, game asks for the side of the object that caused this damage. - if the side of the affected unit is the same as the side of the unit that caused the damage, - the game asks if these two are the same unit (like when you throw a grenade at your feet) - if the units aren't the same, it's considered friendly fire and damage is null. - in all other cases, apply the damage as normal. The issues start whenever the side is unclear, cannot be determined, or isn't given at the moment. This can happen when units don't know about each other's existence, when one is considered "enemy side", or when the damage is caused by collisions and similar (in which case the cause is an unidentified object) ***********/ _unit = player; if (!isNull player) then { _unit addEventHandler [ "HandleDamage", { _returnDamage = _this select 2; if (side (_this select 0) == side (_this select 3)) then { if ((_this select 0) != (_this select 3)) then { _returnDamage = 0; }; }; _returnDamage } ]; };