Jump to content

Recommended Posts

AllPlayers contains all players, but is it only per world, so if we are in Overworld, only all players from overworld, or is it the sum from overworld and cave?

If it is only one of them, how to get the total amount of players (overworld+cave) ?

Edited by Serpens

@DarkXeroIs there an easy way to get the number of players cave+overworld?
I'm asking for the teleportato mod, cause if 5 players are in cave and 1 in overworld and #AllPlayers is used to determine if more than half players are near teleportato, this would mean that this one player can activate the teleportato, resulting in loss of stuff for the other 5 players ... =/

25 minutes ago, Serpens said:

Is there an easy way to get the number of players cave+overworld?

local totalPlayers = #(TheNet:GetClientTable() or (TheNet:IsDedicated() and {1} or {}))-(TheNet:IsDedicated() and 1 or 0)

The first "client" in a dedicated server setup is the [Host] client so that's why there's the -1 at the end if it's dedi, else 0 because localhost and client/host is one and the same.

Using a 1-sized array in case the function returns nil so it will return 0 total.

 

"AllPlayers" is local players on a shard basis and not a total.

 

Here it is as a function instead of a oneliner.

function GetTotalPlayers()
    local clientTable = TheNet:GetClientTable()
    if(clientTable==nil)
    then
        return 0
    end
    return #clientTable - (TheNet:IsDedicated() and 1 or 0)
end

 

Edited by CarlZalph
Local host generalization.
1 hour ago, Serpens said:

I'm asking for the teleportato mod, cause if 5 players are in cave and 1 in overworld and #AllPlayers is used to determine if more than half players are near teleportato, this would mean that this one player can activate the teleportato, resulting in loss of stuff for the other 5 players ... =/

You can trigger the teleportato with players in a cave?

I thought I put a IF guard in the DoJump method of the worldjump component.

@CarlZalphthank you :)

@DarkXeroYes, but we have to take "greefer" into account. There could be one stupid user that is in cave and won't come to overworld, but the rest wants to activate teleportato. That's why I removed this IF, like you suggested.

edit:
uhmm... didnt your "IF guard" include "TheNet:GetPlayerCount()" ? Is this maybe also a way to get All players? :D So I'm dumb? :D

Edited by Serpens
11 hours ago, Serpens said:

uhmm... didnt your "IF guard" include "TheNet:GetPlayerCount()" ? Is this maybe also a way to get All players? :D So I'm dumb? :D

Precisely, I used that to compare it with #AllPlayers.

If GetPlayerCount() was different than #AllPlayers, then there are players in other shards.

11 hours ago, Serpens said:

Yes, but we have to take "greefer" into account. There could be one stupid user that is in cave and won't come to overworld, but the rest wants to activate teleportato. That's why I removed this IF, like you suggested.

So you removed the IF, then what is the problem?

If one guy is in caves and everyone else proceeds because he's stubborn, then he loses his stuff.

 

If you are asking as a general question, "is there a way to get an AllPlayers table with the player information of all shards", the answer is no. The slaves communicate what they have to communicate, and it's pretty much hard coded in TheNet methods. Master to slave communication is more flexible.

You could make some networked information travel from master to slaves (like how shard_network.lua has some components that do that), then make slaves save a persistent string (like how I did to save the data for the jump) for the master to search and parse after 5 seconds pass.

But again, for practical purposes, answer is no. Don't waste excessive effort on griefers.

@DarkXeroOkay, then I will use GetPlayerCount instead, thanks :D

The problem is, if the griefer is the only one on overworld. If I use #AllPlayers he would be able to activate teleportato while everything else is in caves ;) But with GetPlayerCount everything is fine :)

The player information stuff you posted:
Did I get it right, that you are saying: The master (=overworld) can get information from slave(=cave) easily, but the other way round it is complicated?
In teleportato mod cave don't need to get informaton from overworld.
It would be perfect, if overworld would get the information about players from cave, yes. So would that be easy or not?

On 16 сентября 2016 г. at 11:13 AM, CarlZalph said:

Here it is as a function instead of a oneliner.


function GetTotalPlayers()
    local clientTable = TheNet:GetClientTable()
    if(clientTable==nil)
    then
        return 0
    end
    return #clientTable - (TheNet:IsDedicated() and 1 or 0)
end

Little optimization. :)

local num = (TheNet:IsDedicated() and 1 or 0)
function GetTotalPlayers()
    local clientTable = TheNet:GetClientTable()
    return #clientTable - num
end

Btw if clientTable == nil, the mod MUST crash. Otherwise it will be error in another place and author will spend time for searching a problem.

36 minutes ago, Maris said:

Little optimization. :)


local num = (TheNet:IsDedicated() and 1 or 0)
function GetTotalPlayers()
    local clientTable = TheNet:GetClientTable()
    return #clientTable - num
end

Btw if clientTable == nil, the mod MUST crash. Otherwise it will be error in another place and author will spend time for searching a problem.

but why do we need a own function, when we can just use
TheNet:GetPlayerCount()
?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...