Jump to content

not outputing account data "xp"


John Smith

Recommended Posts

Posted

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

560x95_FFFFFF_FF9900_000000_000000.png

Posted

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!

Posted

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

560x95_FFFFFF_FF9900_000000_000000.png

Posted
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

560x95_FFFFFF_FF9900_000000_000000.png

  • Moderators
Posted

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 

  Tutorials  4x 

 

Posted (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 by Guest

If you find my post useful or if it helped you, please like my post :)
Ingame name: ZoeN

560x95_FFFFFF_FF9900_000000_000000.png

Posted
  
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) 
  

Posted

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

560x95_FFFFFF_FF9900_000000_000000.png

  • Moderators
Posted
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 

  Tutorials  4x 

 

  • Moderators
Posted
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 

  Tutorials  4x 

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...