Karuzo Posted February 12, 2014 Share Posted February 12, 2014 Hey all, i have a small problem with my scoreboard. i want to get the player's money. but that doesn't really work, cause i cannot get the Players Money client-side,because the player would only see his money in each line. So i asked a friend and he said me that i need to use element datas. But i just don't get it how that should work.. Here's my client-side Script: local players = getElementsByType ( "player" ) local playas = 0 local playerheight = 20 for amt, player in pairs(players) do playas = playas + 1 if (playas <= 20) then local ping = getPlayerPing(player) local teamp = getPlayerTeam(player) local teamn = getTeamName(teamp) local money = --I don't know how i should make that. if (ping >= 250) then r,g,b = 255,0,0 elseif (ping >= 120) then r,g,b = 255,69,0 else r,g,b = 0,255,0 end dxDrawText(getPlayerName ( player ), X+60,Y+60+playerheight*(amt-1), Width,Height, tocolor(255,255,255), 1 , "default-bold","left", "top",false, false,true,true) dxDrawText(ping,X+480,Y+60+playerheight*(amt-1), Width, Height, tocolor(r,g,b), 1, "default","left", "top",false,false,true,true) dxDrawText(money.." $", X+210,Y+60+playerheight*(amt-1),Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) dxDrawText(teamn, X+350,Y+60+playerheight*(amt-1),Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) end end end Link to comment
Castillo Posted February 12, 2014 Share Posted February 12, 2014 local currentMoney = 0 addEventHandler ( "onClientRender", root, function ( ) local money = getPlayerMoney ( ) if ( currentMoney ~= money ) then outputChatBox ( money ) setElementData ( localPlayer, "playerMoney", money ) currentMoney = money end end ) I'm not sure how efficient this is, it'll set the element data "playerMoney" everytime the player's money changes. Then you can use getElementData to get the player money. Link to comment
Karuzo Posted February 12, 2014 Author Share Posted February 12, 2014 Would that work ? I mean , getPlayerMoney client-sided would show the local players money just several times. e.g.: if i have 400$ my friend would also have 400$ but he has 0$. I think your script is client-side otherwise onClientRender wouldn't work. Link to comment
Castillo Posted February 12, 2014 Share Posted February 12, 2014 Yes, it should work just fine, go ahead a try it. Link to comment
Karuzo Posted February 12, 2014 Author Share Posted February 12, 2014 Can't try it at the moment, no ones online We have 12 o'clock here. And if i want to save it just get a AccountData and set the Element there? Link to comment
Karuzo Posted February 12, 2014 Author Share Posted February 12, 2014 I mean if i want to save the current money the player has in his hands, just do it like this ? function playerLogin (thePreviousAccount, theCurrentAccount, autoLogin) if not (isGuestAccount (getPlayerAccount(source))) then local accountData = getAccountData (theCurrentAccount, "money") if (accountData) then local playerMoney = getAccountData(theCurrentAccount, "money") setElementData(source,"money",getPlayerMoney(source)) end end end addEventHandler("onPlayerLogin", getRootElement(), playerLogin) Link to comment
Castillo Posted February 12, 2014 Share Posted February 12, 2014 No need to do that? the script I gave you earlier will update the element data when the money changes. Link to comment
Karuzo Posted February 12, 2014 Author Share Posted February 12, 2014 Thank you Solidsnake14, it just works perfectly. Link to comment
Karuzo Posted February 13, 2014 Author Share Posted February 13, 2014 Ok i have another problem, if i'm joining my server i don't see the other players , but if i have more than 0$ i can see them, why ? Here's my code : local currentMoney = 0 addEventHandler ( "onClientRender", root, function ( ) local money = getPlayerMoney ( ) if ( currentMoney ~= money ) then outputChatBox ( money ) setElementData ( localPlayer, "playerMoney", money ) currentMoney = money end end ) local players = getElementsByType ( "player" ) local playas = 0 local playerheight = 20 for amt, player in pairs(players) do playas = playas + 1 if (playas <= 20) then local ping = getPlayerPing(player) local teamp = getPlayerTeam(player) local teamn = getTeamName(teamp) local money = getElementData(player, "playerMoney") if (ping >= 250) then r,g,b = 255,0,0 elseif (ping >= 120) then r,g,b = 255,69,0 else r,g,b = 0,255,0 end dxDrawText(money.." $", X+210,Y+60+playerheight*(amt-1),Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) end end end Link to comment
Castillo Posted February 13, 2014 Share Posted February 13, 2014 You need onClientRender to draw it, where is it? Link to comment
Karuzo Posted February 13, 2014 Author Share Posted February 13, 2014 function open() opened = not opened if opened == true then addEventHandler("onClientRender", gRoot, Scoreboard) showChat(false) showPlayerHudComponent("all", false) else removeEventHandler("onClientRender", gRoot, Scoreboard) showPlayerHudComponent("all", true) showChat(true) end end bindKey("tab","both",open) Link to comment
Castillo Posted February 13, 2014 Share Posted February 13, 2014 You haven't posted the full script. Link to comment
Karuzo Posted February 13, 2014 Author Share Posted February 13, 2014 local gRoot = getRootElement() local sWidth,sHeight = guiGetScreenSize() local Width,Height = 549,412 local X = (sWidth/2) - (Width/2) local Y = (sHeight/2) - (Height/2) getPlayersOnline = function () local playersOnline = getElementsByType ( "player" ) local playersO = 0 for count, playerOn in pairs(playersOnline) do playersO = playersO + 1 end return playersO end local currentMoney = 0 addEventHandler ( "onClientRender", root, function ( ) local money = getPlayerMoney ( ) if ( currentMoney ~= money ) then outputChatBox ( money ) setElementData ( localPlayer, "playerMoney", money ) currentMoney = money end end ) function Scoreboard() dxDrawImage(X,Y,Width,Height, "images/back.png") dxDrawText("Name", X+60, Y+10, Width,Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText(getPlayersOnline().."/50" ,X+525, Y-15, Width,Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false) dxDrawText("Ping", X+480, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText("Geld", X+210, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText("Team", X+350, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) local players = getElementsByType ( "player" ) local playas = 0 local playerheight = 20 for amt, player in pairs(players) do playas = playas + 1 if (playas <= 20) then local ping = getPlayerPing(player) local teamp = getPlayerTeam(player) local teamn = getTeamName(teamp) local money = getElementData(player, "playerMoney") if (ping >= 250) then r,g,b = 255,0,0 elseif (ping >= 120) then r,g,b = 255,69,0 else r,g,b = 0,255,0 end dxDrawText(getPlayerName ( player ), X+60,Y+60+playerheight*(amt-1), Width,Height, tocolor(255,255,255), 1 , "default-bold","left", "top",false, false,true,true) dxDrawText(ping,X+480,Y+60+playerheight*(amt-1), Width, Height, tocolor(r,g,b), 1, "default","left", "top",false,false,true,true) dxDrawText(money.." $", X+210,Y+60+playerheight*(amt-1),Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) dxDrawText(teamn, X+350,Y+60+playerheight*(amt-1),Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) end end end function Zeit() local hours = getRealTime().hour local minutes = getRealTime().minute local seconds = getRealTime().second dxDrawText(hours..":"..minutes..":"..seconds, X-325, Y+525, Width, Height, tocolor(255,255,255), 1, "default-bold","left", "top",false, false,true,true) end addEventHandler("onClientRender", gRoot, Zeit) function open() opened = not opened if opened == true then addEventHandler("onClientRender", gRoot, Scoreboard) showChat(false) showPlayerHudComponent("all", false) removeEventHandler("onClientRender", gRoot, Zeit) else removeEventHandler("onClientRender", gRoot, Scoreboard) showPlayerHudComponent("all", true) showChat(true) addEventHandler("onClientRender", gRoot, Zeit) end end bindKey("tab","both",open) Link to comment
Castillo Posted February 13, 2014 Share Posted February 13, 2014 getPlayersOnline = function () local playersOnline = getElementsByType ( "player" ) local playersO = 0 for count, playerOn in pairs(playersOnline) do playersO = playersO + 1 end return playersO end That function is completely useless, you can simply use: playersO = #getElementsByType ( "player" ) About the other problem, try this: function Scoreboard() dxDrawImage(X,Y,Width,Height, "images/back.png") dxDrawText("Name", X+60, Y+10, Width,Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText(getPlayersOnline().."/50" ,X+525, Y-15, Width,Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false) dxDrawText("Ping", X+480, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText("Geld", X+210, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) dxDrawText("Team", X+350, Y+10, Width, Height, tocolor(255, 255, 255, 255), 1.00, "default-bold", "left", "top", false, false, true, false, false) local players = getElementsByType ( "player" ) local playas = 0 local playerheight = 20 for amt, player in pairs(players) do playas = playas + 1 if (playas <= 20) then local ping = getPlayerPing(player) local teamp = getPlayerTeam(player) local teamn = getTeamName(teamp) local money = tonumber ( getElementData(player, "playerMoney") ) or 0 if (ping >= 250) then r,g,b = 255,0,0 elseif (ping >= 120) then r,g,b = 255,69,0 else r,g,b = 0,255,0 end dxDrawText(getPlayerName ( player ), X+60,Y+60+playerheight*(amt-1), Width,Height, tocolor(255,255,255), 1 , "default-bold","left", "top",false, false,true,true) dxDrawText(ping,X+480,Y+60+playerheight*(amt-1), Width, Height, tocolor(r,g,b), 1, "default","left", "top",false,false,true,true) dxDrawText( tostring ( money ) .." $", X+210,Y+60+playerheight*(amt-1),Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) dxDrawText(teamn, X+350,Y+60+playerheight*(amt-1),Width, Height, tocolor(255,255,255), 1, "default","left", "top",false, false, true, true) end end end Link to comment
Karuzo Posted February 13, 2014 Author Share Posted February 13, 2014 playersO = #getElementsByType ( "player" ) Oh didn't knew that To the problem : Thank you it works! 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