Jump to content
Sign in to follow this  
tyrspawn

This script won't work for JIPs, HALP

Recommended Posts

1. All players are supposed to spawn in their respective bradleys, as per their initialization line

2. All players are supposed to respawn in the cargo of their respective bradleys when they die

3. Each player is added to their respective team on the init line

4. The script is called with:

init.sqf:

 
//script to move respawns into IFVs

//non-JIP player
if (!(isNull player)) then  
{	
waitUntil { alive player };

[] execVM "scripts\movetoIFV.sqf";
};

// JIP player
if (!isServer && isNull player) then  
{
waitUntil { alive player };

[] execVM "scripts\movetoIFV.sqf";
};

movetoIFV.sqf:

// Checking if player has successfully synchronized (for JIPs)
if (!isDedicated && isNull player) then
{
waitUntil {!isNull player};
};

while {true} do
{
if (!alive player) then
{
	// Wait until player respawns
	waitUntil {alive player};

	// delay ensures client is synced with server before doing stuff.
	sleep 0.1;

	// Make sure player isn't at the lobby screen?
	if (player != player) exitWith {};

	switch (group player) do
	{
		case team1:
		{
			player moveInCargo brad1;
		};

		case team2:
		{
			player moveInCargo brad2;
		};

		case team3:
		{
			player moveInCargo brad3;
		};

		case team4:
		{
			player moveInCargo brad4;
		};
	};
};	

};

I think it's a problem with how the script is being called... I have also tried execVM. With execVM JIP players will spawn in the bradley, as designed, but the move to bradley script upon respawn does not work. With the current init they will JIP at respawn_west (not the bradley) and the respawn script does not work either. If they respawn they go right back to respawn_west. Both ways it works fine for non-JIP players.

Share this post


Link to post
Share on other sites

Try this:

Init.sqf:

// Player and JIP
if !(isDedicated) then
{
waitUntil { (player == player) };

player addEventHandler ["Killed", {_this execVM "scripts\movetoIFV.sqf"} ]; 
};

movetoIFV.sqf:

while { (True) } do
{
sleep 1;

if (alive player) exitWith
{
	switch (group player) do
	{
		case team1:
		{
			player moveInCargo brad1;
		};

		case team2:
		{
			player moveInCargo brad2;
		};

		case team3:
		{
			player moveInCargo brad3;
		};

		case team4:
		{
			player moveInCargo brad4;
		};
	};
};
};

Share this post


Link to post
Share on other sites

If you want to run something for all players but not for a dedicated server just use if (!isDedicated)

Share this post


Link to post
Share on other sites
If you want to run something for all players but not for a dedicated server just use if (!isDedicated)

It has to work for both... or at least for dedicated.

Share this post


Link to post
Share on other sites

Well both conditions will always be false on a dedicated server, so if that's not what you want, change that.

Besides, running 2 different "IF" conditions while whatever is inside is exactly the same is rather silly. Just use "OR" (or ||).

Share this post


Link to post
Share on other sites
Try this:

Init.sqf:

// Player and JIP
if !(isDedicated) then
{
waitUntil { (player == player) };

player addEventHandler ["Killed", {_this execVM "scripts\movetoIFV.sqf"} ]; 
};

movetoIFV.sqf:

while { (True) } do
{
sleep 1;

if (alive player) exitWith
{
	switch (group player) do
	{
		case team1:
		{
			player moveInCargo brad1;
		};

		case team2:
		{
			player moveInCargo brad2;
		};

		case team3:
		{
			player moveInCargo brad3;
		};

		case team4:
		{
			player moveInCargo brad4;
		};
	};
};
};

This does not work for JIPs. It works for regular players though.

Share this post


Link to post
Share on other sites

If you want it to work for all players, JIP or not, do:

if (isDedicated) exitWith {};
waitUntil {!isNull player};
// enter here any code you want to run for all players as soon as they join.

You don't want to waitUntil {!isNull player}' on a dedicated server as that condition will never be true as on a dedicated server player is always null.

Where are you defining team1/2/3/4 and brad1/2/3/4? You need to make sure that the variables are defined before you use them, and check that you can actually move into the vehicle before you moveInCargo.

Besides your whole movetoifv.sqf is messy. Why are you using exitWith? You do realize it doesn't break the loop, but rather just breaks the current iteration of the loop and then just starts the next one? So basically the loop will never end and if you would've used if (alive player) then {...}; it would've done the exact same thing. If you want the player to run a script on every respawn, use:

while {true} do
{
waitUntil {!alive player}; // wait until player dies
waitUntil {alive player}; // wait until player is alive again
// enter here whatever you want to do when the player respawns
}; // loop will continue forever (that is, until mission is over)

Edited by galzohar

Share this post


Link to post
Share on other sites
If you want it to work for all players, JIP or not, do:

if (isDedicated) exitWith {};
waitUntil {!isNull player};
// enter here any code you want to run for all players as soon as they join.

You don't want to waitUntil {!isNull player}' on a dedicated server as that condition will never be true as on a dedicated server player is always null.

Where are you defining team1/2/3/4 and brad1/2/3/4? You need to make sure that the variables are defined before you use them, and check that you can actually move into the vehicle before you moveInCargo.

Besides your whole movetoifv.sqf is messy. Why are you using exitWith? You do realize it doesn't break the loop, but rather just breaks the current iteration of the loop and then just starts the next one? So basically the loop will never end and if you would've used if (alive player) then {...}; it would've done the exact same thing. If you want the player to run a script on every respawn, use:

while {true} do
{
waitUntil {!alive player}; // wait until player dies
waitUntil {alive player}; // wait until player is alive again
// enter here whatever you want to do when the player respawns
}; // loop will continue forever (that is, until mission is over)

Teams are defined on each unit's init line:

team2 = group this;

etc

The bradleys are just unit names of the bradleys.

Thanks for your help.

I'm not sure what you mean by the first part... you say to use something then say not to ever use it. Very confused and frustrated. Please tell me specifically what I have to change to make this work. Pulling my hair out.

Edited by tyrspawn

Share this post


Link to post
Share on other sites

What if a group has no units existing (AI disabled and no players playing them)? In that case you will get an error!

I didn't say not to use exitWith, I said not to use it the way you were using it because it's confusing for both you and the people trying to read your code.

If you just put if (isDedicated) exitWith {}; then the script will never run on the dedicated server, which is probably what you want as the dedicated server doesn't have a player. Since it's at the start of the script and not within {}, it will exit the whole script and not just that iteration of the while loop.

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  

×