Jump to content
Sign in to follow this  
MrSanchez

Player boolean

Recommended Posts

Hello,

I'm stuck on a multiplayer-compatible script, in which I need to create a player boolean.

At first I thought SetVariable, but that doesn't support booleans, which i need for various checks.

So how do I create a boolean that is also compatible with various SQF scripts?

e.g. a 'death' boolean, if I assign it the value 'true', and make it global it will be set 'true' to every player, if i use '_death' instead, i can only use in that particular sqf file.

Long story short, I need something like setVariable but for booleans.

Share this post


Link to post
Share on other sites

Uhm, from what I know "setVariable" does allow Booleans, I've used it with Booleans before.

Share this post


Link to post
Share on other sites

Hmm, it appears, i erased my work where i was stuck upon, so I can't really figure out what my problem is right now, I'm going to do rewrite it and then i'll see.

edit: alright, i got something odd

_b setVariable ["death",true];
_death = _b getVariable "death";
hint format ["_death = %1",_death];

_death returns 'any' everytime

Edited by PhonicStudios

Share this post


Link to post
Share on other sites

According to the WIki, your syntax should be as follows:

objectName setVariable [name, value, (public)];

So have you tried:

_b setVariable ["death", true, false];

Hope that helps.

Share this post


Link to post
Share on other sites

It defaults to false and does not have to be included.

There should however be no problem using boolean in setVar.

Share this post


Link to post
Share on other sites

Are you sure _b is an object? If _b is just a variable then you cannot use setVariable, instead you should just use _b as a normal variable.

Try doing this, after you declare what _b is.

hint (("typeName _b = ") + (typeName _b));

Share this post


Link to post
Share on other sites

Hahaha, facepalm, as I've been working on this script for like a week, trying to figure out stuff, i just got so tired that i missed that the lines i posted above are actually on top of _b = _this select 1..

noticed due to

Try doing this, after you declare what _b is.
by Horner, I noticed I declared _b under setvariable, I'm going to test now, pretty sure it will work ;)

edit: however, how would I return an array of all alive units? not the number of alive units.

its because of this code

{ if!(_x in thislist) then { _x setDamage 1; _x globalChat format ["%1 got killed because he went out of the area of operations.",name _x]; }; } forEach playableUnits

Edited by PhonicStudios

Share this post


Link to post
Share on other sites

To return an array of alive units (seems you want to use playableUnits instead of allUnits, so it's actually alive players)

private["_aliveUnits"];
_aliveUnits = [];

{
if (alive _x) then
{
	_aliveUnits = _aliveUnits + [_x];
};
} forEach playableUnits;

Share this post


Link to post
Share on other sites

Cheers, works perfectly.

Just got a question if you have time, what does private[] do? on wiki it says something about innermost scope but I have no clue what this means.

edit: I can't seem to get it working, i got a couple of playable units, players.. and i got a trigger that covers a 250x300 area, i want the trigger to activate if any player walks out of that zone, and kills him and displays the message posted in my previous post, how would I do this?

Edited by PhonicStudios

Share this post


Link to post
Share on other sites
The example provided is fairly worthless without a context.

Using the private command allows you to declare a variable in the current scope, without regards to variables in a higher scope with the same name. Note that if you try to declare a variable without an underscore (meaning it's global) with the private command, it will cause an error. Specifically: "Error Local variable in global space".

Here's a code example with output for your benefit.

_foo = 10;
if (true) then
{
   private ["_foo"];
   _foo = 5;
   player sideChat format ["%1", _foo];
};
player sideChat format ["%1", _foo];

In this example, the first sidechat (innermost) returns 5 while the second sidechat (outermost) returns 10.

if (true) then
{
   private ["_bar"];
   _bar = 5;
   player sideChat format ["%1", _bar];
};

In this example, the private command does nothing and is simply a waste of code, assuming there is no higher level code to interfere with the if statement.

This is what I found in the comment section of the private command on the wiki. Hope it helps.

Share this post


Link to post
Share on other sites

so with scope they mean piece of code (between brackets e.g.)

but I edited my previous post,

edit: I can't seem to get it working, i got a couple of playable units, players.. and i got a trigger that covers a 250x300 area, i want the trigger to activate if any player walks out of that zone, and kills him and displays the message posted in my previous post, how would I do this?

when i did some research, i found this: http://forums.bistudio.com/showthread.php?138583-detecting-when-2-units-are-out-of-an-area

but for more units they suggest repeating the trigger, naming every playable unit and create new trigger for that(would be alot of work if u have 50 playable units)

what is the most efficient, fastest way to do this? (compatible with multiple players)

Share this post


Link to post
Share on other sites

I always use private on the outermost scope so the vars defined in the outermost scope work in all inner scopes aswell, even if they are defined in an inner scope. Also, dunno why that isn't working, can you post your trigger code that you're using?

Share this post


Link to post
Share on other sites

Activation 'Blufor' (my players are Blufor)

I set condition to 'true', and set it repeatedly, because I wasn't sure how to do the condition otherwise,

{ if !(_x in thislist) then { _x setDamage 1; _x globalChat format ["%1 got killed because he went out of the area of operations.",name _x]; }; } forEach aliveUnits;

upon placing a hint, i noticed it doesn't loop, this code is executed once while trigger is set to repeatedly.

I'm also pretty sure that some code u just shouldn't paste into a trigger, but I don't know how to do it else wise.

Edited by PhonicStudios

Share this post


Link to post
Share on other sites

Do you have "aliveUnits" defined? Incase you just copied and pasted Horner's code, you'll have to remove the "_" from infront of his "_aliveUnits" array.

Share this post


Link to post
Share on other sites

yes, I know that..

I have also done that yes.. :/

Share this post


Link to post
Share on other sites
yes, I know that..

I have also done that yes.. :/

You never know :D

Where did you put the definition for the alive units?

Edit : I think I understand your problem now :D

Try setting the trigger activiation to once and then use a while loop instead of setting the trigger to "repeatedly".

Please forgive me if I don't understand your problem correctly.

Edited by FreakJoe

Share this post


Link to post
Share on other sites

well i tried

[] spawn {
areacheck = {
while {true} do {
{ if !(_x in (_this select 0)) then { _x setDamage 1; _x globalChat format ["%1 got killed because he went out of the area of operations.",name _x]; }; } forEach aliveUnits; 
hint "loop"; 
};
};
};

and

[thislist] call areacheck; hint "called";

still doesn't loop, it executes once..

even if i remove the forEach line.

Share this post


Link to post
Share on other sites

Are you getting any script errors? Try running your game with -showScriptErrors.

Share this post


Link to post
Share on other sites

what is aliveUnits; I've not seen that command before maybe it should be allunits;

There is another issue you have a loop without a delay, this will eat your cpu and as it's a function you can't use sleep.

You could just place this in a game logic and name it glogic and this code is using a distance check rather than a trigger

null=[] spawn { while {true} do {
{ 
   if (_x distance glogic > 150) then {
     _x setDamage 1; 
       _x globalChat format ["%1 got killed because he went out of the area of operations.",name _x];
         };
} forEach allUnits;
sleep 0.5;
 };
};

Edited by F2k Sel

Share this post


Link to post
Share on other sites

aliveUnits is a custom function, designed in previous posts in this thread, anyway i got it working with this

[] spawn {
while {alive player} do {
if (!(player in (list senzor)) && alive player) exitWith {
[player,true] call Pdeath;
};
sleep 0.1;
};
};

the only small issue in the Pdeath function, i got a globalChat message which is executed locally, but that would be easy for me to fix.

Thanks alot all!

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  

×