Home   Help Search Login Register  

Author Topic: [SOLVED] Insurgency style respawn script  (Read 2446 times)

0 Members and 1 Guest are viewing this topic.

Offline bardosy

  • Honoured Contributor
  • ***
  • campaign designer
    • CartooDiv
[SOLVED] Insurgency style respawn script
« on: 10 Dec 2012, 09:11:18 »
I like Insurgency's respawn system, but I cannot find it in public forums, so I cannot implement it in my mission as an independent script. So I decided to create it, but I stucked.

First, how it works in Insurgency: When you die, the respawn countdown don't start and the respawn scoretable don't show. You just see a squadmate from back. And you can navigate with left-right button between your living squadmates. And when you find someone, who are in a good position, you just hit the Enter button and respawn countdown is start and scoretable is showing.

I guess, I could do everything except the not running respawn and late the respawn. How can I force to wait the BIS respawn system until the player selecting the good places?

(The real Insurgency respawn made much more, but I could satisfy with this. Originally it can stop the respawn countdown if the selected squadmate move close to an enemy and then you have to select an other squadmate.)

----------EDIT:----------------

I found setPlayerRespawnTime command. It's great, but I stucked in other point. So, now the idea is:

1. setPlayerRespawnTime 300
2. Create a camera behind living teammates
3. player can change the selected living playmates with arrow buttons
4. when he found the perfect place, hit the Enter button
5. respawn_west setMarkerPos getPos selected squadmate
6. setPlayerRespawnTime 5

The problem is: after the player die, you can move the respawn place anywhere, it's ineffective. Player will respawn where the respawn_west was in the moment when he died.
Can I somehow move the respawn place AFTER the player died? How insurgency's creator did it?

-----------------EDIT:------------------------------

I solved it and it worked.

You need two file. The small one (lackoRespawn_keydown.sqf):
Code: [Select]
_key = _this select 1;

//player globalchat format ["key=%1", _key];


//right arrow
if (_key == 205) then {
  lck_actualmate = lck_actualmate + 1;
  if (lck_actualmate >= count lck_livingmates) then {
    lck_actualmate = 0;
  };
};
//left arrow
if (_key == 203) then {
  lck_actualmate = lck_actualmate - 1;
  if (lck_actualmate < 0) then {
    lck_actualmate = (count lck_livingmates)-1;
  };
};



if (_key == 76) then {
  TitleText["Right Arrow = next squadmate\nLeft Arrow = previous squadmate\nEnter = respawn","PLAIN DOWN"];
};


//Enter key
if (_key == 28) then { keyout = _key };

The main script (lackoRespawn.sqf):
Code: [Select]
_unit = _this select 0;
private ['_magazines','_weapons','_backpack','_backpackweap','_backpackmags'];

_weapons = weapons _unit;
_magazines = magazines _unit;

_backpack = typeOf unitBackpack _unit;
_backpackmags = getMagazineCargo unitBackpack _unit;
_backpackweap = getWeaponCargo unitBackpack _unit;


if (_unit == player) then {

  setPlayerRespawnTime 500;

  _squad = group player;
  lck_livingmates = [];
  {
    if (alive _x and _x!=player) then {lck_livingmates = lck_livingmates + [_x];};
  } foreach units _squad;

  lck_actualmate = 0;
  _elozoactual=lck_actualmate;
  keyout = 0;

  openMap false;
  0 fadesound 0;
  disableserialization;
  keyspressed = compile preprocessFile "lackoRespawn_keydown.sqf";
  _displayID = (findDisplay 46) displaySetEventHandler ["KeyDown","_this call keyspressed"];

  _cam = "camera" camcreate [0,0,0];
  _cam cameraeffect ["internal", "back"] ;
  showCinemaBorder false;
  _cam camsettarget (lck_livingmates select lck_actualmate);
  _cam camsetrelpos [0,-5,2.5];
  _cam camcommit 0;

  TitleText["Right Arrow = next squadmate\nLeft Arrow = previous squadmate\nEnter = respawn","PLAIN DOWN"];

  _ido=0;
  while {_ido<=500} do {

    if (_ido mod 10 == 0) then {
      TitleText["Right Arrow = next squadmate\nLeft Arrow = previous squadmate\nEnter = respawn","PLAIN DOWN"];
    };

    if (keyout > 0) exitwith {};

    _currentmate = lck_livingmates select lck_actualmate;
    _tempcnt=0;
    lck_livingmates = [];
    {
      if (alive _x and _x!=player) then {
        lck_livingmates = lck_livingmates + [_x];
        if (_x==_currentmate) then {lck_actualmate = _tempcnt;};
        _tempcnt = _tempcnt + 1;
      };
    } foreach units _squad;

    if (count lck_livingmates == 0) exitwith {};

    _cam camsettarget (lck_livingmates select lck_actualmate);
    _cam camsetrelpos [0,-5,2.5];
    _cam camcommit 0;   

    waituntil{camCommitted _cam};
    _ido = _ido + 0.02;
    sleep 0.02;
  };

  TitleText[" ","PLAIN DOWN"];

  (findDisplay 46) displayRemoveAllEventHandlers "KeyDown";
  setPlayerRespawnTime 5;

  _ido=0;
  while {_ido<=5} do {
    _cam camsettarget (lck_livingmates select lck_actualmate);
    _cam camsetrelpos [0,-5,2.5];
    _cam camcommit 0;   

    waituntil{camCommitted _cam};
    _ido = _ido + 0.5;
    sleep 0.5;
  };


  _newpos = getPos glbase;

  if (keyout > 0) then {
    _newpos = getPos (lck_livingmates select lck_actualmate);
    //player globalchat format ["cel=%1, x=%2, y=%3", name (lck_livingmates select lck_actualmate),(_newpos select 0),(_newpos select 1)];

    if ((_newpos select 0)>50 and (_newpos select 1)>50) then {
      player globalchat "good respawn";
    } else {
      player globalchat "base respawn";
      _newpos = getPos glbase;
    };
  } else {
      player globalchat "baserespawn";
      _newpos = getPos glbase;
  };


  player cameraEffect ["terminate","back"];
  camdestroy _cam;
  0 fadesound 1; 




  waituntil {alive player};


  player setPos _newpos;

  _unit = player;
  removeallweapons _unit;
  removeAllItems _unit;
  removeBackpack _unit;

  {_unit addmagazine _x} foreach _magazines;
  {_unit addweapon _x} foreach _weapons;
  _primw = primaryWeapon _unit;
  if (_primw != "") then {
      _unit selectWeapon _primw;
      // Fix for weapons with grenade launcher
      _muzzles = getArray(configFile>>"cfgWeapons" >> _primw >> "muzzles");
      _unit selectWeapon (_muzzles select 0);
  };
  if(_backpack != "") then {
      _unit addBackpack _backpack;
      clearWeaponCargo (unitBackpack _unit);
      clearMagazineCargo (unitBackpack _unit);

      for "_i" from 0 to (count (_backpackmags select 0) - 1) do {
(unitBackpack _unit) addMagazineCargo [(_backpackmags select 0) select _i,(_backpackmags select 1) select _i];
      };
      for "_i" from 0 to (count (_backpackweap select 0) - 1) do {
(unitBackpack _unit) addWeaponCargo [(_backpackweap select 0) select _i,(_backpackweap select 1) select _i];
      };
  };


};

You have to write in the playable unit's init field: xhandle = this addEventHandler ["killed", "_this execvm 'lackoRespawn.sqf'"]
« Last Edit: 11 Dec 2012, 20:30:36 by bardosy »
Fix bayonet!