Jump to content
Sign in to follow this  
BEAKSBY

Hint message problem with my MP money script

Recommended Posts

Hi Folks,

I'm building a multiplayer money script so when a player kills a unit from the opposing team they generate money for their side. Similarly, this is done for the opposite side.

But for some reason the hint is being displayed on both screens when I test this on LAN. How do I ensure the hint is only displayed on for the player that generated the money?

init.sqf

/*Before you use the player object (usually to avoid JIP issues) all you need is to run:
waitUntil {!isNull player}; Anything else you see in other scripts is equivalent and/or redundant. 
Of course JIP players may need more than just the player to point at the actual JIP player unit, but that's script/mission-specific.
https://community.bistudio.com/wiki/player*/

waitUntil {!isNull player};

BLUmoney = 5000;
OPPmoney = 5000;

call compile preProcessFileLineNumbers "scripts\UIFunctions.sqf";

{
   if ((WEST == playerSide) && (side _x != playerSide)) then {
       _x addMPEventHandler ["MPKilled", {[100] execVM "BLUaddMoney.sqf";}];
};

   if ((EAST == playerSide) && (side _x != playerSide)) then {
       _x addMPEventHandler ["MPKilled", {[100] execVM "OPPaddMoney.sqf";}];
};
} forEach allUnits;

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

BLUaddMoney.sqf

waitUntil {!isNull player};    
  _sum = _this select 0;
   BLUmoney = BLUmoney + _sum;
hint format ["You have %1$",BLUmoney];

OPPaddMoney.sqf

waitUntil {!isNull player};     
_sum = _this select 0;
   OPPmoney = OPPmoney + _sum;
hint format ["You have %1$",OPPmoney];

Thanks

Share this post


Link to post
Share on other sites

MP event handlers execute on all machines. Use one of the regular EHs to contain it locally.

Alternatively, you could contain the execute scripts to the server only and then send the hint to the player via BIS_fnc_MP.

Share this post


Link to post
Share on other sites

What I do is I make it locally like Fight says and it works like a charm, when working with money and licenses you always wanna do it locally. SO it should be:

   if ((WEST == playerSide) && (side _x != playerSide)) then { 
       _x addEventHandler ["Killed", {[100] execVM "BLUaddMoney.sqf";}]; 
   }; 

   if ((EAST == playerSide) && (side _x != playerSide)) then { 
       _x addEventHandler ["Killed", {[100] execVM "OPPaddMoney.sqf";}]; 
   }; 

:yay:

Share this post


Link to post
Share on other sites
What I do is I make it locally like Fight says and it works like a charm, when working with money and licenses you always wanna do it locally. SO it should be:

   if ((WEST == playerSide) && (side _x != playerSide)) then { 
       _x addEventHandler ["Killed", {[100] execVM "BLUaddMoney.sqf";}]; 
   }; 

   if ((EAST == playerSide) && (side _x != playerSide)) then { 
       _x addEventHandler ["Killed", {[100] execVM "OPPaddMoney.sqf";}]; 
   }; 

Thanks, but for some reason now BLUaddMoney.sqf is not being executed as the hint message is not being displayed.

BLUaddMoney.sqf

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

---------- Post added at 16:35 ---------- Previous post was at 16:21 ----------

I added forEach but now it only only displays the hint for WEST side.

init.sqf

{
if ((WEST == playerSide) && (side _x != playerSide)) then { 
	_x addEventHandler ["Killed", {[100] execVM "BLUaddMoney.sqf";}]; 
}; 
} forEach allUnits;
{
if ((EAST == playerSide) && (side _x != playerSide)) then { 
	_x addEventHandler ["Killed", {[100] execVM "OPPaddMoney.sqf";}]; 
};  
} forEach allUnits;

BLUaddMoney.sqf

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

OPPaddMoney.sqf

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

Edited by BEAKSBY

Share this post


Link to post
Share on other sites

playerSide is kind of a strange command. It can return WEST by default for any JIP player early during initialization. It differs from the side command because it will works on dead units. You don't really need that though. Try this instead:

{
switch (side _x) do {
	case WEST: {_x addEventHandler ["Killed", {[100] execVM "BLUaddMoney.sqf";}];};
	case EAST: {_x addEventHandler ["Killed", {[100] execVM "OPPaddMoney.sqf";}];};
	default {}:
};
} foreach allUnits;

Edited by Fight9

Share this post


Link to post
Share on other sites

Closer, for the EAST side the money generated is being displayed on the WEST's screen.

The WEST side still works fine.

I tried this too and still displays both money generated from either side on the WEST side's player's screen.

{
   switch (side _x) do {
       case WEST: {_x addEventHandler ["Killed", {[100] execVM "BLUaddMoney.sqf";}];};
       case EAST: {_x addEventHandler ["Killed", {[[[100], "OPPaddMoney.sqf"], "BIS_fnc_execVM",EAST, true] spawn BIS_fnc_MP;}];};
       default {};
   };
} foreach allUnits;  

Edited by BEAKSBY

Share this post


Link to post
Share on other sites

I think we are going about this the wrong way.

Perhaps you are trying to apply this to both AI and players, but if it's just players, try this:

without the forEach loop

switch (side player) do {
case WEST: {player addEventHandler ["Killed", {[100] execVM "BLUaddMoney.sqf";}];};
case EAST: {player addEventHandler ["Killed", {[100] execVM "OPPaddMoney.sqf";}];};
default {}:
};

Share this post


Link to post
Share on other sites

This did not work either for either side.

based on

Fight9

MP event handlers execute on all machines. Use one of the regular EHs to contain it locally.

Alternatively, you could contain the execute scripts to the server only and then send the hint to the player via BIS_fnc_MP.

I tried to incorporate the following, but it only managed to display the WEST money generated on the EAST side's player's screen.

{
   switch (side _x) do {
       case WEST: {if (side _x != playerSide) then {_x addEventHandler ["Killed", {[[[100],"BLUaddMoney.sqf"],"BIS_fnc_execVM", WEST,true] spawn BIS_fnc_MP;}];};};
	case EAST: {if (side _x != playerSide) then {_x addEventHandler ["Killed", {[[[100],"OPPaddMoney.sqf"],"BIS_fnc_execVM", EAST,true] spawn BIS_fnc_MP;}];};};
	default {};
   };
} foreach allUnits;  

How do MP games, like Stratis life, display hints to only the client players?

Share this post


Link to post
Share on other sites

well the way I do it is:

bankvars.sqf

money = 5000;
//all others like licenses

buySomething.sqf

//spawn or give license
money = money + 500;
hint format ["You have $%1", money];

Share this post


Link to post
Share on other sites

I found the problem but don't know how to resolve it.

It has to do with both _x variables from the addEventHandler from WEST and EAST sides conflicting.

{
if ((side player == WEST) && (side _x != side player)) then { 
_x addEventHandler ["Killed", {[100] execVM "BLUaddMoney.sqf";}]; 
}; 
if ((side player == EAST) && (side _x != side player)) then {  
_x addEventHandler ["Killed", {[100] execVM "OPPaddMoney.sqf";}]; 
}; 	
} forEach allUnits;

How do I disguish the _x from WEST vs. EAST side? I tried to incorporate private but couldn't figure out how to place it in the script.

I will start this on a new thread.

Edited by BEAKSBY

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  

×