Newbie Posted February 12, 2014 Share Posted February 12, 2014 function hay(source, command) local cashHave = getAccountData(account, "cash") if cashHave >= 500 then local x,y,z = getElementPosition( player ) createObject ( 3374 , x , y , z ) setTimer(outputChatBox,50,1,"* "..getPlayerName (source).." bought hay stack",root, 255, 255, 255, true ) setAccountData(account, "cash", -500) else outputChatBox ("* You need more cash",source, 255, 255, 255, true ) cancelEvent() end end addCommandHandler("hay", hay) It should check my money if i have 500 If yes create hay stack But it dont work Link to comment
myonlake Posted February 12, 2014 Share Posted February 12, 2014 (edited) You didn't define the account, and the setAccountData didn't subtract the cost from the account's current cash amount. Also, you don't need to cancel the event, it's automatically ended if a condition isn't true. Try this. function hay( player, cmd ) local account = ( ( getPlayerAccount( player ) and not isGuestAccount( getPlayerAccount( player ) ) ) and getPlayerAccount( player ) or false ) if ( account ) then local cashHave = tonumber( getAccountData( account, "cash" ) ) if ( cashHave ) and ( cashHave >= 500 ) then local x, y, z = getElementPosition( player ) createObject( 3374, x, y, z ) outputChatBox( "* " .. getPlayerName( player ) .. " bought a hay stack.", root, 255, 255, 255, false ) setAccountData( account, "cash", cashHave - 500 ) else outputChatBox( "* You need more cash.", player, 255, 255, 255, false ) end else outputChatBox( "* You're not logged in.", player, 255, 255, 255, false ) end end addCommandHandler( "hay", hay ) Edited February 12, 2014 by Guest Link to comment
Newbie Posted February 12, 2014 Author Share Posted February 12, 2014 You didn't define the account, and the setAccountData didn't subtract the cost from the account's current cash amount. Also, you don't need to cancel the event, it's automatically ended if a condition isn't true. Try this. function hay( player, cmd ) local account = ( ( getPlayerAccount( player ) and not isGuestAccount( player ) ) and getPlayerAccount( player ) or false ) if ( account ) then local cashHave = tonumber( getAccountData( account, "cash" ) ) if ( cashHave ) and ( cashHave >= 500 ) then local x, y, z = getElementPosition( player ) createObject( 3374, x, y, z ) outputChatBox( "* " .. getPlayerName( player ) .. " bought a hay stack.", root, 255, 255, 255, false ) setAccountData( account, "cash", cashHave - 500 ) else outputChatBox( "* You need more cash.", player, 255, 255, 255, false ) end else outputChatBox( "* You're not logged in.", player, 255, 255, 255, false ) end end addCommandHandler( "hay", hay ) Really strange.. When i type /hay it outputs that i am not logged in. but i am Link to comment
Newbie Posted February 12, 2014 Author Share Posted February 12, 2014 [2014-02-11 17:56:52] WARNING: buy\buy.lua:2: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got nil] But i have account system Link to comment
myonlake Posted February 12, 2014 Share Posted February 12, 2014 Try now, forgot one thing. Link to comment
Newbie Posted February 12, 2014 Author Share Posted February 12, 2014 Works! can i know what you added ? Link to comment
myonlake Posted February 12, 2014 Share Posted February 12, 2014 Instead of isGuestAccount( player ) I switched the player to the account, forgot about that when posting my reply. 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