Jump to content

Sign in to follow this  
Chairborne

Help with respawn

Recommended Posts

Hello, i'm experiencing problems with the respawns i set up.

I created an anphibious assault mission on lingor where players and vehicles respawn on a ship (http://forums.bistudio.com/showthread.php?123082-LPD-29-San-Antonio-Class). Players and vehicles MUST respawn on a given height, position and direction in order to be on the ship instead of just sinking in the ocean so here's what i did:

For the vehicles i used the simple vehicle spawn script by tophe (http://www.armaholic.com/page.php?id=6080), writing the following in the init of my vehicles:

this setposasl [getpos this select 0, getpos this select 1, 14.4]; veh = [this, 15, 120, 0, false, FALSE, "this setposasl [getpos this select 0, getpos this select 1, 14.4]; this setDir 90"] execVM "vehicle.sqf"

It worked just fine trying it in multiplayer with LAN setup all by myself, but when i launch a second instance of the game to check how things appear to other clients the script STILL works BUT the setdir command stops working, so the vehicles spawn facing 0°. At first i thought it was because of the script so i tried another one: http://forums.bistudio.com/showthread.php?79070-Vehicle-Respawn-with-Name-amp-Init same thing all over again, when i run it by myself in lan everything works as it is supposed to but when i join in with the second instance the setdir command stops working again (while setpos still works).

Second problem is the players respawn. I am using the default respawn system to place a player on the map then through the respawn.sqf i give the command:

waitUntil {alive player};
player moveIncargo ambulance;

Because it's an easy way to take the player on board of the ship without some tricky scripting that is out of my league by now.

Still, when i launch the game by myself they work fine, the host (me) always gets in the ambulance, then when a second player joins it does not work (host goes always in ambulance, even after said JIP, client does not). Another thing i noticed is that when all the players are in the lobby when i launch the game, at first everything works fine, but as soon as someone JIP, said problems come out (im not really sure on this part, maybe i didn't test it deeply enough).

I don't know if these two problems are related or due to two different things, i am new to scripting and couldn't figure it out myself nor searching in alread existing threads, can anybody help me?

Share this post


Link to post
Share on other sites

I bumped my thread 25 hours after opening it, didn't think it was such big issue. Thanks anyways.

Share this post


Link to post
Share on other sites

It sounds like your having a locality issue and maybe a timing issue, please post more of your code and how you are calling it.

Share this post


Link to post
Share on other sites

untested in mp enviroment

init.sqf

waitUntil {isDedicated || !isNull player};

"iDied" addPublicVariableEventHandler {
_pv = _this select 1;
_who = _pv select 0;
_whereTo = _pv select 1;
if (!local _whereTo) exitWith {};
_who assignAsCargo _whereTo;
_who moveInCargo _whereto;
};

player addEventHandler ["Respawn",
{
waitUntil {alive player};
	if (local ambulance) then{
		player assignAsCargo ambulance;
		player moveInCargo ambulance;
	}else{
		iDied= [player,ambulance];
		publicVariable "iDied";
	};
}
];


Share this post


Link to post
Share on other sites

This is what i had before in my init.sqf:

execVM "briefing.sqf";

if (!isDedicated) then
{
player addEventHandler ["KILLED", "execVM 'respawn.sqf'"];
};

Now i'm thinking about a locality issue too because when i tried it again yesterday, as soon as i disconnected with my second instance everything turned back to normal. Vehicles spawned again as how they were supposed to. Maybe publicvariable or setvehicleinit could help resolving this but i have no clue on how or where to use them.

I'll try the code cuel wrote (thanks!) now, anyway.

Share this post


Link to post
Share on other sites

See this post: http://forums.bistudio.com/showthread.php?137110-MP-Dynamic-mission-questions&p=2187562&viewfull=1#post2187562

And you should read this guide : http://community.bistudio.com/wiki/6thSense.eu:EG

Your having some of the same problems.

basically you need to create a player init that runs locally to ensure it is being run on the correct machine and client.

Share this post


Link to post
Share on other sites

And that should work for the setdir command of vehicles too or it's better to use a setvehicleinit so that every client receives the command? I don't have it really clear on how this works but i think that even though they're both caused by locality they are two different problems. I read the topic on the wiki to inform myself but i am still not sure on what way to solve this.

Share this post


Link to post
Share on other sites
  cuel said:
waitUntil {isDedicated || !isNull player};

You aware that waituntil condition will Always return true in any enviroment right? (same has not having the waitUntil at all) :)

Share this post


Link to post
Share on other sites
  AlphaSixtyOne said:
And that should work for the setdir command of vehicles too or it's better to use a setvehicleinit so that every client receives the command? I don't have it really clear on how this works but i think that even though they're both caused by locality they are two different problems. I read the topic on the wiki to inform myself but i am still not sure on what way to solve this.

I think that the reason your having a problem with the veh not facing the correct direction is a timing issue, but this is just a guess. By that I mean the timing is off between when the veh is created then moved and then set dir.

Normaly the use of setVehinit is frowned upon. It creates a lot of un-needed network traffic and it is used a lot by hackers.

These veh are empty so they are local to the server, if your going to use that respawn script, I would just call a small script from the init of the veh, in that script limit it to only run on the server and then setdir, then I would try using modletoworld command to move the veh. That will force it to keep its dir that you just set.

I would stop tryint to do it all in the init of the veh which gets processed on all clients

Edited by Riouken

Share this post


Link to post
Share on other sites
  neokika said:
You aware that waituntil condition will Always return true in any enviroment right? (same has not having the waitUntil at all) :)

... what?

Try this in your init.sqf

sleep 1; 
hint "before wait";
waitUntil {false};
hint "after wait!";

The second hint never shows up. waitUntil suspends the script until whatever the condition is becomes true. In this case, never, since false can never be true.

Share this post


Link to post
Share on other sites

I think what he was talking about was the fact that your checking if it IS a (dedicated server) OR if the (player is not null).

That will always be true, because if it is on a dedicated server then the first condition will be true, if its on a client or self hosted then the second will be true.

I think what you meant to put was this:

[left][color=#0000BB][font=monospace][i]waitUntil [/i][/font][/color][color=#007700][font=monospace][i]{[/i][/font][/color][i]![/i][color=#0000BB][font=monospace][i]isDedicated [/i][/font][/color][color=#007700][font=monospace][i]&& ![/i][/font][/color][color=#0000BB][font=monospace][i]isNull player[/i][/font][/color][color=#007700][font=monospace][i]};[/i][/font][/color][/left]


I added a (!) in front of (isDedicated) and changed from or to AND.

The reason I say this is that you are using the player command later on in that script and that should never be run on the server, it will always be false, and cause errors.

[left][color=#0000BB][font=monospace]waitUntil [/font][/color][color=#007700][font=monospace]{[/font][/color][color=#0000BB][font=monospace]isDedicated [/font][/color][color=#007700][font=monospace]|| ![/font][/color][color=#0000BB][font=monospace]isNull player[/font][/color][color=#007700][font=monospace]};

[/font][/color][color=#DD0000][font=monospace]"iDied" [/font][/color][color=#0000BB][font=monospace]addPublicVariableEventHandler [/font][/color][color=#007700][font=monospace]{
   [/font][/color][color=#0000BB][font=monospace]_pv [/font][/color][color=#007700][font=monospace]= [/font][/color][color=#0000BB][font=monospace]_this select 1[/font][/color][color=#007700][font=monospace];
   [/font][/color][color=#0000BB][font=monospace]_who [/font][/color][color=#007700][font=monospace]= [/font][/color][color=#0000BB][font=monospace]_pv select 0[/font][/color][color=#007700][font=monospace];
   [/font][/color][color=#0000BB][font=monospace]_whereTo [/font][/color][color=#007700][font=monospace]= [/font][/color][color=#0000BB][font=monospace]_pv select 1[/font][/color][color=#007700][font=monospace];
   if (![/font][/color][color=#0000BB][font=monospace]local _whereTo[/font][/color][color=#007700][font=monospace]) [/font][/color][color=#0000BB][font=monospace]exitWith [/font][/color][color=#007700][font=monospace]{};
   [/font][/color][color=#0000BB][font=monospace]_who assignAsCargo _whereTo[/font][/color][color=#007700][font=monospace];
   [/font][/color][color=#0000BB][font=monospace]_who moveInCargo _whereto[/font][/color][color=#007700][font=monospace];
};

[/font][/color][/left]


[color=#ff0000]

[left][font=monospace]player [/font][color=#0000BB][font=monospace]addEventHandler [/font][/color][color=#007700][font=monospace][[/font][/color][color=#DD0000][font=monospace]"Respawn"[/font][/color][color=#007700][font=monospace],[/font][/color][/left]


[/color]

[left][color=#007700][font=monospace]    {
   [/font][/color][color=#0000BB][font=monospace]waitUntil [/font][/color][color=#007700][font=monospace]{[/font][/color][color=#0000BB][font=monospace]alive player[/font][/color][color=#007700][font=monospace]};
       if ([/font][/color][color=#0000BB][font=monospace]local ambulance[/font][/color][color=#007700][font=monospace]) [/font][/color][color=#0000BB][font=monospace]then[/font][/color][color=#007700][font=monospace]{
           [/font][/color][color=#0000BB][font=monospace]player assignAsCargo ambulance[/font][/color][color=#007700][font=monospace];
           [/font][/color][color=#0000BB][font=monospace]player moveInCargo ambulance[/font][/color][color=#007700][font=monospace];
       }else{
           [/font][/color][color=#0000BB][font=monospace]iDied[/font][/color][color=#007700][font=monospace]= [[/font][/color][color=#0000BB][font=monospace]player[/font][/color][color=#007700][font=monospace],[/font][/color][color=#0000BB][font=monospace]ambulance[/font][/color][color=#007700][font=monospace]];
           [/font][/color][color=#0000BB][font=monospace]publicVariable [/font][/color][color=#DD0000][font=monospace]"iDied"[/font][/color][color=#007700][font=monospace];
       };
   }
];  [/font][/color][/left]


  cuel said:
... what?

Try this in your init.sqf

sleep 1; 
hint "before wait";
waitUntil {false};
hint "after wait!";

The second hint never shows up. waitUntil suspends the script until whatever the condition is becomes true. In this case, never, since false can never be true.

Edited by Riouken

Share this post


Link to post
Share on other sites

No that's in the init.sqf, it's a JIP check. Basically waitUntil (!isNull player) means that the player has loaded into the game. Most people check for player == player which is basically the same thing.

But you're right, the dedicated server shouldn't have the event handler so, that's easily solved.

waitUntil {isDedicated || !isNull player};

"iDied" addPublicVariableEventHandler {
   _pv = _this select 1;
   _who = _pv select 0;
   _whereTo = _pv select 1;
   if (!local _whereTo) exitWith {};
   _who assignAsCargo _whereTo;
   _who moveInCargo _whereto;
};

if (!isDedicated) then {
player addEventHandler ["Respawn",
	{
	waitUntil {alive player};
		if (local ambulance) then{
			player assignAsCargo ambulance;
			player moveInCargo ambulance;
		}else{
			iDied= [player,ambulance];
			publicVariable "iDied";
		};
	}
];  
};

But I just tested this and appearently it didn't work. I'm going to investigate.

Share this post


Link to post
Share on other sites

Regarding the setdir i looked up on the wiki and someone suggested to simply put it before the setposasl command, and that WORKED, that is good, maybe it executes the commands in the same way objectives are displayed in briefing (backwards so from last to first command). Now i replaced the setposasl with setposition and in the array i used the position from the mission.sqm file. I have to make some more tests because i'm not sure of the results though.

Riouken i have a question, how do i use the modeltoworld command? I looked it up on the wiki but some things are not clear. This is the example:

Array = object modelToWorld modelPos

Array should be the offset from the defined position, object is obviously the model that the command refers to but what does modelpos stand for? It means that i have to set its position in relation to an already existing object or i can use coordinates (or what i put in the setposasl command, as in "getpos this select 0, getpos this select 1, 14")? The voice on the wiki was not too clear to me sorry.

---------- Post added at 03:44 AM ---------- Previous post was at 03:42 AM ----------

As for the respawns, i followed riouken's advice on the other thread, made a trigger for local players and a jip_init.sqf file, now both already connected AND jip players respawn in the ambulance. Thanks!!

Edit: the setdir trick worked for helo but not for hummvees.

Edited by AlphaSixtyOne

Share this post


Link to post
Share on other sites

Its used like this, this is a teleport script for a player from a flag but you get the idea. Basically the way it works is instead moveing an object to a pos, it creates the world around the object relative to some other place.

// Who are we teleporting
_caller = _this select 1;


// Move them 5m behind the flag.
_worldPos = tele_flag modelToWorld [0,-5,0];
_caller setPos [_worldPos select 0, _worldPos select 1, 0];

Edited by Riouken

Share this post


Link to post
Share on other sites

Yup nice that you got it solved. I thought moveInCargo had to be local to the vehicle, but it was the player that had to be local.

Share this post


Link to post
Share on other sites
  Riouken said:
Its used like this, this is a teleport script for a player from a flag but you get the idea. Basically the way it works is instead moveing an object to a pos, it creates the world around the object relative to some other place.

// Who are we teleporting
_caller = _this select 1;


// Move them 5m behind the flag.
_worldPos = tele_flag modelToWorld [0,-5,0];
_caller setPos [_worldPos select 0, _worldPos select 1, 0];

So basically i need to create the model somewhere in the map THEN give the model a point for reference in order for it to move to the desired location with modeltoworld. Correct?

Share this post


Link to post
Share on other sites

Not exactly.

Lets say you want a plane to move to the aircraft carier and be next to the genarator.

_plane = _this select 0;

// First we refrence the generator and then we provide the offset [-5,0,0]
// That offset will put it 5m beside the generator.
_worldPos = generator modelToWorld [-5,0,0];

// Now we need to get the plane there.
_plane setPos [_worldPos select 0, _worldPos select 1, 0]; 

This is just another way to teleport something, it is usually used to teleport something to a pos offset from an object. but since we create the world pos in model space instead of just a regular getpos or provideing coords, the object retains its original dir. its normaly considered a side effect or something to work around when using this command.

But as I said before I think you were having a timing issue and that's why doing the setdir before you teleported is working, this has the same effect.

Share this post


Link to post
Share on other sites
  cuel said:
... what?

The second hint never shows up. waitUntil suspends the script until whatever the condition is becomes true. In this case, never, since false can never be true.

You misunderstood what I meant.

You had:

waituntil { isDedicated || !isnull player };

The above will ALWAYS return true...No matter if it's currently being checked within a Dedicated Server/hosted Server/SinglePlayer!

Meaning, all you are actually doing is wasting CPU cycles.

Share this post


Link to post
Share on other sites

No it's a JIP check like I said. The player does not equal the player until he's fully loaded into the game

Dedicated server continues, otherwise the init halts until the player is fully connected and is equal to himself

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  

×