papam77 Posted June 28, 2013 Share Posted June 28, 2013 Hello, is possible to get player count from dimension? If yes, how? Link to comment
csiguusz Posted June 28, 2013 Share Posted June 28, 2013 Possible. Loop through all players, check their dimension and if they are in the given dimension count them. Link to comment
xXMADEXx Posted June 28, 2013 Share Posted June 28, 2013 I made this a while ago for a server: function getAllPlayerInDimension ( dimension ) local rValue = { }; for i, v in ipairs ( getElementsByType ( "player" ) ) do if ( getElementDimension ( v ) == dimension ) then table.insert ( rValue, v ); else return; end; end return rValue; end Link to comment
arezu Posted June 28, 2013 Share Posted June 28, 2013 I made this a while ago for a server: function getAllPlayerInDimension ( dimension ) local rValue = { }; for i, v in ipairs ( getElementsByType ( "player" ) ) do if ( getElementDimension ( v ) == dimension ) then table.insert ( rValue, v ); end end return rValue; end fixed Link to comment
xXMADEXx Posted June 28, 2013 Share Posted June 28, 2013 I made this a while ago for a server: function getAllPlayerInDimension ( dimension ) local rValue = { }; for i, v in ipairs ( getElementsByType ( "player" ) ) do if ( getElementDimension ( v ) == dimension ) then table.insert ( rValue, v ); end end return rValue; end fixed What was wrong with mine? Link to comment
denny199 Posted June 28, 2013 Share Posted June 28, 2013 Because this line: " else return; end; " was useless Link to comment
xXMADEXx Posted June 28, 2013 Share Posted June 28, 2013 Because this line:" else return; end; " was useless ah, I never tested the function lol, thanks. Link to comment
VEILUS Posted April 11, 2018 Share Posted April 11, 2018 Okay, but how to use this ? --Where is the error? function getAllPlayerInDimension ( dimension ) local rValue = { }; for i, v in ipairs ( getElementsByType ( "player" ) ) do if ( getElementDimension ( v ) == dimension ) then table.insert ( rValue, v ); end end return rValue; end function SetDimensionLobby() getAllPlayerInDimension (0) outputChatBox ("all players in Dimension 0"..table.concat(rValue)) end addCommandHandler ("s",SetDimensionLobby,false) --I want to check if Dimension 0 has a player, if true, then check Dimension 1, if true, then the next dimension, until Dimension (n) == 0 players, if dimension (n) == 0 players then setElementDimension (source , Dimension (n)), how to do this? (Sorry, I'm brasilian and my English is low level). Link to comment
Moderators IIYAMA Posted April 11, 2018 Moderators Share Posted April 11, 2018 iprint(getAllPlayerInDimension (0)) First debug. After executing the function, it returns a table which contains all players from that dimension. Just run the code and check your debug-console. Link to comment
VEILUS Posted April 11, 2018 Share Posted April 11, 2018 Why is my mod setting the dimension for all players? function joinHandler() fadeCamera(source, true) setCameraTarget(source) spawnPlayer(source, 0, 0, 5) end addEventHandler("onPlayerLogin", getRootElement(), joinHandler) function playerToLobby() triggerClientEvent ( "PlayerOnLobby", root ) end addEventHandler ("onPlayerSpawn",getRootElement(),playerToLobby) function getAllPlayerInDimension ( dimension ) rValue = { }; for i, v in ipairs ( getElementsByType ( "player" ) ) do if ( getElementDimension ( v ) == dimension ) then table.insert ( rValue, v ); end end return rValue; end function SetDimensionLobby(thePlayer) g_NPlayers = true g_NState = 0 while g_NPlayers do getAllPlayerInDimension (g_NState) if (#rValue>0) then g_NState = g_NState + 1; outputChatBox ("O valor é maior que 0") else g_NPlayers = false outputChatBox ("A dimension setada é: "..g_NState) end end local s_PlayerDimension = g_NState setElementDimension (source,s_PlayerDimension) end addEvent ("onCommand", true) addEventHandler ("onCommand",getRootElement(),SetDimensionLobby) Link to comment
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