John Smith Posted April 14, 2014 Posted April 14, 2014 i am starting to create somekind of xp system,just out of boredom but i got a simple problem. function xpSystem() local playerAccount = getPlayerAccount(source) local xp = getAccountData(playerAccount,"xp") if isGuestAccount(playerAccount,source,true) then return else if isGuestAccount(playerAccount,source,false) then if (playerAccount) then if xp ~= nil then setAccountData(playerAccount,"xp",0) outputChatBox(xp, getRootElement(), 0, 255, 0) end end end end end addEventHandler("onPlayerJoin",getRootElement(),xpSystem) addEventHandler("onPlayerLogin",getRootElement(),xpSystem) it doesn't output anything. no errors. maybe i haven't set account data in good way. can anyone help me please? If you find my post useful or if it helped you, please like my post Ingame name: ZoeN
Weii. Posted April 14, 2014 Posted April 14, 2014 Your code does not make any sense, you are trying to set 'xp' when but you are setting it to 0. Please explain what you want!
John Smith Posted April 14, 2014 Author Posted April 14, 2014 lol, if xp ~= nil then im checking if theres data in the account,and that data is "xp" and then if there's no data in account,im setting it to number zero(0 xp aka 0 experience) setAccountData(playerAccount,"xp",0) because if theres no account data considering "xp" it means its a new player, who (logic)-didnt make any kills so he got 0xp. Now in the script there isnt anything about killing but i will add it later,but i just want to test this out by adding 0 xp to people i hope u understand my english If you find my post useful or if it helped you, please like my post Ingame name: ZoeN
Gallardo9944 Posted April 14, 2014 Posted April 14, 2014 empty account data is false, not nil. It's better to check this way: if not xp then Code Debugger - Minimalistic MTA debug line replacement
John Smith Posted April 14, 2014 Author Posted April 14, 2014 empty account data is false, not nil. It's better to check this way: if not xp then still not outputing anything If you find my post useful or if it helped you, please like my post Ingame name: ZoeN
Moderators IIYAMA Posted April 14, 2014 Moderators Posted April 14, 2014 May I ask, how can you login manually before you join?......... isGuestAccount(playerAccount,source,false) if isGuestAccount(playerAccount) then if not isGuestAccount(playerAccount) then Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
John Smith Posted April 14, 2014 Author Posted April 14, 2014 (edited) May I ask, how can you login manually before you join?......... isGuestAccount(playerAccount,source,false) if isGuestAccount(playerAccount) then if not isGuestAccount(playerAccount) then function xpSystem() local playerAccount = getPlayerAccount(source) local xp = getAccountData(playerAccount,"xp") if isGuestAccount(playerAccount) then return else if not isGuestAccount(playerAccount) then if (playerAccount) then if not xp then setAccountData(playerAccount,"xp",0) outputChatBox(xp, getRootElement(), 0, 255, 0) end end end end end addEventHandler("onPlayerJoin",getRootElement(),xpSystem) addEventHandler("onPlayerLogin",getRootElement(),xpSystem) [16:18:39] WARNING: xp\script.lua:11: Bad argument @ 'outputChatBox' [Expected string at argument 1, got boolean] Edited April 14, 2014 by Guest If you find my post useful or if it helped you, please like my post Ingame name: ZoeN
Weii. Posted April 14, 2014 Posted April 14, 2014 function xpSystem(_, playerAccount) local xp = getAccountData(playerAccount,"xp") if (playerAccount) then if xp then outputChatBox(xp, getRootElement(), 0, 255, 0) else setAccountData(playerAccount,"xp",0) end end end addEventHandler("onPlayerLogin",getRootElement(),xpSystem)
John Smith Posted April 14, 2014 Author Posted April 14, 2014 Thanks Weii. If you find my post useful or if it helped you, please like my post Ingame name: ZoeN
John Smith Posted April 14, 2014 Author Posted April 14, 2014 by the way,i just wanted to ask one more question. how could i give xp to people when they send a message on chatbox? function giveXP(_,playerAccount) if (playerAccount) then if xp then setAccountData(playerAccount,"xp"+133) outputChatBox(xp, getRootElement(), 0, 255, 0) end end end addEventHandler("onPlayerChat",getRootElement(),giveXP) sorry if i ask for too much,i just want to know better how setAccountData works If you find my post useful or if it helped you, please like my post Ingame name: ZoeN
Moderators IIYAMA Posted April 14, 2014 Moderators Posted April 14, 2014 setAccountData(playerAccount,"xp",(getAccountData(playerAccount,"xp") or 0)+133) Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
John Smith Posted April 14, 2014 Author Posted April 14, 2014 not working If you find my post useful or if it helped you, please like my post Ingame name: ZoeN
Moderators IIYAMA Posted April 14, 2014 Moderators Posted April 14, 2014 not working NNNNOOO WORKING.... OMG! I AM SO SEXY. addEventHandler("onPlayerChat",root, function(message,messageType) local playerAccount = getPlayerAccount ( source ) if not isGuestAccount ( playerAccount) then setAccountData(playerAccount,"xp",(getAccountData(playerAccount,"xp") or 0)+133) end end) Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
John Smith Posted April 14, 2014 Author Posted April 14, 2014 thanks IIYAMA If you find my post useful or if it helped you, please like my post Ingame name: ZoeN
Moderators IIYAMA Posted April 14, 2014 Moderators Posted April 14, 2014 np. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
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