Home   Help Search Login Register  

Author Topic: Player variables, instances, scope and a big brain fart  (Read 1124 times)

0 Members and 1 Guest are viewing this topic.

Offline Mr.Peanut

  • Former Staff
  • ****
  • urp!
I am used to MP scripting in OFP, but our clan only plays respawnless coop. As such I find myself at a loss with respawn and JIP issues.

If I define an array:
Code: [Select]
PlayerList = [p1, p2 ,p3 ....];and player p1 disconnects but someone else JIPs into his slot. Is the PlayerList array now useless as far as p1 is concerned for every node except p1's?

ArmA2 better damn well have a new eventHandler class for respawn states.
urp!

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Player variables, instances, scope and a big brain fart
« Reply #1 on: 03 Sep 2008, 17:03:48 »
It depends on whether you have respawn and/or whether you have ai disabled. Obviously, you understand the situation with respawn/JIP turned off.

If AI are enabled, then P1 (as stored in the array) will be fine if someone leaves and the same, or another, person joins, since the actual soldier object will be carried through. If you or the AI respawns in this situation, then the PlayerList elements will point towards the first corpse and won't point at the current incarnation. Thus, you'd want to create the array as and when you needed it, so you got the latest value of P1 (or just use a call compile format to just get the value of "P%1", unless you want to iterate through the entire array).

If AI are disabled, then when the player disconnects, then the soldier object is destroyed and when someone connects, it is recreated (so will not be the same). So, on JIP or respawn, as described above, you have to get the current value of P1, not the value it was at the start of the mission, which is what would be recorded in PlayerList if it was set up in your init.sqf.

If you put a killed handler on someone, you can tell when they respawn (assumes that they are respawning players or AI using player bodies, and that they have a name set in the editor):
Code: (respawn_event.sqf) [Select]
// Put in player soldier init:
//   nul = [this] execVM "respawn_event.sqf"

private ["_player"];
_player = _this select 0;

_player addEventHandler ["KILLED", {
_corpse = _this select 0;

_name = vehicleVarName _corpse;

[_name] spawn
{
_name = _this select 0;

_getObject = compile _name;

waitUntil { alive (call _getObject) };

(call _getObject) sideChat "I respawned!";
};
}];
« Last Edit: 15 Sep 2008, 12:39:27 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)