Jump to content

How to add Level on Score board?


Leingod

Recommended Posts

Hello

Today im going to ask how to add level (exp system by Castillo) on scoreboard (i use scorefps by eXo|dragon)?

well i have done this:

on scorefps

Client

local root = getRootElement() 
local player = getLocalPlayer() 
local counter = 0 
local starttick 
local currenttick 
  
addEventHandler("onClientRender",root, 
    function() 
        if not starttick then 
            starttick = getTickCount() 
        end 
        counter = counter + 1 
        currenttick = getTickCount() 
        if currenttick - starttick >= 1000 then 
            setElementData(player,"Fps",counter) 
            counter = 0 
            starttick = false 
        end 
    end 
) 
  
addEventHandler ( "onClientResourceStart", getRootElement(), 
    function (resource) 
        if resource == getThisResource() then 
            local playerLevel = exports.exp_system:getPlayerLevel ( thePlayer ) 
            setElementData(thePlayer, "Level", playerLevel) 
        end 
    end 
) 

server

addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), 
    function() 
        call(getResourceFromName("scoreboard"),"addScoreboardColumn","Fps") 
        call(getResourceFromName("scoreboard"),"addScoreboardColumn","Level") 
    end 
) 

The score board shows the table "Level" but don't show the player level

What should i do? thx before

Sorry im to much asking (Noob)

Link to comment
  • MTA Team

You didn't specify the "thePlayer" in onResourceStart. I fixed it by doing it to all players. Also, you had a few unnecessary functions there so I made it more simple for you.

Should work I guess.

Client-side

local counter = 0 
local starttick 
local currenttick 
  
addEventHandler("onClientRender", root, 
    function() 
        if not starttick then 
            starttick = getTickCount() 
        end 
        counter = counter + 1 
        currenttick = getTickCount() 
        if currenttick - starttick >= 1000 then 
            setElementData(localPlayer, "Fps", counter) 
            counter = 0 
            starttick = false 
        end 
    end 
) 
  
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        for i,v in ipairs(getElementsByType("player")) do 
            setElementData(v, "Level", exports.exp_system:getPlayerLevel(v)) 
        end 
    end 
) 

Server-side

addEventHandler("onResourceStart", resourceRoot, 
    function() 
        call(getResourceFromName("scoreboard"),"addScoreboardColumn","Fps") 
        call(getResourceFromName("scoreboard"),"addScoreboardColumn","Level") 
    end 
) 

Link to comment
  • Other Languages Moderators

Setting the element data for all players everytime a client side resource started not a good idea.

Also getPlayerLevel is server side only, that why not working.

local counter = 0 
local starttick 
local currenttick 
  
addEventHandler("onClientRender", root, 
    function() 
        if not starttick then 
            starttick = getTickCount() 
        end 
        counter = counter + 1 
        currenttick = getTickCount() 
        if currenttick - starttick >= 1000 then 
            setElementData(localPlayer, "Fps", counter) 
            counter = 0 
            starttick = false 
        end 
    end 
) 

addEventHandler("onResourceStart", resourceRoot, 
function() 
     call(getResourceFromName("scoreboard"),"addScoreboardColumn","Fps") 
     call(getResourceFromName("scoreboard"),"addScoreboardColumn","Level") 
     for i,v in ipairs(getElementsByType("player")) do 
          setElementData(v, "Level", exports.exp_system:getPlayerLevel(v)) 
     end 
end) 

Link to comment

ServerSide :

  
exports.scoreboard:addScoreboardColumn('Level') 
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), 
    function() 
        call(getResourceFromName("scoreboard"),"addScoreboardColumn","fps") 
    end 
) 
function setScoreLevel (thePlayer) 
 local Level = exports.exp_system:getPlayerLevel ( thePlayer ) 
    if Level == false then 
        setElementData ( source, "Level", "0" ) 
    else 
        setElementData ( source, "Level", Level) 
    end 
end 
addEventHandler ( "onPlayerSpawn", getRootElement(),setScoreLevel) 
  

Link to comment
  • Other Languages Moderators
Not work either :S

Have you checked debugscript 3?

ServerSide :
  
exports.scoreboard:addScoreboardColumn('Level') 
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), 
    function() 
        call(getResourceFromName("scoreboard"),"addScoreboardColumn","fps") 
    end 
) 
function setScoreLevel (thePlayer) 
 local Level = exports.exp_system:getPlayerLevel ( thePlayer ) 
    if Level == false then 
        setElementData ( source, "Level", "0" ) 
    else 
        setElementData ( source, "Level", Level) 
    end 
end 
addEventHandler ( "onPlayerSpawn", getRootElement(),setScoreLevel) 
  

onPlayerSpawn doesn't have a player parameter, the first parameter is float position. should be source.

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