Jump to content

Levels to image


Recommended Posts

Hello all, i'm trying to transform rank numbers to image, here is the lua

local levels = {[200] = 1, [500] = 2, [600] = 3, [1000] = 4, [2000] = 5, [3000] = 6, [4000] = 7, [5000] = 8, [9000] = 9} 
  
function win(ammo, killer, weapon, bodypart) 
    if (killer and killer ~= source) then 
        local H = getElementData(killer, "Reputation") 
        local S = getElementData(killer, "Rank") 
        local killer1 = getPlayerName(killer) 
        local noob = getPlayerName(source) 
        setElementData(killer, "Reputation", tonumber(H)+math.random ( 20, 50 ) ) 
        if levels[tonumber(H)] then 
            setElementData(killer, "Rank", "Rank ".. tostring(levels[tonumber(H)]) .." ! ") 
            triggerClientEvent ( killer, "playSound", killer ) 
        end 
    end 
    local H = getElementData ( source, "Reputation" ) or 0 
    setElementData ( source, "Reputation", tonumber ( H ) - math.random ( 20, 50 ) ) 
end 
addEventHandler( "onPlayerWasted", getRootElement(), win) 
  
function onLogin (_,account) 
    setElementData(source, "Rank", getAccountData(account, "Rnk") or "0") 
    setElementData(source, "Reputation", getAccountData(account, "Rep") or "0") 
end 
addEventHandler ("onPlayerLogin", root, onLogin) 
  
function saveData(thePlayer, theAccount) 
    if (theAccount and not isGuestAccount(theAccount)) then 
        setAccountData (theAccount, "Rnk", getElementData(thePlayer, "Rank")) 
        setAccountData (theAccount, "Rep", getElementData(thePlayer, "Reputation")) 
    end 
end 
  
addEventHandler ("onPlayerQuit", root, function () saveData(source, getPlayerAccount(source)) end) 
addEventHandler ("onPlayerLogout", root, function (prev) saveData(source, prev) end) 

Also i want add them to scoreboard

elseif column.name == "Rank" then 
                            column.width = 20 
                            dxDrawImage( topX+theX, y+s(1), 16, 11, content, 0, 0, 0, cWhite, drawOverGUI ) 

Ranks images are

Rank/Lvl1.png

.........

Rank/Lvl9.png

I hope somebody help me in this, and thanks

Link to comment

try this:

local levels = { 
    [200] = "1", 
    [500] = "2", 
    [600] = "3", 
    [1000] = "4", 
    [2000] = "5", 
    [3000] = "6", 
    [4000] = "7", 
    [5000] = "8", 
    [9000] = "9" 
} 
  
addEventHandler( "onPlayerWasted",root, function(_, killer) 
    if (killer and killer ~= source) then 
        local Rep = tonumber(getElementData(killer, "Reputation")) or 0 
        local Rank = getElementData(killer, "Rank") 
        local kName = getPlayerName(killer) 
        local sName = getPlayerName(source) 
        setElementData(killer, "Reputation", Rep + math.random ( 20, 50 ) ) 
        if levels[Rep] then 
            setElementData(killer, "Rank", "Rank ".. levels[Rep] .." ! ") 
            triggerClientEvent ( killer, "playSound", killer ) 
        end 
    end 
    local Rep = tonumber(getElementData ( source, "Reputation" )) or 0 
    setElementData ( source, "Reputation", Rep  - math.random ( 20, 50 ) ) 
end) 
  
addEventHandler ("onPlayerLogin", root, function (_,curAcc) 
    setElementData(source, "Rank", getAccountData(curAcc, "Rank") or "0") 
    setElementData(source, "Reputation", getAccountData(curAcc, "Rep") or 0) 
end) 
  
function saveData(source, acc) 
    if not acc or isGuestAccount(acc)then return end 
    setAccountData (acc, "Rnk", getElementData(source, "Rank")) 
    setAccountData (acc, "Rep", getElementData(source, "Reputation")) 
end 
  
