mint3d Posted June 13, 2014 Share 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) Link to comment
Et-win Posted June 13, 2014 Share 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. Link to comment
mint3d Posted June 13, 2014 Author Share Posted June 13, 2014 Can you help me with a timer? I don't know because I never gave the function a name.. Link to comment
Et-win Posted June 13, 2014 Share 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) Link to comment
Spajk Posted June 13, 2014 Share 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) Link to comment
mint3d Posted June 13, 2014 Author Share 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... Link to comment
Et-win Posted June 13, 2014 Share Posted June 13, 2014 Spajk said: Try it out: code You are now only editing the data, not the scoreboard. Link to comment
Spajk Posted June 13, 2014 Share 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) Link to comment
mint3d Posted June 14, 2014 Author Share 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.. Link to comment
Price. Posted June 14, 2014 Share 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. Link to comment
mint3d Posted June 14, 2014 Author Share 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.. Link to comment
Et-win Posted June 14, 2014 Share 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)) Link to comment
Spajk Posted June 14, 2014 Share 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. Link to comment
mint3d Posted June 14, 2014 Author Share Posted June 14, 2014 Still doesn't work. Scoreboard doesn't go up levels. Only when I login it changes. @Et-Win Link to comment
mint3d Posted June 14, 2014 Author Share Posted June 14, 2014 Sorry for double post... Spajk Thanks dude yours worked. Link to comment
Clov3R Posted March 7, 2019 Share 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 11: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. Expand if anyone is willing to help me out id really appericiate it :D ty 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