mint3d Posted June 13, 2014 Posted June 13, 2014 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)
Et-win Posted June 13, 2014 Posted June 13, 2014 This code is only doing it's job if you Login. You should put a timer or an Event on it so it keeps checking the player's level.
mint3d Posted June 13, 2014 Author Posted June 13, 2014 Can you help me with a timer? I don't know because I never gave the function a name..
Et-win Posted June 13, 2014 Posted June 13, 2014 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)
Spajk Posted June 13, 2014 Posted June 13, 2014 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)
mint3d Posted June 13, 2014 Author Posted June 13, 2014 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...
Et-win Posted June 13, 2014 Posted June 13, 2014 Try it out: code You are now only editing the data, not the scoreboard.
Spajk Posted June 13, 2014 Posted June 13, 2014 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)
mint3d Posted June 14, 2014 Author Posted June 14, 2014 It has nothing to do with that.. I only want the scoreboard to change.. It's simply the scoreboard that's not updating..
Price. Posted June 14, 2014 Posted June 14, 2014 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.
mint3d Posted June 14, 2014 Author Posted June 14, 2014 I can't add a name everytime I try add it. it says something about brackets near then the name I put..
Et-win Posted June 14, 2014 Posted June 14, 2014 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))
Spajk Posted June 14, 2014 Posted June 14, 2014 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.
mint3d Posted June 14, 2014 Author Posted June 14, 2014 Still doesn't work. Scoreboard doesn't go up levels. Only when I login it changes. @Et-Win
mint3d Posted June 14, 2014 Author Posted June 14, 2014 Sorry for double post... Spajk Thanks dude yours worked.
Clov3R Posted March 7, 2019 Posted March 7, 2019 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
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