addEventHandler ("onPlayerQuit", root, function () saveData(source, getPlayerAccount(source)) end) 
addEventHandler ("onPlayerLogout", root, function (acc) saveData(source, acc) end) 

Link to comment
local levels = { 
    [200] = "1", 
    [500] = "2", 
    [600] = "3", 
    [1000] = "4", 
    [2000] = "5", 
    [3000] = "6", 
    [4000] = "7", 
    [5000] = "8", 
    [9000] = "9" 
} 
  
addEventHandler( "onPlayerWasted",root, function(_, killer) 
    if (killer and killer ~= source) then 
        local Rep = tonumber(getElementData(killer, "Reputation")) or 0 
        local kName = getPlayerName(killer) 
        local sName = getPlayerName(source) 
        setElementData(killer, "Reputation", Rep + math.random ( 20, 50 ) ) 
        if levels[Rep] then 
            setElementData(killer, "Rank", "Rank/Lvl".. levels[Rep] ..".png") --Rank/Lvl1.png 
            triggerClientEvent ( killer, "playSound", killer ) 
        end 
    end 
    local Rep = tonumber(getElementData ( source, "Reputation" )) or 0 
    setElementData ( source, "Reputation", Rep  - math.random ( 20, 50 ) ) 
end) 
  
addEventHandler ("onPlayerLogin", root, function (_,curAcc) 
    setElementData(source, "Rank", getAccountData(curAcc, "Rank") or "0") 
    setElementData(source, "Reputation", getAccountData(curAcc, "Rep") or 0) 
end) 
  
function saveData(source, acc) 
    if not acc or isGuestAccount(acc)then return end 
    setAccountData (acc, "Rnk", getElementData(source, "Rank")) 
    setAccountData (acc, "Rep", getElementData(source, "Reputation")) 
end 
  
addEventHandler ("onPlayerQuit", root, function () saveData(source, getPlayerAccount(source)) end) 
addEventHandler ("onPlayerLogout", root, function (acc) saveData(source, acc) end) 

Link to comment
  • 3 weeks later...

try this:

local levels = { 
    [200] = "1", 
    [500] = "2", 
    [600] = "3", 
    [1000] = "4", 
    [2000] = "5", 
    [3000] = "6", 
    [4000] = "7", 
    [5000] = "8", 
    [9000] = "9" 
} 
  
addEventHandler( "onPlayerWasted",root, function(_, killer) 
    if (killer and killer ~= source) then 
        local Rep = tonumber(getElementData(killer, "Reputation")) or 0 
        local kName = getPlayerName(killer) 
        local sName = getPlayerName(source) 
        setElementData(killer, "Reputation", Rep + math.random ( 20, 50 ) ) 
        if levels[Rep] then 
            setElementData(killer, "Rank", ":Reputation/Reputation/Rank/Lvl".. levels[Rep] ..".png") -- :Reputation/Reputation/Rank/Lvl1.png 
            triggerClientEvent ( killer, "playSound", killer ) 
        end 
    end 
    local Rep = tonumber(getElementData ( source, "Reputation" )) or 0 
    setElementData ( source, "Reputation", Rep  - math.random ( 20, 50 ) ) 
end) 
  
addEventHandler ("onPlayerLogin", root, function (_,curAcc) 
    setElementData(source, "Rank", getAccountData(curAcc, "Rank") or "0") 
    setElementData(source, "Reputation", getAccountData(curAcc, "Rep") or 0) 
end) 
  
function saveData(source, acc) 
    if not acc or isGuestAccount(acc)then return end 
    setAccountData (acc, "Rnk", getElementData(source, "Rank")) 
    setAccountData (acc, "Rep", getElementData(source, "Reputation")) 
end 
  
addEventHandler ("onPlayerQuit", root, function () saveData(source, getPlayerAccount(source)) end) 
addEventHandler ("onPlayerLogout", root, function (acc) saveData(source, acc) end) 

And please tell me if there's an error or why it's not working!

Link to comment

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