Jump to content
Sign in to follow this  
A-SUICIDAL

Teleport to Leader Script

Recommended Posts

I wrote this script a long time ago for a mission and since then have used it in a few missions I've made. My friends love using it.

I wanted to add to the script - the ability to teleport to leader and if the leader is currently in a vehicle AND if the vehicle has room in gunner, commander, cargo etc - to then teleport the player into the vehicle - and if the vehicle is full, then simply give the player a hint telling them "The leader is in a vehicle that is currently full.

I don't know how to add this, so I figured I would ask for help here. Is there a way to check if there is room in gunner, commander, cargo etc?

Base Flag init:

this addAction ["Teleport to Leader", "teleport\teleport_leader.sqf"];

teleport_leader.sqf

_unit = _this select 1;
if ( !alive s1) then {
   hint "The Team Leader is currently dead.";
} else {
if ( vehicle s1 != s1) then {
   hint "The Team Leader is currently in a vehicle.";
} else {
if ( vehicle s1 == s1) then {
   _unit setDir direction s1;
   _unit setPosATL [getPosATL s1 select 0,getPosATL s1 select 1,getPosATL s1 select 2];
   _unit setPos (s1 modelToWorld [+0.75,-1,((position s1) select 2)+0]);
};
};
};

I made a 14 man coop mission where my team only had 1 vehicle, a UN transport truck since it had 14 cargo seats. So I was able to allow player to teleport into the cargo of the vehicle using:

