Freddywall 11 Posted March 21, 2020 Hello guys, i am trying to make super simple money script for my MP mission. I want the reward depending on the side. If u kill ur teammate or suicide it displays some text but if u kill enemy it will give u some reward. So i tried to use: if (side _killed == side _killer) then {hint "teamkill";} else {cash = (cash + 100); hint str cash;}; but seems it doesn't work //InitPlayerLocal.sqf cash = 0; { _x addEventHandler ["killed", { _unit = (_this select 0); _killer = (_this select 1); pKilled = [_unit, _killer]; publicVariableServer "pKilled"; }]; } forEach allUnits; "pClient" addPublicVariableEventHandler { if (side _killed == side _killer) then {hint "teamkill";} else {cash = (cash + 100); hint str cash;}; }; //InitServer.sqf "pKilled" addPublicVariableEventHandler { private ["_data"]; _data = (_this select 1); _unit = (_data select 0); _killer = (_data select 1); _cID = owner _killer; _cID publicVariableClient "pClient"; }; Share this post Link to post Share on other sites
opusfmspol 273 Posted March 21, 2020 20 minutes ago, Freddywall said: if (side _killed == side _killer) then {hint "teamkill";} else {cash = (cash + 100); hint str cash;}; A dead unit is side civilian. Use playerSide for players or group side for AI. Would also suggest you define your pClient and pKilled variables with default values before adding the public variable event handlers. Share this post Link to post Share on other sites
jts_2009 96 Posted March 21, 2020 // Example // Function should be defined everywhere (Server & Clients) freddywall_fnc_score = { params ["_score","_unit"]; _sideOfKilled = [_unit, true] call BIS_fnc_objectSide; if (_sideOfKilled == side player) then { hint "teamkill" } else { cash = cash + _score; hint str cash; }; }; // Execute this part only on server this addEventHandler ["Killed", { params ["_unit", "_killer", "_instigator", "_useEffects"]; [[100, _unit], freddywall_fnc_score] remoteExec ["call", _instigator]; _unit removeAllEventHandlers "Killed"; }]; this - should be object. For example enemy unit 🤨 Share this post Link to post Share on other sites
Larrow 2801 Posted March 22, 2020 7 hours ago, jts_2009 said: [[100, _unit], freddywall_fnc_score] remoteExec ["call", _instigator]; [ 100, _unit ] remoteExec[ "freddywall_fnc_score", _instigator ]; Just remoteExec the function directly. 7 hours ago, jts_2009 said: _unit removeAllEventHandlers "Killed _unit removeEventHandler[ "killed", _thisEventHandler ]; Remove the event you added, rather than clearing all. Just a good habit to get into, so as not to destroy other events. Spoiler //initServer.sqf addMissionEventHandler[ "EntityKilled", { params[ "_killed", "_killer", "_instigator" ]; if ( isNull _instigator ) then { // UAV/UGV player operated road kill _instigator = UAVControl vehicle _killer select 0; }; if ( isNull _instigator ) then { // player driven vehicle road kill _instigator = _killer; }; if ( isPlayer _instigator ) then { if ( side group _killed isEqualTo side _instigator ) then { format[ "You just team killed %1", name _killed ] remoteExec[ "hint", _instigator ]; }else{ [ 100 ] remoteExec[ "freddywall_fnc_score", _instigator ]; }; }; }]; //initPlayerLocal.sqf freddywall_cash = 0; freddywall_fnc_score = { params[ "_value" ]; freddywall_cash = freddywall_cash + _value; }; 2 Share this post Link to post Share on other sites