Jump to content
Sign in to follow this  
BEAKSBY

how do I run addEventHandler effects on a specific machine, server or client?

Recommended Posts

ONLY the WEST side is working for the BLUaddmoney.sqf / OPPaddmoney.sqf when I test on LAN

init.sqf

BLUmoney = 5000;
OPPmoney = 1000;

call compile preProcessFileLineNumbers "scripts\UIFunctions.sqf";

waitUntil {!isNull player}; 
//////////////////////////////////////////////////// 

*/

If (side player == WEST) then {// for west units  
		player addAction ["Player identity", { hint format ["Player name is %1", _this select 3] }, name player];
			player addAction ["<t color='#00dd00'>Account Status </t>", "BLUaccount.sqf"]; 	// TESTING HINT MESSAGE ON EITHER PLAYER AND THIS WORKS
				player addAction ["Player side", { hint format ["Player side is %1", _this select 3] }, side player]; 
				    {if (side _x != side player) then {_x addEventHandler ["Killed", {[100] execVM "BLUaddmoney.sqf";}];};} forEach allUnits; 
	} 
   	else {// change this for east units  
		player addAction ["Player identity", { hint format ["Player name is %1", _this select 3] }, name player];
			player addAction ["<t color='#00dd00'>Account Status </t>", "OPPaccount.sqf"]; 	// TESTING HINT MESSAGE ON EITHER PLAYER AND THIS WORKS
				player addAction ["Player side", { hint format ["Player side is %1", _this select 3] }, side player]; 	
					{if (side _x != side player) then {_x addEventHandler ["Killed", {[100] execVM "OPPaddmoney.sqf";}];};} forEach allUnits; 
	};


_menu = player addAction ["<t color=""#3399FF"">" +"Weapons", {call FUS_fnc_dialogInit;}];	

BLUaddmoney.sqf

_BLUsum = _this select 0;
BLUmoney = BLUmoney + _BLUsum;
hint format ["You have %1$", BLUmoney];

OPPaddmoney.sqf

_OPPsum = _this select 0;
OPPmoney = OPPmoney + _OPPsum;
hint format ["You have %1$", OPPmoney];

I think this all has to do with addEventHandler --> effects of the given scripting command are not broadcasted over the network and remain local to the client the command is executed on. Check Locality in Multiplayer for more information about locality of objects.

I'm not sure how to check which machine it is run on server or client then run the addEventHandler on the appropriate machine.

SO how do I run addEventHandler effects on a specific machine, server or client?

Edited by BEAKSBY

Share this post


Link to post
Share on other sites

Before I help, mind if I ask what you're trying to achieve overall? There might be a better way of doing things.

Share this post


Link to post
Share on other sites
Before I help, mind if I ask what you're trying to achieve overall? There might be a better way of doing things.

Thanks DnA_UK

When a unit (including the player) kills an enemy unit, the side that made the kill should receive $100 in their account (I.e. BLUmoney or OPPmoney). This $100 should be displayed as a hint on the machine of the player's side that made the kill only. This is for MP.

Share this post


Link to post
Share on other sites

OK, Thanks!

I will need some time to digunderstand it and add it to the OPPFOR side too.

Thanks again

Share this post


Link to post
Share on other sites
It already works for any other side.

Thanks DnA_UK

Question: I replaced

//--- Check if player is killed and is of opposite side

if ( isPlayer _killer && { side group _killer != side group _unit } ) then {

with

//--- Check if opposite side is killed by killer

if (side group _killer != side group _unit) then {

Do you think this will affect MP gameplay as any unit from one side will generate money for their side and vice-versa? This was my original intent. My game will be designed for 4 Vs 4 for the maximum amount of players, yet each player can spawn dozens of units each.

New initServer.sqf

{ 

//--- Add killed EH to unit
_handle = _x addEventHandler [ "Killed", {

	_unit = _this select 0;
	_killer = _this select 1;
	_handle = _unit getVariable [ "DNA_EH_Killed_Money", -1 ];

	//--- Check if opposite side is killed by killer
	if (side group _killer != side group _unit) then {

		//--- Add money to the client
		[ 100, "DNA_fnc_addMoney", _killer ] call BIS_fnc_MP;

	};

	//--- Remove the event handler
	_unit removeEventHandler [ "Killed", _handle ];

} ];

//--- Store killed EH handle in unit namespace
_x setVariable [ "DNA_EH_Killed_Money", _handle ];

} forEach allUnits;

Share this post


Link to post
Share on other sites
It already works for any other side.

Thanks, works great!

I'm still having troubles getting the hint to display the current account after a unit (or player) from the side of the player makes a kill. Both players should see a hint displaying their current account after one of their own units make a kill.

Edited by BEAKSBY

Share this post


Link to post
Share on other sites

Ah, I understand what you want now. I'll help you out if/when I get some free time :P

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×