Miika Posted December 31, 2014 Share Posted December 31, 2014 (edited) 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 January 2, 2015 by Guest Link to comment
Castillo Posted December 31, 2014 Share Posted December 31, 2014 That's because 'currentLevel' is nil, you forgot to define it the same way you did in "LevelOnWasted" function. Link to comment
Miika Posted December 31, 2014 Author Share Posted December 31, 2014 That's because 'currentLevel' is nil, you forgot to define it the same way you did in "LevelOnWasted" function. But how ? Link to comment
Castillo Posted December 31, 2014 Share Posted December 31, 2014 Check your code, you defined it "currentLevel = getElementData blabla". Link to comment
Miika Posted December 31, 2014 Author Share Posted December 31, 2014 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
Castillo Posted December 31, 2014 Share Posted December 31, 2014 Change 'client' to 'killer'. Link to comment
Miika Posted December 31, 2014 Author Share Posted December 31, 2014 Change 'client' to 'killer'. Same problem Link to comment
Castillo Posted December 31, 2014 Share Posted December 31, 2014 Move this: local account = getPlayerAccount(client) if (account) and not isGuestAccount (account) then after: if ( killer ) and ( killer ~= source ) then Link to comment
Miika Posted December 31, 2014 Author Share Posted December 31, 2014 Move this: local account = getPlayerAccount(client) if (account) and not isGuestAccount (account) then after: if ( killer ) and ( killer ~= source ) then ERROR: levelsystem/level_c.lua:16: attempt to concatenate global 'level' (a nill value) Link to comment
Castillo Posted December 31, 2014 Share Posted December 31, 2014 Post your code. Client and server side. Link to comment
Miika Posted December 31, 2014 Author Share Posted December 31, 2014 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
Mizudori Posted January 1, 2015 Share Posted January 1, 2015 Hey man it is New Year here and maybe I am to drunk but where is ur addLevel declared. It's says that your level var which is addlevel or defaultlevel is empty Link to comment
Miika Posted January 1, 2015 Author Share Posted January 1, 2015 Hey man it is New Year here and maybe I am to drunk but where is ur addLevel declared. It's says that your level var which is addlevel or defaultlevel is empty guy, I know it. But I want a solution. Link to comment
Castillo Posted January 1, 2015 Share Posted January 1, 2015 Wait a moment, you are using the event "onResourceStart" to run the "LevelOnWasted" function? you should be using "onPlayerWasted". Link to comment
Miika Posted January 1, 2015 Author Share Posted January 1, 2015 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
Castillo Posted January 1, 2015 Share Posted January 1, 2015 Any error in the debugscript? Link to comment
Miika Posted January 1, 2015 Author Share Posted January 1, 2015 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
Castillo Posted January 1, 2015 Share Posted January 1, 2015 end, 2000, 1 ) You forgot to pass the "playeraccount" argument. Link to comment
Miika Posted January 1, 2015 Author Share Posted January 1, 2015 end, 2000, 1 ) You forgot to pass the "playeraccount" argument. you mean like this? end, 2000, 1, playeraccount ) Doesn't work Link to comment
Castillo Posted January 1, 2015 Share Posted January 1, 2015 setTimer ( function(_, playeraccount) Remove the "_" from it. Link to comment
Miika Posted January 1, 2015 Author Share Posted January 1, 2015 (edited) 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 January 2, 2015 by Guest Link to comment
MTA Team botder Posted January 2, 2015 MTA Team Share Posted January 2, 2015 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
Miika Posted January 2, 2015 Author Share Posted January 2, 2015 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 Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now