Author Topic: [Realistic Space] Clients can't see tools on re-inheriting player  (Read 1478 times)

Clients who leave my Realistic Space server leave behind their player object, which can then still be acted upon by forces such as other players or suffocation. When the client rejoins, they re-inherit their player, and (theoretically) get all their tools back.

The problem is, I can't replicate the problem. The relevant code is:

Code: (Server.cs) [Select]
package RealSpace
{
...
function GameConnection::createPlayer(%cl, %trans)
{
...
if(isObject(%pl))
{
%cl.setControlObject(%pl);
if(isObject(%this = %pl.client) && %this.getClassName() $= "AIConnection")
{
%cl.batteryPower = %this.batteryPower;
%cl.suitDamage = %this.suitDamage;
%cl.noSuit = %this.noSuit;
%this.delete();
}
%pl.client = %cl;
%cl.player = %pl;
PersistentPlayers.remove(%pl);
%pl.setShapeNameColor("1 1 1");
for(%i=0;%i<5;%i++)
messageClient(%cl, 'MsgItemPickup', '', %i, isObject(%tool = %pl.tool[%i]) ? %tool.getID() : -1, 1);
}
...
}
...
};
activatePackage("RealSpace");


Clearly, there's something more that controls player creation and/or spawning for the first time, but I can't figure it out.

Do you have Script_Player_Persistence enabled? That add-on seems to use GameConnection::onClientEnterGame() for first spawn.

Do you have Script_Player_Persistence enabled? That add-on seems to use GameConnection::onClientEnterGame() for first spawn.

No, I don't have it on.

I could just try parenting the function as normal, then delete the new player, but that's ew.

You do have an unnecessary argument in your messageClient.

Code: [Select]
messageClient(%client, 'MsgItemPickup', '', %slot, %item);

Code: [Select]
messageClient(%client, 'MsgItemPickup', '', %slot, %item, %silent);

The last argument, if true, makes the client not play the item pickup sound. Or is this one of those weird TGE things where it has to be 1 to be silent and undefined to not be?

How is that 'ew'?

Anyway, here is the source code for GameConnection::createPlayer.

Code: [Select]
function GameConnection::createPlayer(%client, %spawnPoint)
{
if(%client.player)
error("Attempting to create an angus ghost!");
if(isObject(%client.miniGame))
{
if(%client.miniGame.ending)
%data = %client.miniGame.PlayerDataBlock;
else
%data = "PlayerStandardArmor";
}
else
%data = "PlayerStandardArmor";
%oldQuotaObject = getCurrentQuotaObject();
if(isObject(%oldQuotaObject))
clearCurrentQuotaObject();
%player = new Player() {
dataBlock = %data;
client = %client;
};
if(!isObject(%player))
{
error("ERROR: GameConnection::createPlayer(" @ %client @ ", " @ %spawnPoint @ ") - failed to create player with datablock " @ %data);
return;
}
MissionCleanup.add(%player);
%client.player = %player;
%player.weaponCount = 0;
%player.spawnTime = getSimTime();
if(isObject(%oldQuotaObject))
setCurrentQuotaObject(%oldQuotaObject);
commandToClient(%client, 'ShowEnergyBar', %data.showEnergyBar);
%client.applyCharacterPrefs();
commandToClient(%client, 'PlayGui_CreateToolHud', %player.getDatablock().maxTools);
%mg = %client.miniGame;
if(isObject(%mg))
{
if(!%mg.ending)
{
%player.setShapeNameColor($MiniGameColorF[%mg.colorIdx]);
for(%i = 0; %i < 5; %i++)
{
if(isObject(%mg.startEquip[%i]))
%player.tool[%i] = %mg.startEquip[%i];
else
%player.tool[%i] = 0;
messageClient(%client, 'MsgItemPickup', "", %i, %player.tool[%i]);
}
}
else
{
%player.setShapeNameColor("1 1 1");
%player.GiveDefaultEquipment(1);
}
}
else
{
%player.setShapeNameColor("1 1 1");
%player.GiveDefaultEquipment(1);
}
%player.currWeaponSlot = -1;
%player.setTransform(%spawnPoint);
%player.setEnergyLevel(%player.getDatablock.maxEnergy);
%player.setShapeName(%client.getPlayerName(), "PASSCODE");
%player.canDismount = 1;
if(isObject(%client.camera))
%player.setTransform(%player.getEyeTransform());
%client.Player = %player;
%client.setControlObject(%player);
%p = new Projectile()
{
dataBlock = spawnProjectile;
initialVelocity = "0 0 0";
initialPosition = %player.getHackPosition();
sourceObject = %player;
sourceSlot = 0;
client = %client;

};
if(isObject(%p))
{
%p.setScale(%player.getScale());
MissionCleanup.add(%p);
}
}
« Last Edit: February 24, 2014, 07:15:06 PM by $trinick »

