Jump to content
Sign in to follow this  
BEAKSBY

objectName setVariable [name, value, (public)] ...help with (public) broadcast

Recommended Posts

HI All,

I'm using objectName setVariable [name, value, (public)] in for an addAction condition.

I've added this inside initPlayerLocal.sqf

player setVariable ["addAction", TRUE, TRUE];
player addAction ['REINFORCE EMPLACEMENT', {player setVariable ["addAction", FALSE, TRUE];
[cursorTarget] execVM "ReinforceStaticWeapon.sqf"}, nil, 6, true, true, "", 
"_allowAddAction = player getVariable ""addAction"";
(cursortarget iskindof 'staticWeapon') && (cursortarget distance _this ) < 5 && _allowAddAction"]; 

Yet, another player will have the addAction appear in the their menu when one player has already activated the addAction and setVariable "addAction" to FALSE. I thought the variable would have been broadcasted to all computers and therefor the addAction would not be available once it has been activated?

Is it because I've placed this addAction inside initPlayerLocal.sqf?

Share this post


Link to post
Share on other sites

Not sure if it solve your problem, but it is NEVER a good idea to use variabale names that are the same as scripting commands! There are also some BIS standard variabales you should not use... so it is better to be more creative... use something like BEA_addAction...

;)

Share this post


Link to post
Share on other sites

You have set the variable to the player. Not the player vehicle. (Which must be named). Which means that the condition will always be local to the player even if you make it public. Try giving the player a name like p1 and set the variable to p1. Such as p1 getvariable/set variable.

Share this post


Link to post
Share on other sites
You have set the variable to the player. Not the player vehicle. (Which must be named). Which means that the condition will always be local to the player even if you make it public. Try giving the player a name like p1 and set the variable to p1. Such as p1 getvariable/set variable.

OK, Thanks guys,

You mean something like this?

initPlayerLocal.sqf

