Jump to content
Sign in to follow this  
McArcher

Noob questions about events for objects

Recommended Posts

I'm new to Arma2 scripting and cannot find information about some things. (used search)

* Are there events for player like "onPlayerDeath" or "onPlayerRespawn", or similar in Arma2?

* Where can I see all available events for all objects in game?

(I saw, somebody wrote a script that was run after death using a construction "while(true) {...check for alive status...}", for me it seems very-very strange to use such constructions... like using a microscope as a hammer :eek:)

Share this post


Link to post
Share on other sites

You can use a "Killed" Eventhandler as well.

Example:

<object> addEventhandler ["Killed",{ <code> }];

once the object gets killed, a vehicle gets fully destroyed, respectively, <code> will be executed.

Edited by Bon

Share this post


Link to post
Share on other sites

How to understand when The Player IS RESPAWNED? This event handler runs after death...

Tried to script

RU_player_1 addEventHandler ["Killed", 
{
(_this select 0) globalChat "I'm Dead...)"; 
waitUntil { alive (_this select 0) };
(_this select 0) globalChat "I'm Alive !!! =)"; 
}];

but it says that I'm alive when I am dead... really funny :D

Every event will create an array named _this, which contains specific information about the particular event. (e.g. the "killed" EH will return an array with 2 elements: the killed unit, and the killer.)

what am I doing wrong?!... :(

Share this post


Link to post
Share on other sites

I guess direct input of code doesn't allow waituntil or sleep commands. Put it in a script and call this script instead of inserting the code directly.

Share this post


Link to post
Share on other sites
waitUntil { alive (_this select 0) };

Respawning does not make the unit alive, instead a new unit is created. Thus, you cant do alive check for the dead unit.

Edited by Shuko

Share this post


Link to post
Share on other sites

// mca_players_eh.sqf
// version 1.0
// Evenhandlers for players
// server script

RU_player_1 addEventHandler ["Killed", 
{
(_this select 0) globalChat "I'm Dead...)"; 
[_this select 0] execVM "mca_waitUntil_alive.sqf";
(_this select 0) globalChat "I'm Alive !!! =)"; 
}];

// mca_waitUntil_alive.sqf

waitUntil { alive (_this select 0) };

it still writes that I'm alive when I am dead :( Why??

---------- Post added at 07:14 PM ---------- Previous post was at 07:10 PM ----------

Respawning does not make the unit alive, instead a new unit is created. Thus, you cant do alive check for the dead unit.

so, what should I do then? how can I execute code when I respawn?

---------- Post added at 08:10 PM ---------- Previous post was at 07:14 PM ----------

wtf...

http://community.bistudio.com/wiki/VBS2:_Event_Handlers#Respawn

they included "Respawn" EH for VBS2, but not in Arma 2.... Very honestly...

can anyone help?

Share this post


Link to post
Share on other sites

Would actually help if we knew what you are trying to do exactly.

If its just a client side thing, you can check for player:

RU_player_1 addEventHandler ["Killed",

{

(_this select 0) globalChat "I'm Dead...)";

waitUntil { alive player };

(_this select 0) globalChat "I'm Alive !!! =)";

}];

Share this post


Link to post
Share on other sites
Would actually help if we knew what you are trying to do exactly.

I want to use it in many things.

1. To set a position for teleportation after respawn (not to "respawn_east" marker, but somewhere else after that).

2. I wanted to make COIN working after respawn. Somehow reinitialize it. Or there's better way to have COIN working after death?

3. in every normal multiplayer game, there are events like onPlayerRespawn =) (like NWN/NWN2. it is used there for respawn in temples or in heaven after death..or some other quest features).

---------- Post added at 08:54 PM ---------- Previous post was at 08:45 PM ----------

RU_player_1 addEventHandler ["Killed",
{
(_this select 0) globalChat "I'm Dead...)";
waitUntil { alive player };
(_this select 0) globalChat "I'm Alive !!! =)";
}]; 

hasn't helped.

same as before...

Edited by McArcher

Share this post


Link to post
Share on other sites

