Jump to content

Big Problem


mint3d

Recommended Posts

Posted

Ok so the level on the scoreboard is only updating when you reconnect.. can someone help me?

exports.scoreboard:addScoreboardColumn('Level') 
addEventHandler("onPlayerLogin",root, 
function () 
    local account = getPlayerAccount(source) 
 local myExp = exports.exp_system:getAccountLevel ( account ) 
    if isGuestAccount(account) then return end 
    local Level = exports.exp_system:getAccountLevel (account,"Level") 
    if Level then 
setElementData(source, "Level", tostring(Level)) 
    else 
        setElementData(source,"Level",0)     
  
end 
end) 

Posted

I don't know how to attach a timer to this kind of a function. Give it a name by then and then add a timer. (I should check it every 10 seconds or so, or atleast not every 1 second)

Posted

Try it out:

exports.scoreboard:addScoreboardColumn('Level') 
  
addEventHandler("onPlayerLogin", root, 
function () 
    local account = getPlayerAccount(source) 
    local playerLevel = 0 
    if(not isGuestAccount(account))then  
        local level = exports.exp_system:getAccountLevel(account) 
        if(level)then 
            playerLevel = level 
        end 
    end 
     
    setElementData(source, "Level", playerLevel) 
end) 
  
addEventHandler("onPlayerChangeLevel", root,  
function(old, new)  
    setElementData(source, "Level", new) 
end) 

Posted

It didn't work.. I got up a level and it stayed the same on the scoreboard..

After that I reconnected and it put my level up..

EDIT: what is this? "onPlayerChangeLevel" never heard of it in my life...

Posted

The scoreboard uses the data from element data.

If you are using Castillo's exp system, which I think you are using, then you can see this page:

https://wiki.multitheftauto.com/wiki/Re ... Exp_system

Look at the bottom and you will see the events it adds.

As for the problem, I am not sure when is each of these events triggered as there's onPlayerChangeLevel and onPlayerLevelUP. My guess is that both of them need to be hooked.

Try this one:

exports.scoreboard:addScoreboardColumn('Level') 
  
addEventHandler("onPlayerLogin", root, 
function () 
    local account = getPlayerAccount(source) 
    local playerLevel = 0 
    if(not isGuestAccount(account))then 
        local level = exports.exp_system:getAccountLevel(account) 
        if(level)then 
            playerLevel = level 
        end 
    end 
    
    setElementData(source, "Level", playerLevel) 
end) 
  
addEventHandler("onPlayerChangeLevel", root, 
function(old, new) 
    setElementData(source, "Level", new) 
end) 
  
addEventHandler("onPlayerLevelUP", root, 
function(old, new) 
    setElementData(source, "Level", new) 
end) 

Posted

attach the timer like this

exports.scoreboard:addScoreboardColumn('Level') 
addEventHandler("onPlayerLogin",root, 
function () 
    local account = getPlayerAccount(source) 
 local myExp = exports.exp_system:getAccountLevel ( account ) 
    if isGuestAccount(account) then return end 
    local Level = exports.exp_system:getAccountLevel (account,"Level") 
    if Level then 
setElementData(source, "Level", tostring(Level)) 
    else 
        setElementData(source,"Level",0)     
end 
end) 
setTimer ( function'sName, 5000, 1 ) 
  
  
 

If you dont have a function's name add one to execute the timer correctly.

Posted
function sPlayerLevel() 
    local account = getPlayerAccount(source) 
    local playerLevel = 0 
    if not (isGuestAccount(account)) then 
        local level = exports.exp_system:getAccountLevel(account) 
        if (level ~= nil) and (level ~= false) then 
            playerLevel = level 
        end 
    end 
    setElementData(source, "Level", playerLevel) 
end 
  
addEvent("onPlayerChangeLevel", true) 
addEventHandler("onPlayerChangeLevel", getRootElement(), sPlayerLevel) 
addEventHandler("onPlayerLogin", getRootElement(), sPlayerLevel) 

This should work without a timer. Otherwise, add:

setTimer(function() sPlayerLevel() end, seconds-in-milliseconds, 0) 

(Didn't test it, could be I typos something. (A))

Posted

It would be better if you used newLevel argument from onPlayerChangeLevel.

function sPlayerLevel() 
    local account = getPlayerAccount(source) 
    local playerLevel = 0 
    if not (isGuestAccount(account)) then 
        local level = exports.exp_system:getAccountLevel(account) 
        if (level ~= nil) and (level ~= false) then 
            playerLevel = level 
        end 
    end 
    setElementData(source, "Level", playerLevel) 
end 
  
function sPlayerLevel2(old, new) 
    setElementData(source, "Level", new) 
end 
addEvent("onPlayerChangeLevel", true) 
addEvent("onPlayerLevelUP", true) 
addEventHandler("onPlayerChangeLevel", getRootElement(), sPlayerLevel2) 
addEventHandler("onPlayerLevelUP", getRootElement(), sPlayerLevel2) 
addEventHandler("onPlayerLogin", getRootElement(), sPlayerLevel) 

Avoid using timers as much as possible. They are very performance-intensive.

  • 4 years later...
Posted

Im verry noobish at scripting so im trying to learn more and more because i am creating a server and i am having the exact same problem as Mint3d had and i see he found a solution thanks to Spajk

Now i don't understand where i would have to put this code he send last, in wich Recourse file does it belong?

On 14/06/2014 at 13:38, Spajk said:

It would be better if you used newLevel argument from onPlayerChangeLevel.


function sPlayerLevel() 
    local account = getPlayerAccount(source) 
    local playerLevel = 0 
    if not (isGuestAccount(account)) then 
        local level = exports.exp_system:getAccountLevel(account) 
        if (level ~= nil) and (level ~= false) then 
            playerLevel = level 
        end 
    end 
    setElementData(source, "Level", playerLevel) 
end 
  
function sPlayerLevel2(old, new) 
    setElementData(source, "Level", new) 
end 
addEvent("onPlayerChangeLevel", true) 
addEvent("onPlayerLevelUP", true) 
addEventHandler("onPlayerChangeLevel", getRootElement(), sPlayerLevel2) 
addEventHandler("onPlayerLevelUP", getRootElement(), sPlayerLevel2) 
addEventHandler("onPlayerLogin", getRootElement(), sPlayerLevel) 
 

 

Avoid using timers as much as possible. They are very performance-intensive.

 

if anyone is willing to help me out id really appericiate it :D ty

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