Home   Help Search Login Register  

Author Topic: killing the disconnected?  (Read 1489 times)

0 Members and 1 Guest are viewing this topic.

Offline D.murphy man

  • Members
  • *
  • I'm a llama!
killing the disconnected?
« on: 11 Apr 2008, 01:00:51 »
Hey all, just a quick question:

How would i go about detecting when, and what player has disconnected, then simply setdammage 1 the players character (dont want to use deletevehicle) and all AI in his squad.

I have tried using onplayerdissconnected with numerous variations of (_x setdammage 1) foreach units _id/_name/player/this etc.... with no success, am i on the right track or completely wrong on how to use this command?

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: killing the disconnected?
« Reply #1 on: 11 Apr 2008, 01:36:13 »
You might keep track of each player connected and disconnected:
Code: [Select]
//init.sqf
new_player = objNull;
if (isServer) then
{
   players = [];
   []spawn
   {
      while {true} do
      {
         waitUntil {!isNull new_player};
         players = players + [new_player];
         new_player = objNull;
      };
   };

   []spawn
   {
      private["_i"];
      while {true} do
      {
         Sleep 5;
         for [{_i=0},{_i != count players},{_i=_i+1}] do
         {
            if (!isPlayer (players select _i)) then
            {
               (players select _i) setDamage 1;
               players set [_i, objNull];
            };
         };
         players = players - [objNull];
      };
   };
};

[]spawn
{
   waitUntil {alive player};
   new_player = player;
   publicVariable "new_player";
};

Offline Rommel92

  • Members
  • *
Re: killing the disconnected?
« Reply #2 on: 11 Apr 2008, 03:15:22 »
Does the player not die usually? (Unless you don't have DisabledAi = 1 in the description.ext).

Quote
            if (!isPlayer (players select _i)) then
            {
               (players select _i) setDamage 1;
               {If (isNull _x) then {_x setDamage 1};} ForEach units group (players select _i);
               players set [_i, objNull];
            };
« Last Edit: 11 Apr 2008, 03:18:56 by Rommel92 »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: killing the disconnected?
« Reply #3 on: 11 Apr 2008, 17:44:58 »
If you have AI disabled, then the player soldier will appear/disappear on connection/disconnection. If AI is enabled, then the player will take over an existing AI when connecting and be taken over by AI when disconnecting.

If AI is disabled, then you wouldn't need to delete the player when disconnected and wouldn't be able to find the followers of a player using this example script, since the player object would have been deleted before this script could do anything about it.

If AI is enabled, then the player would continue to operate normally as an AI after disconnection and killing him would just make him respawn normally as an AI who would then continue in the game as usual; it wouldn't make the ex-player soldier stop being in the game. You would be able to delete his retinue with this script in this case.

Quote from: D.murphy man
I have tried using onplayerdissconnected with numerous variations of (_x setdammage 1) foreach units _id/_name/player/this etc.... with no success, am i on the right track or completely wrong on how to use this command?
Within the onPlayerDisconnected handler code, you have access to _id (a number unique to a copy of ArmA) and _name (a string name of the player). You don't have access to the soldier object that the player used to be connected to and since the game doesn't keep a list of player objects for you, you need to manually monitor player objects as shown (you can actually use SPON Core to do this for you. Since I know you use this in your mission, contact me if you need wisdom on how to do this).
« Last Edit: 11 Apr 2008, 17:47:07 by Spooner »
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)