Jump to content

Another Q


Newbie

Recommended Posts

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

AddCommandHandler doesn't have a source.

You gotta use the player parameter.

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

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

Posted

No, there isn't, you misunderstood me. You have to switch it to 'source' in order for it to work. There is no player parameter anywhere, so you can't return the player element by that name neither.

Posted
No, there isn't, you misunderstood me. You have to switch it to 'source' in order for it to work. There is no player parameter anywhere, so you can't return the player element by that name neither.

Aaaah. Thanks .

Posted (edited)

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

Posted

I have another Q.

There's problem. I need to update(refresh) the rank stat every 5 secods.

What should i update ? "Race Loses" or "Rank"

And what should i use ?

Posted
I think you could to that with onClientRender if im right.

I will try it

Why do you have to refresh it constantly?

It updates only after relogin

Posted

OnClientRender would be a waste if you want to make it every 5 sec, and cant be used server-side.

I suggest you using a timer with infinite loop, like this:

  
LoopTimer = setTimer(function() 
--Do Stuff 
end, 5000, 0) 
  

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

I decided to make it refresh onPlayerWasted

but still.. Refresh's only when Login.

Posted

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?

Posted
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

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

Posted

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 ?

  • Moderators
Posted

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) 
  
  

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