Jump to content

Another Q


Newbie

Recommended Posts

exports.scoreboard:addScoreboardColumn('Rank') 
  
addEventHandler("onPlayerLogin", root, 
function(_, account) 
    local rankss = getAccountData(account, "Race Loses") 
    if rankss then 
        if (rankss >= 0) and (rankss <= 4) then 
            setElementData(source,"Rank","R1") 
        elseif (rankss >= 5) and (rankss <= 10) then 
            setElementData(source,"Rank","R2") 
        elseif (rankss >= 11) and (rankss <= 249) then 
            setElementData(source,"Rank","R3") 
        elseif (rankss >= 250) and (rankss <= 499) then 
            setElementData(source,"Rank","R4") 
        end 
    end 
end) 
  
function checkRank ( player ) 
    local rankss = getElementData(source, "Rank") 
    outputChatBox( "Your rank:" ..rankss,player) 
end 
addCommandHandler ( "rank", checkRank ) 

I tryed to put a command in my rank script. But it doest work.

In the scoreboard, it works and showing my rank.

Edited by Guest
Link to comment
AddCommandHandler doesn't have a source.

You gotta use the player parameter.

function checkRank ( player ) 
  
local rankss = getElementData(player, "Rank") 

Works thanks.

addEventHandler ("onPlayerChat",getRootElement(), 
function(message,type) 
    local nick = getPlayerName(source) 
    local ranks1 = getElementData(player, "Rank")    
    if (string.find(message,"!rank")) and not (string.find(message," !rank")) then 
        outputChatBox("#FFA824*" .. nick .."#FFA824 rank is #FFA824" ..ranks1, getRootElement(), 255, 255, 255, true) 
    end 
end) 

When i do in this way. It does not. Where did i failed ?

Link to comment

He meant.

  
 local ranks1 = getElementData(source, "Rank") 

But in case of getAccountData

  
addEventHandler("onPlayerLogin", root, 
function ( _, acc ) 
local ranks1 = getAccountData ( getPlayerAccount ( acc ), "Rank") 
-- your code 
end 
) 
  

You can also replace acc with source for getPlayerAccount.

EDIT: Oh seems that's not the problem. ;p

Edited by Guest
Link to comment
He meant.
  
 local ranks1 = getElementData(source, "Rank") 

But in case of getAccountData

  
addEventHandler("onPlayerLogin", root, 
function ( _, acc ) 
local ranks1 = getAccountData ( getPlayerAccount ( acc ), "Rank") 
-- your code 
  

You can also replace acc with source for getPlayerAccount.

EDIT: Oh seems that's not the problem. ;p

I already did it. But thanks.

Link to comment
Because you're not saving nor getting anything except the current data, which you want to update...

What do you want to update it to? Why do you want it to update constantly?

I just want to update result when i get when type !rank

Lets say i have 1 Lose.

And my rank should be R1

I have 6 loses and my rank should be R2.

It working, but the rank updating only when player relogins.

I need to update because players could see rank everytime it has changed. And dont need to relog

Link to comment
  • Moderators
Any suggestions ?

Why not up date the rank at the moment you are losing/winning?

Okay! Can you show an example ?

Write the same code as at your first post, only at the place were the score get set.

No example needed...

Link to comment

Totally messed up..

function update() 
    local rankss = getAccountData(account, "Race Loses") 
end 
  
addEventHandler("onPlayerWasted", getRootElement(), update) 

onPlayerWasted - Same like lose. Because player died. And Race Loses comes +1

What should i add or delete to make it working ?

Link to comment
  • Moderators

A LOT,

  
addEventHandler("onPlayerWasted", root, 
function () 
    local player = source 
  
    local account = getPlayerAccount (player) 
    if not isGuestAccount ( account) then 
        local rankss = (getAccountData(account, "Race Loses") or 0)+1 
        if rankss >= 0 then 
            if (rankss <= 4) then 
                if getElementData(player,"Rank") ~= "R1" then 
                    setElementData(player,"Rank","R1") 
                end 
            elseif (rankss <= 10) then 
                if getElementData(player,"Rank") ~= "R2" then 
                    setElementData(player,"Rank","R2") 
                end 
            elseif (rankss <= 249) then 
                if getElementData(player,"Rank") ~= "R3" then 
                    setElementData(player,"Rank","R3") 
                end 
            elseif (rankss <= 499) then 
                if getElementData(player,"Rank") ~= "R4"  then 
                    setElementData(player,"Rank","R4") 
                end 
            end 
        end 
        setAccountData(account,"Race Loses",rankss) 
    end 
end) 
  
  

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