how can I run code on serverside when my player respawns? (not when he is killed, but when he REALLY resurrects and is standing alive, i dont see "Respawn" EH in Arma2, like in VBS2 and all my efforts to make Alive-check result that it says that I'm always alive, even when I am killed :(:(:()

PLEASE HELP ME !!!!!!

---------- Post added at 01:35 ---------- Previous post was at 01:33 ----------

Respawning does not make the unit alive, instead a new unit is created. Thus, you cant do alive check for the dead unit.

how can I know new unit ?

---------- Post added at 01:39 ---------- Previous post was at 01:35 ----------

// mca_players_eh.sqf
// version 1.0
// Evenhandlers for players
// server script

RU_player_1 addEventHandler ["Killed", 
{
   if (isServer) then
   {
       private ["_me"];
       _me = _this select 0;
       waitUntil { alive _me };
       _me globalChat "Resyncing COIN...";
       deleteVehicle COIN_RU_MHQ;
       //Side_RU_MHQ = createCenter east;
       //group_RU_MHQ = createGroup east;
       "ConstructionManager" createUnit [ getPos RU_MHQ, group_RU_MHQ, "COIN_RU_MHQ = this;"];
       COIN_RU_MHQ synchronizeObjectsAdd [_me];
   }
}];

tried to resync COIN after "respawn", but it gives error about waitUntil ( alive _me };

---------- Post added at 01:53 ---------- Previous post was at 01:39 ----------

When playerRespawnTime reaches zero the player respawns as expected. When the player has completed respawning this command returns -1. --Sy 18:33, 21 June 2007 (CEST)
http://community.bistudio.com/wiki/playerRespawnTime

It returns -1 when I just die ! How can that be??????? Idiotizm бл*ть...

---------- Post added at 01:53 ---------- Previous post was at 01:53 ----------

I hate this game.... криворукие бл*Ñ‚ÑŒ пиÑали Ñтот движок....идиоты...

Share this post


Link to post
Share on other sites

Try something like this (not tested):

if (isserver) then {
 "McArcher_NewUnit" addpublicvariableeventhandler {
   _unit = _this select 1;
   diag_log format ["Log: recieved spawned unit: %1",_unit];
 };
} else {
 [] spawn {
   while {true} do {
     waituntil {!alive player};
     waituntil {alive player};
     McArcher_NewUnit = player;
     publicvariable "McArcher_NewUnit";
   };
 };
};

That's for dedi servers, for mp host the if else needs to be changed.

Share this post


Link to post
Share on other sites

Can i replace this:

 [] spawn {
   while {true} do {
     waituntil {!alive player};
     waituntil {alive player};
     McArcher_NewUnit = player;
     publicvariable "McArcher_NewUnit";
   };
 };
};

by making it this:

RU_player_1 addEventHandler ["Killed", 
{
   McArcher_NewUnit = player;
   publicvariable "McArcher_NewUnit";
}];

so that "else"-part goes into Killed EH and "isServer"-part stays where it was?

(I think "while {true} " is a very resource consuming loop?)

Edited by McArcher

Share this post


Link to post
Share on other sites
Can i replace this:

by making it this:

You can do anything you wish, but I wouldn't do that if you want it to work some day.

(I think "while {true} " is a very resource consuming loop?)

Yes, except it's not looping 99.9% of the time, it's actually waiting for the player to die (after that it waits for him to respawn), then loops to wait for dieing again.

Share this post


Link to post
Share on other sites
You can do anything you wish, but I wouldn't do that if you want it to work some day.

Yes, except it's not looping 99.9% of the time, it's actually waiting for the player to die (after that it waits for him to respawn), then loops to wait for dieing again.

but "waituntil {!alive player};" is looping 100% of time before death? maybe code after "waituntil {!alive player};" can be put into EH Killed?

RU_player_1 addEventHandler ["Killed", 
{
   waituntil {alive player};
   McArcher_NewUnit = player;
   publicvariable "McArcher_NewUnit";
}];

I forgot first line in previous quote.

---------- Post added at 03:29 ---------- Previous post was at 03:22 ----------

is

"McArcher_NewUnit" addpublicvariableeventhandler {
 _unit = _this select 1;
 diag_log format ["Log: recieved spawned unit: %1",_unit];
};
[] spawn {
  while {true} do {
     waituntil {!alive player};
     waituntil {alive player};
     McArcher_NewUnit = player;
     publicvariable "McArcher_NewUnit";
  };
};

ok for non-Dedi server?

my dedi is not working now, no standalone 1.05 server exe for win =)

Share this post


Link to post
Share on other sites
my dedi is not working now, no standalone 1.05 server exe for win =)

Standalone exe is exactly same as the arma2server.exe that came with 1.05.

As for the script, if you insist on using the killed EH, then I hope someone else has the patience to help.

Btw, waituntil stops the loop and waits for the condition to become true. In theory waituntil is a loop (but not one that trys to run as fast as possible) itself as well, but in practice checking for single boolean isn't any more cpu time consuming than using sleep.

