List - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Plugins (https://forum.cuberite.org/forum-1.html) +--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html) +--- Thread: List (/thread-2225.html) |
List - Schwertspize - 11-29-2015 Stupid question... how can I have a list, which is empty by default. SocialSpyList = {} I wanna add Player:GetUUID(), loop over the list while running DoWithPlayerByUUID() I also want to remove items (just remove a specific UUID, eg on a disable command or on leave) so where do I have to define the list, so I can use it in OnCommandExecute (loop over the list if not empty) and HandleSocialSpyCommand (and how to add/remove entries) RE: List - NiLSPACE - 11-29-2015 I'm not completely sure what you want. You want to loop over all players and extract their UUID? RE: List - Schwertspize - 11-29-2015 see my updated pr on github. i want to add the UUID to a list, if they run the /socialspy on command. I want to remove the UUID from the list, if they run /socialspy off. i want to loop over the UUIDs if anyone runs a command and send the command to each player in the list (DoWithPlayerByUUID) It doesnt have to be the UUID, but thats the only possibility i found to loop over a set of players RE: List - xoft - 11-30-2015 Use a global Lua table, and use it as a dictionary: -- Initialize the array, this should be in a file outside of any functions -- Maps UUID -> true for all players who are currently spying g_SpyingPlayers = {} -- Add a player: g_SpyingPlayers[a_Player:GetUUID()] = true -- Remove a player: g_SpyingPlayers[a_Player:GetUUID()] = nil -- Do something with all players: for _, uuid in pairs(g_SpyingPlayers) do cRoot:Get():DoWithPlayerByUUID(uuid, function (a_CBPlayer) a_CBPlayer:SendMessage("You are spying") end ) end -- for uuid - g_SpyingPlayers[] RE: List - Schwertspize - 11-30-2015 thats exactly what i did ->github |