Jump to content

[SOLVED]Help with levelsystem !


Miika

Recommended Posts

Levelsystem doesn't work :?

ERROR: levelsystem/level_s.lua:20: attempt to concatenate global 'currentLevel' (a nill value) 

ERROR: levelsystem/level_c.lua:16: attempt to concatenate global 'level' (a nill value) 

[Client]

function playerJoin() 
    setTimer ( checkLevel, 1000, 1) 
end 
addEventHandler("onClientResourceStart", getRootElement(), playerJoin) 
  
function addLevels(level) 
    levelElement = guiCreateLabel ( 0.45, 0.02, 0.40, 0.40, "", true ) 
    guiSetFont ( level, "sa-gothic" ) 
    guiLabelSetColor ( level, math.random(0, 255), math.random(0, 255), math.random(0, 255) ) 
end 
addEvent( "getLevel", true ) 
addEventHandler( "getLevel", localPlayer, addLevels ) 
  
function checkLevel() 
    setTimer ( checkLevel2, 1000, 1) 
    guiSetText ( levelElement, "Level: ".. level ) 
end 
function checkLevel2() 
    setTimer ( checkLevel, 1000, 1) 
end 
  

[server]

defaultlevel = 1 
function LevelOnWasted ( ammo, killer, killerweapon, bodypart ) 
  local account = getPlayerAccount(client) 
  if (account) and not isGuestAccount (account) then 
    if ( killer ) and ( killer ~= source ) then 
        currentlevel = getElementData( client, "levelsystem.currentlevel" ) 
    if (currentlevel) == nil then 
        setElementData ( client, "levelsystem.currentlevel", defaultlevel ) 
        setTimer(1000, 1, clientData) 
    else 
        addLevel = currentlevel + 1 
        setElementData ( client, "levelsystem.currentlevel", addLevel ) 
        setTimer(1000, 1, clientData) 
    end 
end 
end 
end 
  
function clientData() 
    triggerClientEvent ( playerSource, "getLevel", playerSource, "" .. currentlevel ) 
end 
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), clientData) 

What is the problem?

Edited by Guest
Link to comment
Check your code, you defined it "currentLevel = getElementData blabla".

I edit my code and next problem is:

ERROR: levelsystem/level_s.lua:3: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got nill] 

[server]

defaultlevel = 1 
function LevelOnWasted ( ammo, killer, killerweapon, bodypart ) 
  local account = getPlayerAccount(client) 
  if (account) and not isGuestAccount (account) then 
    if ( killer ) and ( killer ~= source ) then 
        currentlevel = getElementData( client, "levelsystem.currentlevel" ) 
    if (currentlevel) == nil then 
        setElementData ( client, "levelsystem.currentlevel", defaultlevel ) 
        setTimer(1000, 1, clientData) 
        triggerClientEvent ( playerSource, "getLevel", playerSource, "" .. defaultlevel ) 
    else 
        addLevel = currentlevel + 1 
        setElementData ( client, "levelsystem.currentlevel", addLevel ) 
        setTimer(1000, 1, clientData) 
        triggerClientEvent ( playerSource, "getLevel", playerSource, "" .. addLevel ) 
    end 
end 
end 
end 
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), LevelOnWasted) 
  

Link to comment
Post your code.

Client and server side.

[server]

defaultlevel = 1 
function LevelOnWasted ( ammo, killer, killerweapon, bodypart ) 
  if ( killer ) and ( killer ~= source ) then 
    if ( killer ) and ( killer ~= source ) then 
        currentlevel = getElementData( killer, "levelsystem.currentlevel" ) 
    if (currentlevel) == nil then 
        setElementData ( killer, "levelsystem.currentlevel", defaultlevel ) 
        setTimer(1000, 1, clientData) 
        triggerClientEvent ( playerSource, "getLevel", playerSource, "" .. defaultlevel ) 
    else 
        addLevel = currentlevel + 1 
        setElementData ( killer, "levelsystem.currentlevel", addLevel ) 
        setTimer(1000, 1, clientData) 
        triggerClientEvent ( playerSource, "getLevel", playerSource, "" .. addLevel ) 
    end 
end 
end 
end 
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), LevelOnWasted) 
  

[Client]

function playerJoin() 
    setTimer ( checkLevel, 1000, 1) 
end 
addEventHandler("onClientResourceStart", getRootElement(), playerJoin) 
  
function addLevels() 
    levelElement = guiCreateLabel ( 0.45, 0.02, 0.40, 0.40, "", true ) 
    guiSetFont ( levelElement, "sa-gothic" ) 
    guiLabelSetColor ( levelElement, math.random(0, 255), math.random(0, 255), math.random(0, 255) ) 
end 
  
function checkLevel(level) 
    setTimer ( checkLevel2, 1000, 1) 
    guiSetText ( levelElement, "Level: ".. level ) 
end 
addEvent( "getLevel", true ) 
addEventHandler( "getLevel", localPlayer, checkLevel ) 
function checkLevel2() 
    setTimer ( checkLevel, 1000, 1) 