if ( vehicle s1 != s1) then {
   _unit moveInCargo mhq;

I've also done it with blackhawks. The problem comes in when it's a 14 man coop and the leader is in a Littlebird chopper and 4 players then try to teleport to the leader. If there is 1 empty seat in the Littlebird, I would like for one player to be able to teleport into that seat - and any other players that then try to teleport to the leader would then be given a hint telling them that the Leaders vehicle is currently full.

Edited by A-SUICIDAL

Share this post


Link to post
Share on other sites

First, thank you kylania, this is probably the 1000 time you've helped me. So I tried to apply this to my script - thinking that I was completely scripting it wrong, but on my first test run just a few minutes after reading your reply, my new script seemed to work with success. I'm still testing it right now, but I wanted to post it before Demonized beats me to it, lol.

_unit = _this select 1;

if ( !alive s1) then {
   hint "The US Team Leader is currently dead.";
} else {
if ( vehicle s1 == s1) then {
_unit setDir direction s1;
_unit setPosATL [getPosATL s1 select 0,getPosATL s1 select 1,getPosATL s1 select 2];
_unit setPos (s1 modelToWorld [+0.75,-1,((position s1) select 2)+0]);
} else {
if ( vehicle s1 != s1) then {
_freePosGunner = (vehicle s1) emptyPositions "gunner";
_freePosCommander = (vehicle s1) emptyPositions "commander";
_freePosCargo = (vehicle s1) emptyPositions "cargo";
_freePosDriver = (vehicle s1) emptyPositions "driver";
if ( _freePosGunner > 0) then {
_unit moveInGunner (vehicle s1);
} else {
if ( _freePosCommander > 0) then {
_unit moveInCommander (vehicle s1);
} else {
if ( _freePosCargo > 0) then {
_unit moveInCargo (vehicle s1);
} else {
if ( _freePosDriver > 0) then {
_unit moveInDriver (vehicle s1);
} else {
hint "The leaders vehicle currently has no empty seats to teleport to.";
};
};
};
};
};
};
};

I am totally unsure of what I scripted above and I'm sure there has to be a cleaner way to script it using exitWith or something. By all means, please feel free to perfect it. I chose moveInDriver as the lowest priority seat because sometimes you just don't want players taking the drivers seat right away when you are parked and gunning away at an enemy - then they start driving the vehicle and you can't aim your gun straight and... uhh sux, you know what I mean, heh.

Share this post


Link to post
Share on other sites

I'd probably replace the if else tree with a switch command myself, but otherwise looks good.

I'd also restructure things so everything isn't all on the left edge, makes it really hard to read. Always indent a new code block.

Hard to read:

if (something) then {
if (somethingelse) then {
stuff = "stuff";
}:
}:

Easy to read:

// check for something
if (something) then {

    // Check for something else
    if (somethingelse) then {

         // do stuff here
         stuff = "stuff";
    };
};

Share this post


Link to post
Share on other sites

Right now I am testing with a HMMWV SOV, which has a regular gunner seat and a front gunner seat. Both moveInCommander and moveInGunner will put a unit in the front gunner seat. I can't seem to get anybody into the main gunner seat.

emptyPositions

Returns the number of given positions in the vehicle.

Positions can be "Commander", "Driver", "Gunner" or "Cargo".

So in a situation where the Leader is in a HMMWV SOV vehicle and the only empty seat is the main gunner seat, my teleport to leader script will check for an available seat for front gunner and not check the main gunner seat, so instead of teleporting me into the empty main gunner seat, I instead receive a hint telling me that the Leaders vehicle is currently full - which sorta sux and I don't know how to fix that, but it's still a good script.

---------- Post added at 03:05 AM ---------- Previous post was at 02:56 AM ----------

ghetto scripter. yeah, it looks terrible doesn't it.

I'll work on my indents in the future.

I honestly don't know how to replace the if else tree with a switch command. I'm so proud of the fact that I actually got this script to work that I'm almost afraid to tweak it any further and screw it all up. I really wish I knew how.

Share this post


Link to post
Share on other sites

Maybe because it's a turret?

Personally given the incredibly unrealistic ability of that command I'd really make it more limited like you can only do it if the leader is in an MTVR and there's room in cargo kind of thing.

Might brute force it too. moveInGunner, check if they are in the vehicle or not, and repeat as needed? Messy, but it's too late for me to think straight right now. heh

Actually, taking a closer look a switch might be difficult.

Share this post


Link to post
Share on other sites

The friends I play with used to be very big Battlefield 2 players. In BF2 you had the choice to pick a spawn point or respawn on your leader, and if your leader was in a vehicle and the vehicle had an empty seat, it would respawn you in the vehicle with the leader. I do not use a halo drop flag pole script. I just use teleport to MHQ, teleport to Rally Point(leader deployed) and in some missions I've used teleport to leader. In my opinion, from having used the teleport to leader script, players most often choose to teleport to leader more often then they would choose to get in a vehicle at base or teleport to MHQ or Rally Point - because they notice that when they teleport to leader that there is much more tight teamwork and everybody sticks together and kicks ass just like when they would stick together and work as a tight team and respawn on the leader in BF2 and kick ass. Without the teleport to leader in my missions, my friends all complain. That is why I started this thread today.

... because they complained.

---------- Post added at 03:34 AM ---------- Previous post was at 03:32 AM ----------

Is this how it should look?

_unit = _this select 1;


if ( !alive s1) then {
  hint "The Team Leader is currently dead.";
  } else {
  if ( vehicle s1 == s1) then {
     _unit setDir direction s1;
     _unit setPosATL [getPosATL s1 select 0,getPosATL s1 select 1,getPosATL s1 select 2];
     _unit setPos (s1 modelToWorld [+0.75,-1,((position s1) select 2)+0]);
  } else {
  if ( vehicle s1 != s1) then {
     _freePosGunner = (vehicle s1) emptyPositions "gunner";
     _freePosCommander = (vehicle s1) emptyPositions "commander";
     _freePosCargo = (vehicle s1) emptyPositions "cargo";
     _freePosDriver = (vehicle s1) emptyPositions "driver";
     if ( _freePosGunner > 0) then {
        _unit moveInGunner (vehicle s1);
        } else {
        if ( _freePosCommander > 0) then {
        _unit moveInCommander (vehicle s1);
        } else {
        if ( _freePosCargo > 0) then {
        _unit moveInCargo (vehicle s1);
        } else {
        if ( _freePosDriver > 0) then {
        _unit moveInDriver (vehicle s1);
        } else {
        hint "The Team Leader's vehicle currently has no empty seats to teleport to.";
        };
        };
        };
     };
  };
  };
};

Again, I don't know how to replace the if else tree with a switch command. I don't even know what a switch is.

Share this post


Link to post
Share on other sites

this is how it should look: btw, you had one to many }; wich isnt surprising since it was setup in its messy state.

anyhow, not tested or changed anything, just removed the extra }; and set it up so its actually viewable.

_unit = _this select 1;