Share this post


Link to post
Share on other sites
Standalone exe is exactly same as the arma2server.exe that came with 1.05.

As for the script, if you insist on using the killed EH, then I hope someone else has the patience to help.

Btw, waituntil stops the loop and waits for the condition to become true. In theory waituntil is a loop (but not one that trys to run as fast as possible) itself as well, but in practice checking for single boolean isn't any more cpu time consuming than using sleep.

i dont insist now.

now i want to run it on non-dedi server.... and i can't)

---------- Post added at 03:52 ---------- Previous post was at 03:51 ----------

oh, there's really a 1.05 server's exe in the root..... my mistake...

---------- Post added at 04:04 ---------- Previous post was at 03:52 ----------

and I'm having a virus that creates a window on top ov every application with advertisements of sex toys... i was shocked to see it in arma on top of the game screen.... and antivirus doesnt help... f*cking hackers...... thats why my PC was lagging lately..... so many troubles at te same time.... 1.05 server's exe is working at last))

---------- Post added at 04:19 ---------- Previous post was at 04:04 ----------

2009/12/25, 4:10:07 Unsupported language Russian in stringtable

2009/12/25, 4:11:18 Server: Update of object 2:35 arrived from nonowner

2009/12/25, 4:11:43 Server: Object 3:3 not found (message 121)

2009/12/25, 4:11:48 Server: Object 3:5 not found (message 121)

2009/12/25, 4:11:51 Server: Object 3:6 not found (message 121)

2009/12/25, 4:12:07 "Log: recieved spawned unit: RU_player_1"

so, the name is the same... then how can I know that my new RU_player_1 is different from old RU_player_1? when it goes into

waituntil {!alive player};

waituntil {alive player};

?

---------- Post added at 04:47 ---------- Previous post was at 04:19 ----------

how can I execute a script on server's side, when I am totally respawned (i am resurrected and standing alive) ?

(alive check says I'm alive, but I am dead, waiting for respawn)

---------- Post added at 04:48 ---------- Previous post was at 04:47 ----------

btw, virus was CMedia... my antivirus was at medium level of defence, on high level it detected it...

Share this post


Link to post
Share on other sites

Just use

if ( isNil{player getVariable "mk_killedEHadded"} ) then 
{
player addEventHandler ["killed", 
{ 
	[] spawn {
		waitUntil { alive player }; 
		execVM "script.sqf";
	};	
}];
player setVariable ["mk_killedEHadded", true];
};

Share this post


Link to post
Share on other sites
Just use
if ( isNil{player getVariable "mk_killedEHadded"} ) then 
{
player addEventHandler ["killed", 
{ 
	[] spawn {
		waitUntil { alive player }; 
		execVM "script.sqf";
	};	
}];
player setVariable ["mk_killedEHadded", true];
};

oh, great! that's what I meant, but didn't know how to write. thanx, I'll try it.

Share this post


Link to post
Share on other sites
Just use
if ( isNil{player getVariable "mk_killedEHadded"} ) then 
{
player addEventHandler ["killed", 
{ 
	[] spawn {
		waitUntil { alive player }; 
		execVM "script.sqf";
	};	
}];
player setVariable ["mk_killedEHadded", true];
};

the script works fine in Dedicated server,

I am now testing and editing scripts to be Client's Server compatible,

and this script doesn't work.... don't know even why...

// mca_players_eh.sqf
// version 1.1c

if (not (isNull player)) then
{
waitUntil {time >10};
[color="Lime"]player groupChat format ["Initializing player..."];[/color]
if ( isNil{player getVariable "mk_killedEHadded"} ) then 
{
[color="Red"]player groupChat format ["Setting EH..."];/////////////////[/color]
	player addEventHandler ["killed", 
	{ 
[color="Red"]player groupChat format ["Starting onPlayerKilled..."];/////////////////[/color]
		[player] execVM "mca_onPlayerKilled.sqf";
		[] spawn 
		{
			waitUntil { alive player }; 
			[player] execVM "mca_onPlayerRespawn.sqf";
		};

	}];
	player setVariable ["mk_killedEHadded", true];
};
};

the code in red isn't shown for a player (on server) in non-dedicated server, so script isn't even executed, though the green one was run... (if it works for clients of client-server i dont know, i cannot test without second copy of the game) why can it be?

---------- Post added at 21:53 ---------- Previous post was at 21:10 ----------

seems like mk_killedEHadded was conflicting. after removing it, script works..... hm...

Edited by McArcher

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  

×