Jump to content
patpowercat

Event Handler Persist after respawn

Recommended Posts

I'm having some trouble. I add and event handler in the editor, which works great at first. However, once I respawn, the event handler no longer applies. Do I need to apply the event hander INSIDE another respawn event handler?

Share this post


Link to post
Share on other sites

One thing you can do is rather than apply an event handler to the unit you could use an event script. These function as event handlers that are applied to anything that respawns. 

Share this post


Link to post
Share on other sites

Respawn EH (on a unit) can be added only where the unit is local. This thus doesn't work on editor init lines for players (playable units) as the init line is run on the server (registering the EH), but immediately after, the unit is "moved" (changes locality) to the player client. At that point, the respawn EH is lost.

The respawn EH itself persists through respawn just fine (again, as long as the unit doesn't change locality). You can use event scripts/files (suggested above) or just register the EH in init.sqf, which runs after the initial locality change.

Maybe a better description of your use case would help.

Share this post


Link to post
Share on other sites

I have an event handler for hit damage that reduces damage to the player. For the onplayerrespawn.sqf, would I just add in the event handler to the script? Does a onplayerrespawn override a respawn in the description.ext?

Share this post


Link to post
Share on other sites

I have an event handler for hit damage that reduces damage to the player. For the onplayerrespawn.sqf, would I just add in the event handler to the script? Does a onplayerrespawn override a respawn in the description.ext?

 

yes do that. it doesn't overwrite respawn templates from the description.ext (assuming you want to preserve revive or just respawn in general). all these event scripts do is execute once the specific event happens.

 

here's a list and possibly more details: https://community.bistudio.com/wiki/Event_Scripts

Share this post


Link to post
Share on other sites

Ok thanks. I've been reading up on it but still a bit confused. Honestly the locality host/server thing just confuses me in general. if all I wanted was to move the respawn event handler into onplayerrespawn, would the code just be:

this addeventhandler ["handle damage", etc etc]

Or would I need to change "this" to player? I'm away from my computer so I can't actually test any of the script.

Share this post


Link to post
Share on other sites

Ok thanks. I've been reading up on it but still a bit confused. Honestly the locality host/server thing just confuses me in general. if all I wanted was to move the respawn event handler into onplayerrespawn, would the code just be:

this addeventhandler ["handle damage", etc etc]

Or would I need to change "this" to player? I'm away from my computer so I can't actually test any of the script.

"this"/player has nothing to do with locality. :)

If you look at https://community.bistudio.com/wiki/Event_Scripts, you'll see that onPlayerRespawn.sqf gets passed "[<newUnit>, <oldUnit>, <respawn>, <respawnDelay>]" as arguments. So if you want to add the EH to the newly respawned unit, you would use the first (0th) argument,

(_this select 0) addEventHandler ["HandleDamage", { ... your code ... }];
where "your code" gets passed HandleDamage-specific arguments (see https://community.bistudio.com/wiki/Arma_3:_Event_Handlers#HandleDamage, 3rd column), which you can use in a similar way, ie.

(_this select 0) addEventHandler ["HandleDamage", {
    params ["_unit", "_selectionName", "_damage", "_source", "_projectile", "_hitPartIndex"];
    hint format ["%1 was damaged by %2", _unit, _source];
}];
You don't need to worry about locality because onPlayerRespawn.sqf always runs only for the local player unit, so you can safely add the HandleDamage EH and it will trigger as long as the player unit remains local (which it will unless you TeamSwitch or something).

PS: You can also use description.ext respawnOnStart to make the EH register on player spawn in addition to respawn.

Share this post


Link to post
Share on other sites

Sweet thanks a ton for explaining that! I'll try it when I get home Wednesday.

Share this post


Link to post
Share on other sites

Hi guys!

 

Not sure it's worth opening a new thread for that, so here goes : do we have a list of persistent EHs somewhere?

The wiki states that some of them are persistent, but not wich ones...

 

I'm trying to figure out wich ones I need to re-assign after a respawn, and that's a super pain in the arse. This being for a mod, event scripts aren't really an option. :/

  • Like 1

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

×