end 
  

Now error is:

ERROR: levelsystem/level_c.lua:14: attempt to concatenate global 'level' (a nill value) 

Link to comment
Wait a moment, you are using the event "onResourceStart" to run the "LevelOnWasted" function? you should be using "onPlayerWasted".

I made the code again, and the next problem is:

convertXP timer doesn't work.

It does not update the client message. But /myxp works good.

[server]

function xpSystem(_, playerAccount) 
local lvl = getAccountData(playerAccount,"lvlsystem.currLevel") 
local xp = getAccountData(playerAccount,"lvlsystem.xp") 
    if (playerAccount) then 
        if lvl then 
  
        else 
            setAccountData(playerAccount,"lvlsystem.currLevel",0) 
        end 
        if xp then 
         
        else 
            setAccountData(playerAccount,"lvlsystem.xp",0) 
        end 
    end 
end 
addEventHandler("onPlayerLogin",getRootElement(),xpSystem) 
  
function convertXP (_, playeraccount) 
setTimer ( function(_, playeraccount) 
local xp = getAccountData(playeraccount,"lvlsystem.xp") 
local currLevel = getAccountData (playeraccount, "lvlsystem.currLevel") 
triggerClientEvent ( source, "getLevel", source, "Level: " .. currLevel .. " xp: " .. xp .. "") 
  if ( playeraccount ) then 
    local xp = getAccountData(playeraccount,"lvlsystem.xp") 
      if xp then 
        if (xp) < 1000 then 
             
        elseif (xp) > 1000 then 
          local currLevel = getAccountData (playeraccount, "lvlsystem.currLevel") 
            setAccountData(playeraccount,"lvlsystem.xp",xp - 1000) 
            setAccountData(playeraccount,"lvlsystem.currLevel",currLevel + 1) 
            -- level up message here -- 
        end 
      else 
        setAccountData(playeraccount,"lvlsystem.xp",0) 
      end 
    end 
    local xp = getAccountData(playeraccount,"lvlsystem.xp") 
    local currLevel = getAccountData (playeraccount, "lvlsystem.currLevel") 
    triggerClientEvent ( source, "getLevel", source, "Level: " .. currLevel .. " xp: " .. xp .. "") 
end, 2000, 1 ) 
end 
addEventHandler("onPlayerLogin",getRootElement(),convertXP) 
  
function checkLevelAndxp(thePlayer) 
local account = getPlayerAccount(thePlayer) 
  if ( account ) then 
    local level = getAccountData (account, "lvlsystem.currLevel") 
    local xp = getAccountData (account, "lvlsystem.xp") 
    outputChatBox("You have: " .. level .. " level and " .. xp .. " xp.", source, 0, 255, 0, true) 
  end 
end 
addCommandHandler("myxp", checkLevelAndxp) 
  
function rewardOnWasted ( ammo, killer, killerweapon, bodypart ) 
    if ( killer ) and ( killer ~= source ) then 
        local account = getPlayerAccount(killer) 
        if (account) then 
        local xp = getAccountData (account, "lvlsystem.xp") 
        randomxp = math.random(50, 100) 
        setAccountData(account,"lvlsystem.xp", xp + randomxp) 
    end 
end 
end 
addEventHandler ( "onPlayerWasted", getRootElement(), rewardOnWasted ) 

[Client]

function playerJoin() 
    setTimer ( checkLevel, 1000, 1) 
end 
addEventHandler("onClientResourceStart", getRootElement(), playerJoin) 
  
function addLevels() 
    levelElement = guiCreateLabel ( 0.4, 0.02, 0.40, 0.40, "", true ) 
    font = guiCreateFont( "font.ttf", 20 ) 
    guiSetFont( levelElement, font ) 
    guiLabelSetColor ( levelElement, 0, 180, 255 ) 
end 
addEventHandler("onClientResourceStart", getRootElement(), addLevels) 
  
function checkLevel( message ) 
    setTimer ( checkLevel2, 1000, 1) 
    guiSetText ( levelElement, "" .. message .. "" ) 
end 
addEvent( "getLevel", true ) 
addEventHandler( "getLevel", localPlayer, checkLevel ) 
function checkLevel2() 
    setTimer ( checkLevel, 1000, 1) 
end 
  

