John Smith Posted April 14, 2014 Share 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? Link to comment
Weii. Posted April 14, 2014 Share 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! Link to comment
John Smith Posted April 14, 2014 Author Share 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 Link to comment
Gallardo9944 Posted April 14, 2014 Share Posted April 14, 2014 empty account data is false, not nil. It's better to check this way: if not xp then Link to comment
John Smith Posted April 14, 2014 Author Share 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 Link to comment
Moderators IIYAMA Posted April 14, 2014 Moderators Share 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 Link to comment
John Smith Posted April 14, 2014 Author Share 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 Link to comment
Weii. Posted April 14, 2014 Share 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) Link to comment
John Smith Posted April 14, 2014 Author Share 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 Link to comment
Moderators IIYAMA Posted April 14, 2014 Moderators Share Posted April 14, 2014 setAccountData(playerAccount,"xp",(getAccountData(playerAccount,"xp") or 0)+133) Link to comment
Moderators IIYAMA Posted April 14, 2014 Moderators Share 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) 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