OFPEC Forum
Editors Depot - Mission Editing and Scripting => Arma2 - Editing/Scripting Multiplayer => Topic started by: Cougarxr7 on 01 Jul 2009, 07:52:40
-
I remmember playing Battlefield2 and in it you could respawn on your Squad Leader.
Has anyone come acrossed any code like that for Arma?
I have an idea of how it should be setup but then again I am no scripter.
I hope to make this possible to help encourage ground pounding.
Thanks!
-
I've not tested this (but it should work), and it does absolutely no checking to see if the unit is spawning inside a building, etc., but it does provide basic functionality.
Put this in your "Description.ext":
respawn = "BASE";
respawnDelay = 10;Adjust the respawnDelay value to match the number of seconds you want to wait until respawn.
Put this in a file called "respawnOnLeader.sqf":
if(!isServer) exitWith {};
private["_leader", "_marker"];
_leader = _this select 0;
_marker = _this select 1;
while {true} do {
_marker setMarkerPos (getPos _leader);
sleep 0.5;
};
Then in your "init.sqf" put:
[squadLeader, "respawn_west"] execVM "respawnOnLeader.sqf";
Replace "squadLeader" with the name of your unit (defined in the editor). Don't put quotes around this value.
Replace "respawn_west" with "respawn_east" if you want this functionality for OPFOR, etc... leave the quotes surrounding it. Then make sure you've placed a marker, name as above, in the editor.
-
"respawn_west", "respawn_east" are only used as respawn points in "BASE" respawn mode. "INSTANT" makes you respawn where you died.
Although your method, assuming you use "BASE" respawn, will work if there is only one group per side, it won't work in most missions.
// Remember to place the side spawn markers in a safe position.
respawn = "BASE";
respawnDelay = 10;
if (not isDedicated) then {
[] spawn {
waitUntil { alive player };
player addEventHandler ["KILLED", {
[] spawn
{
waitUntil { alive player };
if ((alive (leader player)) and (player != (leader player))) then {
// Move the player just behind the leader, but ensure they arrive on the ground.
_spawnPos = getPos ((vehicle _leader) modelToWorld [0, -2, 0]);
_spawnPos set [2, 0];
player setPos _spawnPos;
};
};
}];
};
};
Note: This doesn't take into account vehicles, since that is a bit messy (and I can't be bothered right now, but if it is important, maybe someone else could deal with that special case for you using emptyPositions). You'll spawn in just behind the leader (or leader's vehicle) and hope that the leader isn't on the edge of a cliff, in a plane or driving a tank backwards :whistle:
You could also use BIS_fnc_findSafePos (from BIS Functions module) to find a clear position in which to spawn.
NOTE: All example code UNTESTED!
EDIT: Remembered additional spawn required. Also should ensure that leader is alive before spawning on them.
-
"respawn_west", "respawn_east" are only used as respawn points in "BASE" respawn mode. "INSTANT" makes you respawn where you died.
Whoops, 'slip of the fingers'. I really need to double-check my stuff a little more before I post, eh? :)
You could also use BIS_fnc_findSafePos (from BIS Functions module) to find a clear position in which to spawn.
To be honest, Spooner, I learn something pretty much every time you post ;)
-
Actually, you might learn something new, but I just realised I missed out a spawn I needed in the code I posted last. Edited it in the previous post rather than repeated it. Oops (sorry!).
-
I tried the following code.
init.sqf
//Code by Spooner
if (not isDedicated) then {
[] spawn {
waitUntil { alive player };
player addEventHandler ["KILLED", {
[] spawn
{
waitUntil { alive player };
if ((alive (leader player)) and (player != (leader player))) then {
// Move the player just behind the leader, but ensure they arrive on the ground.
_spawnPos = getPos ((vehicle _leader) modelToWorld [0, -2, 0]);
_spawnPos set [2, 0];
player setPos _spawnPos;
};
};
}];
};
};
init.sqf
[1-1-A, "respawn_west"] execVM "data\scripts\respawnOnLeader.sqf";
descripton.ext
respawn="BASE";
respawndelay=30;
It retuned this error.
[1-1-A, "respawn_west"] execVM "data\scripts\>
Error position: <A, "respawn_west"] execVM "data\scripts\>
Error Undefined variable in expression: a
Thanks!
-
Sorry, I didn't specifically tell you how to call the script. From init.sqf:
[] execVM "data\scripts\respawnOnLeader.sqf";
You will need to place specific respawn markers on the map as appropriate for regular "BASE" respawn (since you want to respawn at base if the leader is dead or if you are the leader).
[1-1-A, "respawn_west"] execVM "data\scripts\respawnOnLeader.sqf";
Cannot work, since 1-1-A is the name of a group, not a variable containing that group (hard to go back to first principles here). This is why you get an error. Apart from that, I don't ask for variables to be sent to the script (if you see one or more lines like _xxx = _this select N; at the top of a script, then it tells you that you need to send it parameters).
-
Respawn marker for "Base" is set.
I Change the name from 1-1-A to eng5. eng5 is the name of the squad leader.
[eng5, "respawn_west"] execVM "data\scripts\respawnOnLeader.sqf";
It returned this error.
[eng5, "respawn_west"] execVM "data\scrip>
Error position: <eng5, "respawn_west"] execVM "data\scrip>
Error Undefined variable in expression: eng5
Thanks!
-
Please read my post again! I tell you how to do it in the first code snippet (I've further commented it now to make it utterly clear).
-
Spooner
Please remmember with me, old and meds.
init.sqf
[] execVM "data\scripts\respawnOnLeader.sqf";descripton.ext
respawn="BASE";
respawndelay=30;
respawnOnLeader.sqf
//Code by Spooner
if (not isDedicated) then {
[] spawn {
waitUntil { alive player };
player addEventHandler ["KILLED", {
[] spawn
{
waitUntil { alive player };
if ((alive (leader player)) and (player != (leader player))) then {
// Move the player just behind the leader, but ensure they arrive on the ground.
_spawnPos = getPos ((vehicle _leader) modelToWorld [0, -2, 0]);
_spawnPos set [2, 0];
player setPos _spawnPos;
};
};
}];
};
};
Ran this on a test server.
I was set to Squad Leader in editor, friends were Squad Members, all privates in editor.
I was 2000 meters from default spawn. All members said 'away' on icon.
My friends respawned at base everytime.
My respawn timer is 30secs, I have a kill cam script that runs at players death.
Do you think that 30secs respawn could be the problem or does that matter?
What am I missing/doing wrong?
Any ideas?
Thanks!
-
You aren't wrong at all. I'm just sloppy and didn't do a live test because I think I know everything :whistle:
// Call from init.sqf with:
// [] execVM "data\scripts\respawnOnLeader.sqf";
if (not isDedicated) then {
[] spawn {
waitUntil { alive player };
player addEventHandler ["KILLED", {
[] spawn
{
private ["_leader", "_spawnPos"];
waitUntil { alive player };
_leader = leader player;
if ((alive _leader) and (player != _leader)) then {
// Move the player just behind the leader, but ensure they arrive on the ground.
_spawnPos = (vehicle _leader) modelToWorld [0, -2, 0];
_spawnPos set [2, 0]; // Ensure respawn on the ground.
player setPos _spawnPos;
};
};
}];
};
};
2m behind leader seemed a bit too close, so I moved it to 5m. Easy enough to change it to an appropriate value though.
Can't be bothered ensuring that you are facing the leader either. It isn't critical though, since the important thing is just that you aren't placed in front of the leader where he would get a shock and shoot you... ;)
-
Spooner, it works! :D
Been busy testing. Thank you so much for your help!
It's really cool, squad members spawn randomly between leader and default.
Members were able to spawn inside a building with leader and outside of vehicles the leader was in.
I was in a stairwell that went to nowhere and member spawned under the stairs inside the walls but was able to walk right out.
In a helo which was landing and a member spawned on the ground below the leader.
Where do you change the number to 5, This one [0, -2, 0]; or this one [2, 0]; ?
I am so close to having this modded mission done.
Have a few more questions, starting new thread.
Thanks!
-
Yeah, sorry, I said 5m behind but I left it as 2m in the code I gave you!
_spawnPos = (vehicle _leader) modelToWorld [0, -5, 0]; // -5 is 5m behind leader
_spawnPos set [2, 0]; // Ensure respawn on the ground. Set z-coordinate to 0.
-
Modified version, works for multiple groups etc.
respawn = "BASE";
respawnDelay = 10;Adjust the respawnDelay value to match the number of seconds you want to wait until respawn.
if(isDedicated) exitWith {};
_side = side player;
waituntil {
"respawn_west" setMarkerPosLocal (getPos leader player);
sleep 0.5;
0 > 1
};
execVM "respawnOnLeader.sqf";
-----------
Untested code:
if(isDedicated) exitWith {};
_side = side player;
waituntil {
format["respawn_%1", _side] setMarkerPosLocal (getPos leader player);
sleep 0.5;
0 > 1
};
-
Thanks Rommel92,
I will try it and test it!
Need to find out why I'm losing squad control.
-
Rommel's does mostly the same as mine, but uses an continual loop rather than an event handler, so is less efficient. It also doesn't place the player behind the leader. Also, when there is no leader alive to spawn at, you will respawn out at sea ([0, 0, 0], the position of nullObject) rather than at base (all easy to add, but just so you know ;) ).
Does have the advantage that moving the spawn-point means that you will automatically spawn in a safe place, rather than in a wall, which is a big boon. Well, at least I assume respawn is that clever.
Scripts could be merged though, to get the best of both worlds.
@Rommel:
waituntil {
"respawn_west" setMarkerPosLocal (getPos leader player);
sleep 0.5;
0 > 1
};
Is clearer as:
while { true } do {
"respawn_west" setMarkerPosLocal (getPos leader player);
sleep 0.5;
};
Since waitUntil implies you are running once-per-frame. while is better for loops with sleep in.
-
Thanks for clearing that up for me, in any case, unfortunately respawn isn't that smart. :whistle:
It does try to make an effort but.
-
Oh right. Still, plenty of other methods to ensure that the guy appears in a sensible place. You could spawn a local HeliH and see where it appears or use that BIS function I mentioned.
-
Hello all.
I'm using a script to move respawn at random intervals to random people, but I have this problem:
Also, when there is no leader alive to spawn at, you will respawn out at sea ([0, 0, 0],
How would I overcome this?
And how do I move the marker behind, instead of onto a player? Or better yet, a certain distance from the player in the direction of original spawn?
-
As I gave in examples above, it is best to keep the base marker in place and to only move the player from that position if there is a viable leader to move to. Saves continually moving the marker, too, so is more efficient.
If you need to move the marker, then:
_spawnPos = getPos ((vehicle _leader) modelToWorld [0, -5, 0]);
"respawn_west" setMarkerPos _spawnPos;
-
Sorry for bringing up an older thread, especially if there is one newer, but how would one go about modifying this script so that you would spawn on your respective squad leader if and only if he's alive. If he's dead, you instead spawn as a crow?