Jump to content

Scoreboard getPlayerMoney


Karuzo

Recommended Posts

Posted

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 

Posted
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.

Posted

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.

Posted

Can't try it at the moment, no ones online :-D We have 12 o'clock here.

And if i want to save it just get a AccountData and set the Element there?

Posted

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) 

Posted

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 
  

Posted
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) 
  

Posted
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) 

Posted
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 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...