Author Topic: Why are loaded bricks on an internet/dedicated server given a client of "-1"?  (Read 427 times)

Code: [Select]
function GameConnection::spawnPlayer(%this) {
[irrelevant code]

$LoadingBricks_BrickGroup = %this.brickgroup;
$LoadingBricks_Client = %this;
$LoadingBricks_ColorMethod = 3;
$LoadingBricks_DoOwnership = false;
$LoadingBricks_FileName = "Add-Ons/Gamemode_Numb3rs/bls/station.bls";
$LoadingBricks_Silent = true;
$LoadingBricks_StartTime = getSimTime();
$loadOffset = %xpos SPC %ypos SPC %zpos;
ServerLoadSaveFile_Start($LoadingBricks_FileName);

return parent::spawnPlayer(%this);
}

function fxDTSBrick::onLoadPlant(%this) {
parent::onLoadPlant(%this);
// not everything is set automatically
%this.schedule(50,renameNumbersBrick);
}

function fxDTSBrick::renameNumbersBrick(%this) {
//only works on SP for whatever reason
//%client = %this.client;

if(%client $= "") {
%group_name = %this.getGroup().getName();
%client = findClientByBL_ID(getSubStr(%group_name,stripos(%group_name,"_")+1,strLen(%group_name)));
}

[irrelevant code]

When bricks are loaded by the first part of the code in Single Player, I can use %client = %this.client to get the client from the loaded brick. On internet/dedicated servers, I can't do this, it's "-1" for everything.
I have to resort to grabbing the brickgroup the brick is in and do string manipulation on the name of said brickgroup, then find the client via the BL_ID obtained from the group name. This works on everything fine, but it seems completely unnecessary.
Is there a reason for everything loaded being "-1" on internet/dedicated servers?

EDIT: It's actually a bigger issue now with clients using the same IDs, stuff.
« Last Edit: May 23, 2015, 12:02:57 AM by TheBlackParrot »

I believe that brickgroup.client works.

To answer the why:
1. The client isn't saved with the brick, only the BL_ID.
2. 90% of the time the client doesn't exist when loading the brick, they could join later, or not at all.

You should never need to use .client unless you are doing things in onPlant or other functions where there already has to be a client. Otherwise, you should be using the brickgroup for this sort of thing. I mean that generically, not necessarily directed at you, TheBlackParrot