Good lord trinick at least give it some half decent formatting, here's a nicer version.

Code: [Select]
function GameConnection::createPlayer(%client, %spawnPoint)
{
if(%client.player)
error("Attempting to create an angus ghost!");

if(isObject(%client.miniGame))
{
if(%client.miniGame.ending)
%data = %client.miniGame.PlayerDataBlock;
else
%data = "PlayerStandardArmor";
}
else
%data = "PlayerStandardArmor";

%oldQuotaObject = getCurrentQuotaObject();

if(isObject(%oldQuotaObject))
clearCurrentQuotaObject();

%player = new Player()
{
dataBlock = %data;
client = %client;
};

if(!isObject(%player))
{
error("ERROR: GameConnection::createPlayer(" @ %client @ ", " @ %spawnPoint @ ") - failed to create player with datablock " @ %data);
return;
}

MissionCleanup.add(%player);

%client.player = %player;
%player.weaponCount = 0;
%player.spawnTime = getSimTime();

if(isObject(%oldQuotaObject))
setCurrentQuotaObject(%oldQuotaObject);

commandToClient(%client, 'ShowEnergyBar', %data.showEnergyBar);

%client.applyCharacterPrefs();

commandToClient(%client, 'PlayGui_CreateToolHud', %player.getDatablock().maxTools);
%mg = %client.miniGame;

if(isObject(%mg) && !%mg.ending)
{
%player.setShapeNameColor($MiniGameColorF[%mg.colorIdx]);

for(%i = 0; %i < 5; %i++)
{
if(isObject(%mg.startEquip[%i]))
%player.tool[%i] = %mg.startEquip[%i];
else
%player.tool[%i] = 0;

messageClient(%client, 'MsgItemPickup', "", %i, %player.tool[%i]);
}
}
else
{
%player.setShapeNameColor("1 1 1");
%player.GiveDefaultEquipment(1);
}

%player.currWeaponSlot = -1;

%player.setTransform(%spawnPoint);
%player.setEnergyLevel(%player.getDatablock.maxEnergy);
%player.setShapeName(%client.getPlayerName(), "PASSCODE");

%player.canDismount = 1;

if(isObject(%client.camera))
%player.setTransform(%player.getEyeTransform());

%client.Player = %player;
%client.setControlObject(%player);

%p = new Projectile()
{
dataBlock = spawnProjectile;
initialVelocity = "0 0 0";
initialPosition = %player.getHackPosition();
sourceObject = %player;
sourceSlot = 0;
client = %client;
};

if(isObject(%p))
{
%p.setScale(%player.getScale());
MissionCleanup.add(%p);
}
}

For some reason, completely empty lines makes code hard to read for me.

Really all you added was empty lines, so sorry I didn't go back and space the code out more after translating it I guess. I'd still had some actual code errors when I posted it, so I was more concerned with making sure I translated it correctly than how it looked.


You defined %client.player twice Trinick.

I didn't write the code, blame Badspot.

I didn't write the code, blame Badspot.
: /

Where did you get it from? You can't access Blockland's source code.

: /

Where did you get it from? You can't access Blockland's source code.
[abbr=Can we decrypt DSOs now?]Nice.[/abbr]
« Last Edit: February 24, 2014, 11:23:10 PM by Greek2me »

Speak for yourself. I don't go around showing people how Blockland authenticates (or for that matter figuring it out) so Badspot shouldn't really have an issue with me posting snippets of source code to benefit peoples understanding of how some safe functions work. I removed the passcode for setShapeName, so nothing in that snippet is really that secretive.