Castillo Posted July 7, 2010 Posted July 7, 2010 hey im wondering how to make a players list like a gridlist but with DX functions, if someone could tell me.
DiSaMe Posted July 7, 2010 Posted July 7, 2010 function showPlayersList() local all_players = getElementsByType("player") for num,this_player in ipairs(all_players) do local plname = getPlayerName(this_player) dxDrawText(plname,100,100+num*16) --num increases with each cycle, so every name is drawn under previous name end end addEventHandler("onClientRender",getRootElement(),showPlayersList) Maybe this will help you to start.
Lordy Posted July 7, 2010 Posted July 7, 2010 Or you could cache the player list in a table on resource start and every time someone joins/leaves, you modify the table, so you wouldn't have to getElementsByType("player") every frame. local players = {} -- make it local to the file, not necessary, but I like function cachePlayers() for k, v in ipairs(getElementsByType("player")) do players[k] = v end end function addPlayer() table.insert(players,source) end function removePlayer() for k,v in ipairs(players) do if v == source then table.remove(players,k) return end end end function drawList() for num,this_player in ipairs(players) do local plname = getPlayerName(this_player) dxDrawText(plname,100,100+num*16) --num increases with each cycle, so every name is drawn under previous name end end addEventHandler("onClientRender",root,drawList) addEventHandler("onClientResourceStart",resourceRoot,cachePlayers) addEventHandler("onClientPlayerJoin",root,addPlayer) -- add a player into the table when someone joins addEventHandler("onClientPlayerQuit",root,removePlayer) -- remove a player from table if he quits It's slightly more complicated but should be faster. Not much, but if you have lot's of stuff going on onClientRender, things should be optimized.
Castillo Posted July 7, 2010 Author Posted July 7, 2010 Thanks guys it worked! Edit: why this dosnt work function drawList() for num,this_player in ipairs(players) do r, g, b = getPlayerNametagColor( this_player ) local plname = getPlayerName(this_player) dxDrawText(plname,300,150+num*16,tocolor( r or 255, g or 255, b or 255, 255 )) end end i try to set any color and nothing works.
MaddDogg Posted July 8, 2010 Posted July 8, 2010 You omitted the right and bottom arguments of dxDrawText. Errors should have told you that. You could have easily fixed that by yourself. https://wiki.multitheftauto.com/wiki/DxDrawText
Castillo Posted July 8, 2010 Author Posted July 8, 2010 You omitted the right and bottom arguments of dxDrawText.Errors should have told you that. You could have easily fixed that by yourself. https://wiki.multitheftauto.com/wiki/DxDrawText If i put like this function drawList() for num,this_player in ipairs(players) do local plname = getPlayerName(this_player) local r, g, b = getPlayerNametagColor( this_player ) dxDrawText(plname,300,150+num*16,tocolor( r or 255, g or 255, b or 255, 255 ),1.0,"default","left","top",false,false,false) end end text dosnt even appear
50p Posted July 8, 2010 Posted July 8, 2010 If it doesn't appear, you must be getting a warning/error message. Try to make a new variable which will be the colour (value returned from tocolor) and check what it is (debug the script...).
Castillo Posted July 8, 2010 Author Posted July 8, 2010 If it doesn't appear, you must be getting a warning/error message. Try to make a new variable which will be the colour (value returned from tocolor) and check what it is (debug the script...). I got everytime i script the debugscript on and no errors comes.
Callum Posted July 8, 2010 Posted July 8, 2010 You have added an event handler, haven't you (use onClientRender)? If not, add this to the bottom; addEventHandler("onClientRender",getRootElement(),drawList)
Castillo Posted July 8, 2010 Author Posted July 8, 2010 You have added an event handler, haven't you (use onClientRender)? If not, add this to the bottom; addEventHandler("onClientRender",getRootElement(),drawList) I have already this.
MaddDogg Posted July 8, 2010 Posted July 8, 2010 If you had just paid attention to what I told you, it would have been fixed. You're missing 2 arguments in dxDrawText. It's unbelievably easy to fix, I won't fix it for you.
Castillo Posted July 8, 2010 Author Posted July 8, 2010 If you had just paid attention to what I told you, it would have been fixed.You're missing 2 arguments in dxDrawText. It's unbelievably easy to fix, I won't fix it for you. ahhhhhhhh i found it, thanks!
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