Serpens Posted September 15, 2016 Share Posted September 15, 2016 (edited) 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 September 28, 2016 by Serpens Link to comment https://forums.kleientertainment.com/forums/topic/70169-solved-is-allplayers-per-world/ Share on other sites More sharing options...
Serpens Posted September 16, 2016 Author Share Posted September 16, 2016 @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 ... =/ Link to comment https://forums.kleientertainment.com/forums/topic/70169-solved-is-allplayers-per-world/#findComment-814209 Share on other sites More sharing options...
CarlZalph Posted September 16, 2016 Share Posted September 16, 2016 (edited) 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 September 16, 2016 by CarlZalph Local host generalization. Link to comment https://forums.kleientertainment.com/forums/topic/70169-solved-is-allplayers-per-world/#findComment-814213 Share on other sites More sharing options...
DarkXero Posted September 16, 2016 Share Posted September 16, 2016 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. Link to comment https://forums.kleientertainment.com/forums/topic/70169-solved-is-allplayers-per-world/#findComment-814249 Share on other sites More sharing options...
Serpens Posted September 16, 2016 Author Share Posted September 16, 2016 (edited) @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? So I'm dumb? Edited September 16, 2016 by Serpens Link to comment https://forums.kleientertainment.com/forums/topic/70169-solved-is-allplayers-per-world/#findComment-814351 Share on other sites More sharing options...
DarkXero Posted September 17, 2016 Share Posted September 17, 2016 11 hours ago, Serpens said: uhmm... didnt your "IF guard" include "TheNet:GetPlayerCount()" ? Is this maybe also a way to get All players? So I'm dumb? 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. Link to comment https://forums.kleientertainment.com/forums/topic/70169-solved-is-allplayers-per-world/#findComment-814556 Share on other sites More sharing options...
Serpens Posted September 17, 2016 Author Share Posted September 17, 2016 @DarkXeroOkay, then I will use GetPlayerCount instead, thanks 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? Link to comment https://forums.kleientertainment.com/forums/topic/70169-solved-is-allplayers-per-world/#findComment-814573 Share on other sites More sharing options...
DarkXero Posted September 17, 2016 Share Posted September 17, 2016 10 minutes ago, Serpens said: 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? I said the opposite. Link to comment https://forums.kleientertainment.com/forums/topic/70169-solved-is-allplayers-per-world/#findComment-814576 Share on other sites More sharing options...
Maris Posted September 26, 2016 Share Posted September 26, 2016 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. Link to comment https://forums.kleientertainment.com/forums/topic/70169-solved-is-allplayers-per-world/#findComment-818641 Share on other sites More sharing options...
Serpens Posted September 26, 2016 Author Share Posted September 26, 2016 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() ? Link to comment https://forums.kleientertainment.com/forums/topic/70169-solved-is-allplayers-per-world/#findComment-818651 Share on other sites More sharing options...
Maris Posted September 27, 2016 Share Posted September 27, 2016 15 hours ago, Serpens said: but why do we need a own function, when we can just use TheNet:GetPlayerCount() ? Because there is no API documentation I guess. Thanks for tip. Link to comment https://forums.kleientertainment.com/forums/topic/70169-solved-is-allplayers-per-world/#findComment-818990 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now