Jump to content
Sign in to follow this  
bangabob

Script to check whether specific player alive

Recommended Posts

Hi everybody. I am trying to script a trigger that detects when '_traitor' is the last person alive in the trigger area.

So i have this script that randomly selects which player is the '_traitor'.

I want the trigger to activate when he(_traitor) is the last BLUFOR unit in the trigger area (the whole map).

traitor.sqf

if (!isServer) exitWith {};

_host = _this select 0;

_caller = _this select 1;

_id = _this select 2;

_units = [s4,s1,s3,s2,s5,s6];

_traitor = _units select floor (random 6);

_host removeaction _id;

hint format ["Traitor: %1", name _traitor];

_trg=createTrigger["EmptyDetector",getPos e2];

_trg setTriggerArea[1000,1000,0,false];

_trg setTriggerActivation["WEST","PRESENT",true];

_trg setTriggerStatements["_traitor in thislist; ", "hint 'The traitor killed everyone'; ", ""];

Share this post


Link to post
Share on other sites

if you've covered the whole map why not just check the units in the array and forget the trigger

I'd start with something like this........

while{alive _traitor}do

{

if((count _units) <= 1) exitwith {hint 'The traitor killed everyone'};

sleep .1;

};

if(((count _units) > 0) && (!alive _traitor)) then {hint 'The traitor died'};

Edited by Squ33z3

Share this post


Link to post
Share on other sites

Cheers. I will try that. Im new to scripting so things that may appear obvious dont even cross my mind.lol

---------- Post added at 22:53 ---------- Previous post was at 22:17 ----------

while{alive _traitor}do

{

if((count _units) <= 1) exitwith {hint 'The traitor killed everyone'};

sleep .1;

};

if(((count _units) > 0) && (!alive _traitor)) then {hint 'The traitor died'};

Okay my brain melts when i try and read this.

So i got the second bit working. When the traitor is killed the hint is activated.

But can someone explain to me what the first bit says. Is it everyone listed in _units dead apart from one?

Share this post


Link to post
Share on other sites

Try this, I made a few changes that might have caused some errors in game, not sure if there are any bugs. Threw this together in about 5 minutes:

if (!isServer) exitWith {};

private ["_host","_caller","_id","_units","_traitor","_x","_unit"];

_host = _this select 0;
_caller = _this select 1;
_id = _this select 2;

_units = [s4,s1,s3,s2,s5,s6];
_traitor = _units select floor (random 5);
_units = _units - [_traitor];
_host removeaction _id;

hint format ["Traitor: %1", name _traitor];

while{true}do {
for[{_x=0},{_x<=(count _units)},{_x=_x+1}] do {
	_unit = _units select i;
	if(!alive _unit) then {
		_units = _units - [_unit];
	};
	sleep 0.2;
};
if(((count _units) > 0) && (!alive _traitor)) exitWith {hint "The traitor is dead!"};
if(((count _units) < 1) && (alive _traitor)) exitWith {hint "The traitor killed everyone!"};
sleep 0.2;
};

P.S. When ever you are posting code please but the


or

tags around it, makes it much easier to read and may even show you errors! Thanks!

Share this post


Link to post
Share on other sites

while{alive _traitor}do .....this line checks if the traitor is alive

if((count _units) <= 1) exitwith {hint 'The traitor killed everyone'};..........then straight away counts the units in the array and if 1 or less then it can only be the traitor alive or dieing if he happens to be standing near explosive ready to go off or falling from a building..etc etc

bigshotking script is the same thing but has a bit i left out....

if(!alive _unit) then {

_units = _units - [_unit];

};

which is needed for the (count _units) bit to work....

no ones perfect and I'm sure bigshotking agrees

_unit = _units select i; #should be# _unit = _units select _x;

heres another way without errors (fingers crossed)

if (!isServer) exitWith {};

private ["_host","_caller","_id","_units","_traitor","_x","_unit"];

_host = _this select 0;
_caller = _this select 1;
_id = _this select 2;

_units = [s4,s1,s3,s2,s5,s6];
_traitor = _units select floor (random 5);
_units = _units - [_traitor];
_host removeaction _id;

hint format ["Traitor: %1", name _traitor];

while{true}do
{
{if(!alive _x) then { _units = _units - [_x]}}foreach _units;

 if(((count _units) > 0) && (!alive _traitor)) exitWith {hint "The traitor is dead!"};
 if(((count _units) < 1) && (alive _traitor)) exitWith {hint "The traitor killed everyone!"};
 sleep 0.2;
};

Edited by Squ33z3

Share this post


Link to post
Share on other sites

Yup like I said I through it together in about 5 minutes in my colleges Cafeteria. And yes you are correct, I did make some mistakes in there

Share this post


Link to post
Share on other sites

Thanks a lot for all the help. I have got it all working

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  

×