player = _p1;
_p1 setVariable ["addAction", TRUE, TRUE]; 
player addAction ['REINFORCE EMPLACEMENT', {_p1 setVariable ["BEAKS_addAction", FALSE, TRUE];
[cursorTarget] execVM "ReinforceStaticWeapon.sqf"}, nil, 6, true, true, "",  
"_allowAddAction = _p1 getVariable ""BEAKS_addAction""; 
(cursortarget iskindof 'staticWeapon') && (cursortarget distance _this ) < 5 && _allowAddAction"];

I have a number of other setVariables in other scripts that will change the condition of _allowAddAction that I will change from player to _p1. The (public) boolean is realy helpful...

... but wondering if it comes at a cost to performance and how to handle lag between different clients?

Share this post


Link to post
Share on other sites
OK, Thanks guys,

You mean something like this?

initPlayerLocal.sqf

player = _p1;
_p1 setVariable ["addAction", TRUE, TRUE]; 
player addAction ['REINFORCE EMPLACEMENT', {_p1 setVariable ["BEAKS_addAction", FALSE, TRUE];
[cursorTarget] execVM "ReinforceStaticWeapon.sqf"}, nil, 6, true, true, "",  
"_allowAddAction = _p1 getVariable ""BEAKS_addAction""; 
(cursortarget iskindof 'staticWeapon') && (cursortarget distance _this ) < 5 && _allowAddAction"];

I have a number of other setVariables in other scripts that will change the condition of _allowAddAction that I will change from player to _p1. The (public) boolean is realy helpful...

... but wondering if it comes at a cost to performance and how to handle lag between different clients?

Passing BOOLEANS shouldn't cause lag.

But to help you optimize the script we really need a better understanding of the script purpose.

Share this post


Link to post
Share on other sites
Passing BOOLEANS shouldn't cause lag.

But to help you optimize the script we really need a better understanding of the script purpose.

Fair enough,

This is for a 3v3 MP remake of The Outfit (2004 XBOX 360). Players can call in all types of assest on the fly (via parachute drop) given they have enough money and they control certain key sectors such as a Motor Pool for vehicles, Armory for staticWeapons and Radio Tower for artillery/CAS...etc.

If they encounter a staticWeapon, that no longer has a gunner, when they place the cursorTarget on the staticWeapon, the addAction above should be initiated, given the conditions (within 5m of staticWeapon and _allowAddAction) are true.

In the code portion of the addAction I added, _p1 setVariable ["BEAKS_addAction", FALSE, TRUE]; so once they click the 'REINFORCE EMPLACEMENT' addAction and are waiting for a new gunner to parachute in, the player or any other players do not see an addAction for the same staticWeapon.

I use a "Killed" EH on the gunner reinforcement parachuting in and use _p1 setVariable ["BEAKS_addAction", TRUE, TRUE]; if he is killed during the game so any player can call in another reinforcement, once more...and the cycle continues.

I use _allowAddAction = _p1 getVariable ""BEAKS_addAction""; to retrieve the variable for the condition in the player's addAction to enable it or not.

Edited by BEAKSBY

Share this post


Link to post
Share on other sites
You have set the variable to the player. Not the player vehicle. (Which must be named). Which means that the condition will always be local to the player even if you make it public. Try giving the player a name like p1 and set the variable to p1. Such as p1 getvariable/set variable.

Not sure what you mean when you say You have set the variable to the player. "Not the player vehicle. (Which must be named)."? Do you mean set the variable to the staticWeapon?

If so how do I set a variable to something that has not been created yet? Basically, how do I setVariable to a unit that will be called in by a script later on during the game?

I tried this but it did not change anything...

	p1 = player;
p1 setVariable ["addAction", TRUE, TRUE];
player addAction ['<t size=''0.85''>REINFORCE EMPLACEMENT </t>' + '<t size=''0.85''  color=''#ff0000''>$ 25 </t>', {p1 setVariable ["addAction", FALSE, TRUE];
	[cursorTarget] execVM "ReinforceStaticWeapon.sqf"}, nil, 6, true, true, "", 
	"_allowAddAction = p1 getVariable ""addAction"";
	(cursortarget iskindof 'staticWeapon') && (cursortarget distance _this ) < 5 &&  !(alive gunner cursorTarget) && alive cursorTarget && _allowAddAction"]; 

Edited by BEAKSBY

Share this post


Link to post
Share on other sites
Not sure what you mean when you say You have set the variable to the player. "Not the player vehicle. (Which must be named)."? Do you mean set the variable to the staticWeapon?

If so how do I set a variable to something that has not been created yet? Basically, how do I setVariable to a unit that will be called in by a script later on during the game?

I tried this but it did not change anything...

	p1 = player;
p1 setVariable ["addAction", TRUE, TRUE];
player addAction ['<t size=''0.85''>REINFORCE EMPLACEMENT </t>' + '<t size=''0.85''  color=''#ff0000''>$ 25 </t>', {p1 setVariable ["addAction", FALSE, TRUE];
	[cursorTarget] execVM "ReinforceStaticWeapon.sqf"}, nil, 6, true, true, "", 
	"_allowAddAction = p1 getVariable ""addAction"";
	(cursortarget iskindof 'staticWeapon') && (cursortarget distance _this ) < 5 &&  !(alive gunner cursorTarget) && alive cursorTarget && _allowAddAction"]; 

If you are spawning the unit using a script then something like this will work

_unit = group player createUnit ["B_soldier_F", Position player, [], 0, "FORM"];

_unit setVariable ["addAction",true,true];

And 'vehicle player' is referring to the object that a client (player) is controlling. Most of the time this object is a unit.

And 'Player' just a local command, not a name that other players can see.

So to send variables to other clients using set/GetVariable we need to use the object name.

Share this post


Link to post
Share on other sites
Not sure what you mean when you say You have set the variable to the player. "Not the player vehicle. (Which must be named)."? Do you mean set the variable to the staticWeapon?

If so how do I set a variable to something that has not been created yet? Basically, how do I setVariable to a unit that will be called in by a script later on during the game?

I tried this but it did not change anything...

	p1 = player;
p1 setVariable ["addAction", TRUE, TRUE];
player addAction ['<t size=''0.85''>REINFORCE EMPLACEMENT </t>' + '<t size=''0.85''  color=''#ff0000''>$ 25 </t>', {p1 setVariable ["addAction", FALSE, TRUE];
	[cursorTarget] execVM "ReinforceStaticWeapon.sqf"}, nil, 6, true, true, "", 
	"_allowAddAction = p1 getVariable ""addAction"";
	(cursortarget iskindof 'staticWeapon') && (cursortarget distance _this ) < 5 &&  !(alive gunner cursorTarget) && alive cursorTarget && _allowAddAction"]; 

I'm not spending too much time looking over everything, but this is what i think your doing wrong. Addaction is local, so you have a different action on each persons machine with the same information. When you assigned p1 = player; basically everyones p1 got assigned to their own person. So changing a variable on your guy, and then broadcasting it, will basically have no effect because THEIR p1 is different then yours (their player instead). So you have to realize that each machine has its own player and own action when you run this script.

Next you need to understand that handling state changes (the ability to see the action in this case) over the net will be subject to race conditions. If everyone does something at the same time their packets will take time to travel across the net (packets being the variables in this case)

Share this post


Link to post
Share on other sites
If you are spawning the unit using a script then something like this will work

_unit = group player createUnit ["B_soldier_F", Position player, [], 0, "FORM"];

_unit setVariable ["addAction",true,true];

And 'vehicle player' is referring to the object that a client (player) is controlling. Most of the time this object is a unit.

And 'Player' just a local command, not a name that other players can see.

So to send variables to other clients using set/GetVariable we need to use the object name.

OK thanks,

I've got the setVariable to the _unit in the spawning script already...but...

...in the initPlayerLocal.sqf how do I get the _unit getVariable into the player's addAction?

player addAction ['REINFORCE EMPLACEMENT', {[cursorTarget] execVM "ReinforceStaticWeapon.sqf"}, nil, 6, true, true, "", 
"_allowAddAction = _gun1 getVariable ""addAction"";
(cursortarget iskindof 'staticWeapon') && (cursortarget distance _this ) < 5 &&  !(alive gunner cursorTarget) && alive cursorTarget && _allowAddAction"]; 

the above does not seem to work?

hold on...In think I got it...

I just replaced _allowAddAction = _gun1 getVariable ""addAction""; with

_allowAddAction = cursortTarget getVariable ""addAction"";

...this might work.

Edited by BEAKSBY
hold on...In think I got it...

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  

×