Author Topic: Possession?  (Read 680 times)

Hey guys, I'm making a possession gamemode where a person can press the light key to possess someone in their vicinity. Here's the code:

   function servercmdLight(%client)
   {
      if(%client.isBossGhost == 1 && $gamemode $= "Possession" && %client.ghostCD < $Sim::Time)
      {
         %client.ghostCD = $Sim::Time + 3;
         %start = %client.player.getEyePoint();
         %scaled = vectorScale(%client.player.getEyeVector(), 4);
         %end = vectorAdd(%start, %scaled);
         %result = containerRaycast(%start, %end, $Typemasks::PlayerObjectType, %client.player);
         %tPlayer = getWord(%result, 0);
         if(isObject(%tPlayer))
         {
            %client.player.delete();
            %client.setControlObject(%tPlayer);
            %tPlayer.client.setControlObject(%tPlayer.client.camera);
            //Exposition
            %client.chatMessage("\c6You have successfully possessed" SPC %tPlayer.client.name @ "!");
            %tPlayer.client.chatMessage("\c7You have been possessed by the \c6ghost\c7," SPC %client.name);
         }
         return;
      }
      parent::servercmdLight(%client);
   }


The problem is that the ghost takes control fine and dandy, and can walk around. Yet, the target client can still control the tools, and can Ctrl-K the problem away. Is there any way to completely kick out the old controller, or do I have to spawn a player at the target's coordinates and painstakingly copy the avatar's appearance?
edit: if so, how could i do that?
« Last Edit: May 31, 2015, 07:41:58 PM by Johnny Blockhead »

instead of taking control of the player just create a copy of the player with the same avatar and weapons and make your boss control that, then move the old player somewhere far away and put them into some sort of camera view mod or something, if you want to regain control delete the copy player, move the old player back and give back the victim camera control

Reset the client/player object ties like so:
%newClient.player = %oldClient.player;
%oldClient.player = "";
%newClient.player.client = %newClient;

After that set the old player to observe the new player, or the old player will have weird lag issues where they THINK they are still controlling their own player.

Reset the client/player object ties like so:
%newClient.player = %oldClient.player;
%oldClient.player = "";
%newClient.player.client = %newClient;

After that set the old player to observe the new player, or the old player will have weird lag issues where they THINK they are still controlling their own player.

This is half the ideal solution. The reason the above work is because the possessed person's client is still linked to the player they no longer control. The new client, in order to have complete control of the player object, will need to have everything updated to it. So you will still have to send over the tools.