Link to comment
Any error in the debugscript?
ERROR: levelsystem/level_s.lua:21: Bad argument at @ 'getAccountData' [Expected account at arument 1, got nill 

ERROR: levelsystem/level_s.lua:22: Bad argument at @ 'getAccountData' [Expected account at arument 1, got nill 

Link to comment
setTimer ( function(_, playeraccount) 

Remove the "_" from it.

ERROR: levelsystem/level_s.lua:23: Bad argument at @ 'getAccountData' [Expected account at arument 1, got nill 

ERROR: levelsystem/level_s.lua:24: Bad argument at @ 'getAccountData' [Expected account at arument 1, got nill 

function xpSystem(_, playerAccount) 
local lvl = getAccountData(playerAccount,"lvlsystem.currLevel") 
local xp = getAccountData(playerAccount,"lvlsystem.xp") 
    if (playerAccount) then 
        if lvl then 
  
        else 
            setAccountData(playerAccount,"lvlsystem.currLevel",0) 
        end 
        if xp then 
         
        else 
            setAccountData(playerAccount,"lvlsystem.xp",0) 
        end 
    end 
end 
addEventHandler("onPlayerLogin",getRootElement(),xpSystem) 
  
function convertXP () 
setTimer ( function(playeraccount) 
  if ( playeraccount ) then 
  outputChatBox("asd") 
  local xp = getAccountData(playeraccount,"lvlsystem.xp") 
local currLevel = getAccountData (playeraccount, "lvlsystem.currLevel") 
triggerClientEvent ( source, "getLevel", source, "Level: " .. currLevel .. " xp: " .. xp .. "") 
    local xp = getAccountData(playeraccount,"lvlsystem.xp") 
      if xp then 
        if (xp) < 1000 then 
             
        elseif (xp) > 1000 then 
          local xp = getAccountData (playeraccount, "lvlsystem.xp") 
          local currLevel = getAccountData (playeraccount, "lvlsystem.currLevel") 
            setAccountData(playeraccount,"lvlsystem.xp",xp - 1000) 
            setAccountData(playeraccount,"lvlsystem.currLevel",currLevel + 1) 
            -- level up message here -- 
        end 
      else 
        setAccountData(playeraccount,"lvlsystem.xp",0) 
      end 
    end 
end, 2000, 1 ) 
end 
addEventHandler("onPlayerLogin",getRootElement(),convertXP) 
  
function checkLevelAndxp(thePlayer) 
local account = getPlayerAccount(thePlayer) 
  if ( account ) then 
    local level = getAccountData (account, "lvlsystem.currLevel") 
    local xp = getAccountData (account, "lvlsystem.xp") 
    outputChatBox("You have: " .. level .. " level and " .. xp .. " xp.", source, 0, 255, 0, true) 
  end 
end 
addCommandHandler("myxp", checkLevelAndxp) 
  
function rewardOnWasted ( ammo, killer, killerweapon, bodypart ) 
    if ( killer ) and ( killer ~= source ) then 
        local account = getPlayerAccount(killer) 
        if (account) then 
        local xp = getAccountData (account, "lvlsystem.xp") 
        randomxp = math.random(50, 100) 
        setAccountData(account,"lvlsystem.xp", xp + randomxp) 
    end 
end 
end 
addEventHandler ( "onPlayerWasted", getRootElement(), rewardOnWasted ) 

Edited by Guest
Link to comment
  • MTA Team
function convertXP (account) 
    setTimer( 
        function (playeraccount, player) 
            if ( playeraccount ) then 
                outputChatBox("asd") 
                local xp = getAccountData(playeraccount,"lvlsystem.xp") 
                local currLevel = getAccountData (playeraccount, "lvlsystem.currLevel") 
                triggerClientEvent ( player, "getLevel", player, "Level: " .. currLevel .. " xp: " .. xp .. "") 
                 
                if xp then 
                    if (xp) < 1000 then 
            
                    elseif (xp) > 1000 then 
                        local currLevel = getAccountData (playeraccount, "lvlsystem.currLevel") 
                        setAccountData(playeraccount,"lvlsystem.xp",xp - 1000) 
                        setAccountData(playeraccount,"lvlsystem.currLevel",currLevel + 1) 
                        -- level up message here -- 
                    end 
                else 
                    setAccountData(playeraccount,"lvlsystem.xp",0) 
                end 
            end 
        end,  
    2000, 1, account, source) 
end 
addEventHandler("onPlayerLogin",getRootElement(),convertXP) 

Link to comment
function convertXP (account) 
    setTimer( 
        function (playeraccount, player) 
            if ( playeraccount ) then 
                outputChatBox("asd") 
                local xp = getAccountData(playeraccount,"lvlsystem.xp") 
                local currLevel = getAccountData (playeraccount, "lvlsystem.currLevel") 
                triggerClientEvent ( player, "getLevel", player, "Level: " .. currLevel .. " xp: " .. xp .. "") 
                 
                if xp then 
                    if (xp) < 1000 then 
            
                    elseif (xp) > 1000 then 
                        local currLevel = getAccountData (playeraccount, "lvlsystem.currLevel") 
                        setAccountData(playeraccount,"lvlsystem.xp",xp - 1000) 
                        setAccountData(playeraccount,"lvlsystem.currLevel",currLevel + 1) 
                        -- level up message here -- 
                    end 
                else 
                    setAccountData(playeraccount,"lvlsystem.xp",0) 
                end 
            end 
        end,  
    2000, 1, account, source) 
end 
addEventHandler("onPlayerLogin",getRootElement(),convertXP) 

Same problem :o

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