Author Topic: Having a client control another client's player object  (Read 662 times)

Trying to get client A to have full control over client B's player movements at will.

I assume it involves setControllingObject, but I'd rather know for sure what's the best way to approach this problem.

Alright so it's client.getcontrolobject(player);. Now I'm wondering, how do you remove client B's control over his own player so client A can control client B freely?
« Last Edit: December 17, 2015, 02:51:51 PM by Path »

For the sake of simplicity I'm going to refer to the client taking over as client A and the one being taken over as client B.

Now. Before you give client A control, you need to assign client B something to control. Otherwise their screen will freak out and they'll probably leave the server. I suggest giving client B control of their camera object(%client.camera) and setting it to observer mode on their body. You can now give client A control of client B's body. Don't forget to change both client's %client.player variable. Otherwise when they talk, play an emote, etc. it'll be their previous player object that does it. You might also need to tell client A what client B's inventory is.

For swapping the clients should I do

%clientB.player.client = %client.A?

also when the controlled client, client B, dies, client A's player object will be broken. Should I pass an ondeath function that returns client a to their bodies?

Something like this could work. Try to learn based on comments.

Code: [Select]
//%this = %client
function GameConnection::TakeOver(%this, %clientTarget, %warn)
{
if(!isObject(%clientTarget)) //Does the client exist?
if(!isObject(%clientTarget = findClientByName(%clientTarget))) //If not, let's see if they typed in a client's name
return;

if(%clientTarget.getClassName() !$= "GameConnection") //If it's not an actual client don't continue
return;

if(!isObject(%playerTarget = %clientTarget.player)) //Does their player even exist?
return;

if(!isObject(%camTarget = %clientTarget.camera)) //This should rarely happen but let's make sure if the target has a camera
return;

%this.setControlObject(%playerTarget); //Set our client control to the target's player

//Let's not break the target's camera, so we will make it spy their own player
%camTarget.setMode("Observer", %playerTarget);
%clientTarget.setControlObject(%camTarget);

if(%warn) //If warn is set to 1, we will alert the target that the client took over his body.
%clientTarget.chatMessage("\c5" @ %this.getPlayerName() @ " has taken over your body!");
}

also when the controlled client, client B, dies, client A's player object will be broken. Should I pass an ondeath function that returns client a to their bodies?
Package Armor::onDisabled(%armor, %object) and check to see if the player was controlled by another client with %object.getControllingClient() and check if it matches with %object.client
For %object.client to still exist you must put the parent at the end of your modified code, because one the parent hits the client variable is set to 0
« Last Edit: December 17, 2015, 03:05:57 PM by Kyuande »

As mentioned above. You should also do:

%this.player.client = 0;

%this.player = %playerTarget;
%playerTarget.client = %this;

%clientTarget.player = 0;

I probably should make the client's player delete as well since it's going to just sit there and rot