ViRuZGamiing Posted December 12, 2013 Posted December 12, 2013 Hi Community, titles explaines it... but how? "If debugging is the process of removing software bugs, then programming must be the process of putting them in."
csiguusz Posted December 12, 2013 Posted December 12, 2013 local onlinePlayers = {} for i, v in ipairs ( getElementsByType ( "player" ) ) do table.insert ( onlinePlayers, v ) end Owner of [HUN]Magyar Play Szerver 1.4, IP: 31.220.43.153:22003
ViRuZGamiing Posted December 12, 2013 Author Posted December 12, 2013 Can I show all players onCommand? addEventHandler("online", function () --show online players part end ) "If debugging is the process of removing software bugs, then programming must be the process of putting them in."
csiguusz Posted December 12, 2013 Posted December 12, 2013 Yes, you can. Here is a simple example: addCommandHandler ( "online", function () for i, v in ipairs ( getElementsByType ( "player" ) ) do outputChatBox ( getPlayerName ( v ) ) end end ) Owner of [HUN]Magyar Play Szerver 1.4, IP: 31.220.43.153:22003
ViRuZGamiing Posted December 12, 2013 Author Posted December 12, 2013 Can I set a "," between everyname like this; Name1, Name2, ... "If debugging is the process of removing software bugs, then programming must be the process of putting them in."
csiguusz Posted December 12, 2013 Posted December 12, 2013 So you want more names in a line? local charLimit = 50 -- maximum charachters in a line addCommandHandler ( "online", function () local line = {} local currLength = 0 for i, v in ipairs ( getElementsByType ( "player" ) ) do local name = getPlayerName ( v ) if currLength + #name > charLimit then outputChatBox ( table.concat ( line, ", " ) ) line = {} currLength = 0 end table.insert ( line, name ) currLength = currLength + #name end end ) Owner of [HUN]Magyar Play Szerver 1.4, IP: 31.220.43.153:22003
Gallardo9944 Posted December 12, 2013 Posted December 12, 2013 (edited) function getOnlinePlayers() return getElementsByType("player") end function listOnlinePlayers(player) local players = getOnlinePlayers() local playerNames = { } for i=1,#players do table.insert(playerNames,getPlayerName(players[i])) end local text = table.concat(playerNames,", ") -- Separate each player with comma outputChatBox(text,getRootElement()) end Edited December 12, 2013 by Guest Code Debugger - Minimalistic MTA debug line replacement
ViRuZGamiing Posted December 12, 2013 Author Posted December 12, 2013 I've tested addCommandHandler ( "online", function () for i, v in ipairs ( getElementsByType ( "player" ) ) do outputChatBox ( getPlayerName ( v ) ) end end ) but i'm currently alone on a LAN Server what if i'm with 2 or more how would it be displayed? 1 Name a line? All behind eachother with just a space in between? greetz viruz "If debugging is the process of removing software bugs, then programming must be the process of putting them in."
Gallardo9944 Posted December 12, 2013 Posted December 12, 2013 but i'm currently alone on a LAN Server what if i'm with 2 or more how would it be displayed? 1 Name a line? All behind eachother with just a space in between? This code prints the stuff each new line. Code Debugger - Minimalistic MTA debug line replacement
ViRuZGamiing Posted December 12, 2013 Author Posted December 12, 2013 Then it's good enough; Thx all! "If debugging is the process of removing software bugs, then programming must be the process of putting them in."
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