Home   Help Search Login Register  

Author Topic: Squad Leader as a respawn point. Solved!  (Read 9563 times)

0 Members and 1 Guest are viewing this topic.

Offline Cougarxr7

  • Members
  • *
Squad Leader as a respawn point. Solved!
« 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!
« Last Edit: 06 Jul 2009, 16:06:32 by Cougarxr7 »
If this thread is in volation of forum rules , please delete.

Offline JamesF1

  • Editors Depot Staff
  • *****
    • JamesBurgess.co.uk
Re: Squad Leader as a respawn point.
« Reply #1 on: 01 Jul 2009, 11:26:45 »
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":
Code: [Select]
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":
Code: (respawnOnLeader.sqf) [Select]
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:
Code: (init.sqf) [Select]
[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.
« Last Edit: 01 Jul 2009, 14:38:33 by JamesF1 »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Squad Leader as a respawn point.
« Reply #2 on: 01 Jul 2009, 13:54:17 »
"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.

Code: (description.ext) [Select]
// Remember to place the side spawn markers in a safe position.
respawn = "BASE";
respawnDelay = 10;

Code: (init.sqf) [Select]
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.
« Last Edit: 01 Jul 2009, 19:05:49 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline JamesF1

  • Editors Depot Staff
  • *****
    • JamesBurgess.co.uk
Re: Squad Leader as a respawn point.
« Reply #3 on: 01 Jul 2009, 14:38:22 »
"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? :)

Quote
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 ;)
« Last Edit: 01 Jul 2009, 14:58:10 by JamesF1 »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Squad Leader as a respawn point.
« Reply #4 on: 01 Jul 2009, 19:03:50 »
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!).
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Cougarxr7

  • Members
  • *
Re: Squad Leader as a respawn point.
« Reply #5 on: 03 Jul 2009, 09:05:24 »
I tried the following code.
init.sqf
Code: [Select]
//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
Code: [Select]
[1-1-A, "respawn_west"] execVM "data\scripts\respawnOnLeader.sqf";
descripton.ext
Code: [Select]
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!
 

If this thread is in volation of forum rules , please delete.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Squad Leader as a respawn point.
« Reply #6 on: 03 Jul 2009, 13:06:33 »
Sorry, I didn't specifically tell you how to call the script. From init.sqf:
Code: (This is right way) [Select]
[] 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).

Code: (This is wrong, so don't do it) [Select]
[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
Code: (How to tell if something requires parameters) [Select]
_xxx = _this select N; at the top of a script, then it tells you that you need to send it parameters).
« Last Edit: 03 Jul 2009, 16:08:12 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Cougarxr7

  • Members
  • *
Re: Squad Leader as a respawn point.
« Reply #7 on: 03 Jul 2009, 15:23:37 »
Respawn marker for "Base" is set.
I Change the name from 1-1-A to eng5. eng5 is the name of the squad leader.
Code: [Select]
[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!
« Last Edit: 03 Jul 2009, 15:27:07 by Cougarxr7 »
If this thread is in volation of forum rules , please delete.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Squad Leader as a respawn point.
« Reply #8 on: 03 Jul 2009, 16:07:24 »
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).
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Cougarxr7

  • Members
  • *
Re: Squad Leader as a respawn point.
« Reply #9 on: 04 Jul 2009, 08:49:52 »
Spooner
Please remmember with me, old and meds.
init.sqf
Code: [Select]
[] execVM "data\scripts\respawnOnLeader.sqf";descripton.ext
Code: [Select]
respawn="BASE";
respawndelay=30;


respawnOnLeader.sqf
Code: [Select]
//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!
« Last Edit: 04 Jul 2009, 09:22:12 by Cougarxr7 »
If this thread is in volation of forum rules , please delete.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Squad Leader as a respawn point.
« Reply #10 on: 04 Jul 2009, 16:09:50 »
You aren't wrong at all. I'm just sloppy and didn't do a live test because I think I know everything  :whistle:

Code: [Select]
// 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... ;)
« Last Edit: 04 Jul 2009, 16:24:09 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Cougarxr7

  • Members
  • *
Re: Squad Leader as a respawn point.Solved!
« Reply #11 on: 06 Jul 2009, 15:59:05 »
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!
« Last Edit: 12 Jul 2009, 03:39:39 by Cougarxr7 »
If this thread is in volation of forum rules , please delete.

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Squad Leader as a respawn point. Solved!
« Reply #12 on: 06 Jul 2009, 16:11:12 »
Yeah, sorry, I said 5m behind but I left it as 2m in the code I gave you!
Code: [Select]

_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.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Rommel92

  • Members
  • *
Re: Squad Leader as a respawn point.
« Reply #13 on: 06 Jul 2009, 16:36:30 »
Modified version, works for multiple groups etc.

Code: (description.ext) [Select]
respawn = "BASE";
respawnDelay = 10;
Adjust the respawnDelay value to match the number of seconds you want to wait until respawn.

Code: (respawnOnLeader.sqf) [Select]
if(isDedicated) exitWith {};
_side = side player;
waituntil {
  "respawn_west" setMarkerPosLocal (getPos leader player);
  sleep 0.5;
  0 > 1
};

Code: (init.sqf) [Select]
execVM "respawnOnLeader.sqf";
-----------

Untested code:
Code: (respawnOnLeader.sqf) [Select]
if(isDedicated) exitWith {};
_side = side player;
waituntil {
  format["respawn_%1", _side] setMarkerPosLocal (getPos leader player);
  sleep 0.5;
  0 > 1
};
« Last Edit: 06 Jul 2009, 16:38:36 by Rommel92 »

Offline Cougarxr7

  • Members
  • *
Re: Squad Leader as a respawn point. Solved!
« Reply #14 on: 07 Jul 2009, 02:36:39 »
Thanks Rommel92,
 I will try it and test it!
Need to find out why I'm losing squad control.
If this thread is in volation of forum rules , please delete.