Karuzo Posted January 4, 2014 Share Posted January 4, 2014 hey guys, i have a scoreboard and i want to draw the Money of the Player , But if i do my code : local players = getElementsByType ( "player" ) local playas = 0 for amt, player in pairs(players) do playas = playas + 1 if (playas <= 20) then local ping = getPlayerPing(player) if (ping >= 250) then r,g,b = 200,20,25 elseif (ping >= 120) then r,g,b = 255,149,4 else r,g,b = 50,200,50 end dxDrawText(getPlayerName ( player ), x/15,y/4*amt/5-700+pls, x/1.9,y/1.9-700+pls, tocolor(255,255,255), 1.2 , "sans","center", "center",false, false,true,true) dxDrawText(getPlayerMoney ( player ).." $", x/3.5,y/4*amt/5-700+pls, x/1.9,y/1.9-700+pls, tocolor(255,255,255), 1.2, "sans","center", "center",false, false, true, true) dxDrawText(ping, x/1.1,y/4*amt/5-700+pls, x/1.9,y/1.9-700+pls, tocolor(r,g,b), 1.2 , "sans","center", "center",false, false,true,true) end end end It just shows the Money from the first player to all ._. Link to comment
Karuzo Posted January 4, 2014 Author Share Posted January 4, 2014 No one can help me ? Link to comment
zixxonx Posted January 4, 2014 Share Posted January 4, 2014 ./debugscript 3 then show us errors (or in server.log) Link to comment
.:HyPeX:. Posted January 4, 2014 Share Posted January 4, 2014 You need to call this function every time with onClientRender, please read the wiki. https://wiki.multitheftauto.com/wiki/DxDrawText Draws a string of text on the screen for one frame. In order for the text to stay visible continuously, you need to call this function with the same parameters on each frame update (see onClientRender). addEventHandler("onClientRender", getRootElement(), YourFunctionName) Link to comment
Karuzo Posted January 4, 2014 Author Share Posted January 4, 2014 Same problem ... Full Code : local x,y = guiGetScreenSize () local nodeFont = dxCreateFont("Harabara.ttf" ) getPlayersOnline = function () local playersOnline = getElementsByType ( "player" ) local playersO = 0 for count, playerOn in pairs(playersOnline) do playersO = playersO + 1 end return playersO end drawPlayerList = function (pls) dxDrawRectangle ( x/4.05,y/4.1-700+pls, x/1.88,y/1.86, tocolor(1,1,1,200), true ) dxDrawRectangle ( x/4,y/4-700+pls, x/1.9,y/1.9, tocolor(50,50,50,150), true ) dxDrawLine ( x/2.9,y/4.001-700+pls, x/2.9,y/1.288-700+pls, tocolor(1,1,1,200),2,true ) dxDrawLine ( x/2.1,y/4.001-700+pls, x/2.1,y/1.288-700+pls, tocolor(1,1,1,200),2,true ) dxDrawText("Name :", x/15,y/30/20-700+pls, x/1.9,y/1.9-700+pls, tocolor(255,69,0), 1.2 , nodeFont,"center", "center",false, false,true,true) dxDrawText("Ping : ", x/1.1,y/30/20-700+pls, x/1.9,y/1.9-700+pls, tocolor(255,69,0), 1.2 , "pricedown","center", "center",false, false,true) dxDrawText( getPlayersOnline().." Player/s Online", x/1.3,y/30/20-700+pls, x/1.9,y/0.66-700+pls, tocolor(255,69,0), 1.2 , "sans","center", "center",false, false,true) dxDrawText("Money :", x/3.5, y/30/20-700+pls, x/1.9,y/1.9-700+pls, tocolor(255,69,0), 1.2, nodeFont, "center","center",false,false,true) dxDrawText("Location :", x/7,y/30/20-700+pls, x/1.9,y/1.9-700+pls, tocolor(255,69,0), 1.2, nodeFont, "center","center",false,false,true) local players = getElementsByType ( "player" ) local playas = 0 for amt, player in pairs(players) do playas = playas + 1 if (playas <= 20) then local ping = getPlayerPing(player) if (ping >= 250) then r,g,b = 200,20,25 elseif (ping >= 120) then r,g,b = 255,149,4 else r,g,b = 50,200,50 end dxDrawText(getPlayerName ( player ), x/15,y/4*amt/5-700+pls, x/1.9,y/1.9-700+pls, tocolor(255,255,255), 1.2 , "sans","center", "center",false, false,true,true) dxDrawText(getPlayerMoney ( player ).." $", x/3.5,y/4*amt/5-700+pls, x/1.9,y/1.9-700+pls, tocolor(255,255,255), 1.2, "sans","center", "center",false, false, true, true) dxDrawText(ping, x/1.1,y/4*amt/5-700+pls, x/1.9,y/1.9-700+pls, tocolor(r,g,b), 1.2 , "sans","center", "center",false, false,true,true) end end end local cnt = 0 addEventHandler("onClientRender",getRootElement(), function () if ( getKeyState( "tab" ) == true) then cnt = cnt + 10 drawPlayerList(cnt) if (cnt >= 690) then cnt = 690 end elseif ( getKeyState( "tab" ) == false) then cnt = cnt - 10 drawPlayerList(cnt) if (cnt <= 10) then cnt = 5 end end end) Link to comment
DiSaMe Posted January 4, 2014 Share Posted January 4, 2014 https://wiki.multitheftauto.com/wiki/GetPlayerMoney Client-side: ReturnsReturns an integer with the amount of money the local player has. That's it, you're just getting the local player's money, since that's the only thing client-side getPlayerMoney can return because client is unaware of whatever happens on other clients. Link to comment
Karuzo Posted January 4, 2014 Author Share Posted January 4, 2014 So what do i have to change ? Link to comment
.:HyPeX:. Posted January 4, 2014 Share Posted January 4, 2014 NOOOOOOOOOOO - Do you read?!!!! THE dxDrawText function needs to be inside the onClientRender!! addEventHandler("onClientRender", getRootElement(), function) removeEventHandler("onClientRender", getRootElement(), function) and by the way: dxDrawText( getPlayersOnline().." Player/s Online", x/1.3,y/30/20-700+pls, x/1.9,y/0.66-700+pls, tocolor(255,69,0), 1.2 , "sans","center", "center",false, false,true) getPlayerCount() or in your case: local number = #players Link to comment
DiSaMe Posted January 5, 2014 Share Posted January 5, 2014 .:HyPeX:., don't write if you don't know. KRZO, if you need to sync data (such as money), you need to use the element data or custom events: setElementData getElementData addEvent addEventHandler triggerClientEvent In case of element data, whatever you set (using setElementData) on server or any of the clients, becomes visible for everyone (unless you choose not to sync it using the 4th argument of setElementData), so that the data can be retrieved using getElementData. As for events, you can create an event on the client using addEvent, then add the handler using addEventHandler, and when you call triggerClientEvent on the server using the same event name, the handler function will be called on the client with the same parameters which were specified in triggerClientEvent. 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