Jump to content
Sign in to follow this  
doomanchu

Execute Script When Player Joins and Respawns

Recommended Posts

What's the best way to have a script run when a player joins a server and then each time they respawn, run that same script again?

My mission has 4 playable units, when each one joins/respawns they have scripts that need to be run.

Example:

When "west01" joins/respawns then "west01.sqf" needs to be run.

When "west02" joins/respawns then "west02.sqf" needs to be run.

ect...

I've tried using a trigger with "alive west01" in the condition, however it doesn't always run the script when that player respawns.

Share this post


Link to post
Share on other sites
This thread here might help you.

Thank you, this does help.

Going to use this for when players respawn.

For example, when the unit named "west01" respawns:

this addeventhandler ["respawn","_this execvm 'west01.sqf'"];

Now, I just need to run the scripts for when players join, or will the event handler consider that as a "respawn"?

Also, what's the difference between the event handlers "respawn" and "MPRespawn"?

Share this post


Link to post
Share on other sites

Also, what's the difference between the event handlers "respawn" and "MPRespawn"?

afik Respawn is local to a pc/client

where as MPRespawn is global. meaning the data will be transfered over the network. which in most cases is not what you want

Share this post


Link to post
Share on other sites

Figured it out. I'm just running my init lines like this for each of my playable units and it seems to be working great so far!

null = execVM "west01.sqf"; this addeventhandler ["respawn","_this execvm 'west01.sqf'"];

That seems to run my script when players join and also when they respawn! Thank you again.

Share this post


Link to post
Share on other sites
Figured it out. I'm just running my init lines like this for each of my playable units and it seems to be working great so far!

null = execVM "west01.sqf"; this addeventhandler ["respawn","_this execvm 'west01.sqf'"];

That seems to run my script when players join and also when they respawn! Thank you again.

Well, the above worked when testing on a lan but not on a dedicated server. What's the best way to get the eventhandler to work on a server?

Share this post


Link to post
Share on other sites
What are you doing in the west.sqfs?

Spawning AI squad members for that player.

Share this post


Link to post
Share on other sites

Is there another way to run a script when a player respawns? The respawn event handler just isn't working for me.

Share this post


Link to post
Share on other sites

Placed Functions module and then this:

unit init:

this addEventHandler ["respawn",{_this execvm "respawn.sqf"}];

respawn.sqf:

_g = [getpos player, WEST, 5] call BIS_fnc_spawnGroup;
{[_x] joinsilent player} foreach units _g;

EH worked just fine.

Share this post


Link to post
Share on other sites
Placed Functions module and then this:

unit init:

this addEventHandler ["respawn",{_this execvm "respawn.sqf"}];

respawn.sqf:

_g = [getpos player, WEST, 5] call BIS_fnc_spawnGroup;
{[_x] joinsilent player} foreach units _g;

EH worked just fine.

Got the EH working, my script for spawning units had "if (!isServer) exitWith {};" at the top. It seems event handlers are run on the server and not the client, which was causing my units not to spawn.

Without that "if (!isServer) exitWith {};" I'm worried that depending on how many people are connected, the script will run that many times. For example, my script spawns 3 AI on a player. If 2 players are connected, then the script will run twice giving each player 6 AI... or is that not the case anymore?

Share this post


Link to post
Share on other sites

EHs (the non MP ones) only run on the machine the unit is local to. Thus, script is only run once.

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  

×