if (!alive s1) then {
hint "The Team Leader is currently dead.";
} else {
if (vehicle s1 == s1) then {
	_unit setDir direction s1;
	_unit setPosATL [getPosATL s1 select 0,getPosATL s1 select 1,getPosATL s1 select 2];
	_unit setPos (s1 modelToWorld [+0.75,-1,((position s1) select 2)+0]);
} else {
	if (vehicle s1 != s1) then {
	_freePosGunner = (vehicle s1) emptyPositions "gunner";
	_freePosCommander = (vehicle s1) emptyPositions "commander";
	_freePosCargo = (vehicle s1) emptyPositions "cargo";
	_freePosDriver = (vehicle s1) emptyPositions "driver";
	if (_freePosGunner > 0) then {
		_unit moveInGunner (vehicle s1);
	} else {
		if (_freePosCommander > 0) then {
			_unit moveInCommander (vehicle s1);
		} else {
			if (_freePosCargo > 0) then {
				_unit moveInCargo (vehicle s1);
			} else {
				if (_freePosDriver > 0) then {
					_unit moveInDriver (vehicle s1);
				} else {
					hint "The Team Leader's vehicle currently has no empty seats to teleport to.";
				};
			};
		};
	};
};
};

Like Kylania posted in 4th post, use tab between next line after {, arma edit does that automatically for me, a superb script editor.

Share this post


Link to post
Share on other sites

Thank you. Looks beautiful now.

Oh, so the action to teleport to leader isn't available to the leader, I tried re-scripting the addAction. I think I did this correctly. Anyway, I tested it and it worked.

this addAction ["Teleport to Team Leader", "teleport\teleport_leader.sqf", [], 51, true, true, "", "player != s1"]; 

No reason why the leader needs to teleport to himself, so why should he need to see the action on the base teleport flag, right?

Thanks Demonized

Share this post


Link to post
Share on other sites

The script works great when I tested in single player. I was able to teleport to the leader if he was on foot, or if he was in a vehicle that had empty seats and if his vehicle was full it would give me a hint telling me so. So then I tested it online and I was hosting and friends said that when they performed the "Teleport to Team Leader" action from the base flag - that nothing would happen at all. It wouldn't teleport them or give them a hint or anything. I honestly don't have a clue why it won't work online when I host. I really need to get this working. I am using the exact script shown above the way Demonized cleaned it up. Do I need to create some sort of variable for the player/leader "s1"? Can somebody please help me with this?

---------- Post added at 10:33 AM ---------- Previous post was at 10:04 AM ----------

Never mind, the extra }; that Demonized removed was the problem, lol. I put it back and everything is now working again. I'm not always sure about when to use a }; so i usually count how many times if is used. So if I see if seven times, then I figure I need }; seven time too.

---------- Post added at 10:44 AM ---------- Previous post was at 10:33 AM ----------

So I guess I had my first and very own novice script baby. Yay!

Working version

Flag Pole init:

this addAction ["Teleport to Team Leader", "teleport_to_leader.sqf", [], 51, true, true, "", "player != s1"];

teleport_to_leader.sqf

_unit = _this select 1;


if (!alive s1) then {
hint "The Team Leader is currently dead.";
} else {
if (vehicle s1 == s1) then {
	_unit setDir direction s1;
	_unit setPosATL [getPosATL s1 select 0,getPosATL s1 select 1,getPosATL s1 select 2];
	_unit setPos (s1 modelToWorld [+0.75,-1,((position s1) select 2)+0]);
} else {
	if (vehicle s1 != s1) then {
	_freePosGunner = (vehicle s1) emptyPositions "gunner";
	_freePosCommander = (vehicle s1) emptyPositions "commander";
	_freePosCargo = (vehicle s1) emptyPositions "cargo";
	_freePosDriver = (vehicle s1) emptyPositions "driver";
	if (_freePosGunner > 0) then {
		_unit moveInGunner (vehicle s1);
	} else {
		if (_freePosCommander > 0) then {
			_unit moveInCommander (vehicle s1);
		} else {
			if (_freePosCargo > 0) then {
				_unit moveInCargo (vehicle s1);
			} else {
				if (_freePosDriver > 0) then {
					_unit moveInDriver (vehicle s1);
				} else {
					hint "The Team Leader's vehicle currently has no empty seats to teleport to.";
				};
			};
		};
	};
};
};

Share this post


Link to post
Share on other sites

[/color]Never mind, the extra }; that Demonized removed was the problem, lol. I put it back and everything is now working again. I'm not always sure about when to use a }; so i usually count how many times if is used. So if I see if seven times, then I figure I need }; seven time too.

That's why it's important to indent your code, so that you don't have to count right curly braces, you can see easily which one matches up with each left curly brace.

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  

×