Author Topic: Doing something to all players in a server [Solved]  (Read 2277 times)

^ There will be absolutely no difference in speed because you don't run it 31 billion times, just 20

^ There will be absolutely no difference in speed because you don't run it 31 billion times, just 20
It's good practice to write the most efficient versions of code

Is everyone done stuffting up this thread now? The OP was appropriately answered from the first post, we don't need to belabor anything else

It works, but it will call the loop a last time with an inexistant object.

Good point

It's good practice to write the most efficient versions of code

Is everyone done stuffting up this thread now? The OP was appropriately answered from the first post, we don't need to belabor anything else

Okay

Lol.
This thread exploded within the 30 minutes I didn't look at it.

The first post was an excellent answer that I went with, it works great and thank you very much treynolds.

Now my secondary question, does a variable assigned to a client save upon the client disconnecting?

Like

client.test = 5

When they return will the client.test still be 5?

Lol.
This thread exploded within the 30 minutes I didn't look at it.

The first post was an excellent answer that I went with, it works great and thank you very much treynolds.

Now my secondary question, does a variable assigned to a client save upon the client disconnecting?

Like

client.test = 5

When they return will the client.test still be 5?
Obviously not
It's a new object

No it will not save automatically. You will either have to make your own save/load system or tie in with an existing save/load system (Script_Player_Persistence)

Okay, I can do that.

What if a player Self Deletes, will they lose that variable again?

Like

%client.test = 5
[death]testplayer

Will the %client.test still be 5?

Okay, I can do that.

What if a player Self Deletes, will they lose that variable again?

Like

%client.test = 5
[death]testplayer

Will the %client.test still be 5?
client =|= player
client varibles will stay, player varibles will be gone as it's a new object

Yes because it's assigned to the client object as opposed to the player object.

Edit: Dammit, Mold.

I'm sorry horrible confused.

Mold said earlier that a client variable won't stay after leaving/rejoining as it's a new object.

Then he says if a client Self Deletes it will stay as it's the same object.

I know player variables are lost via death in VCE and client is kept

I think I understand this now:

Client stays as long as the player is on the server
Player is lost when the player object is changed
Neither stay when connection is lost

I'm sorry horrible confused.

Mold said earlier that a client variable won't stay after leaving/rejoining as it's a new object.

Then he says if a client Self Deletes it will stay as it's the same object.

I know player variables are lost via death in VCE and client is kept

I think I understand this now:

Client stays as long as the player is on the server
Player is lost when the player object is changed
Neither stay when connection is lost
You need to get this:

Someone that joins/leaves a server, is a client (%client)
A client that spawns, will now also have a player (%client.player).
If the client calls /Self Delete, the player will get killed.

You need to get this:

Someone that joins/leaves a server, is a client.
A client that spawns, will get a player.
If the client calls /Self Delete, the player will get killed.
Understood.
Thank you

Okay so I tried the whole saving/loading thing

Code: [Select]
function gameConnection::onClientEnterGame(%client)
{
Parent::onClientEnterGame(%client);
%fw = new FileObject();
%fw.openForRead("config/server/test/" @ %client.BL_ID @ ".txt");
%testvariable = %fw.readLine();
if(%testvariable >= 1)
{
%client.test = %testvariable;
%fw.close();
%fw.delete();
}
else
{
%fw.close();
%fw.delete();
%client.test = 100;
}
}
function gameConnection::onClientLeaveGame(%client)
{
%fw = new FileObject();
%fw.openForWrite("config/server/test/" @ %client.BL_ID @ ".txt");
%fw.writeLine(%client.test);
%fw.close();
%fw.delete();
Parent::onClientLeaveGame(%client);
}

This works great when a player disconnects while spawned and rejoins and such.

The issue is that if the player leaves with the client.test being 50 then joins, doesn't spawn, disconnects, rejoins and lets himself spawn it will reset to 100.

If they spawn after they leave it works just fine.

You can use gameConnection::autoAdminCheck instead of onClientEnterGame, that should solve it.
But remember for autoadmincheck you must return the parent, unlike oncliententergame.

Code: [Select]
function gameConnection::autoAdminCheck(%client)
{
    //do stuff
    return parent::autoAdminCheck(%client);
}

Do what HellsHero said.

As for an explanation of why, onClientEnterGame is called when the client is finished loading, whereas autoAdminCheck is called when they first enter the server.

Also, code neatness changes:
If a piece of code is being executed no matter what the condition (%fw.close and %fw.delete), put it after the if...else block, rather than in every condition.