Jump to content

Command dont work


Newbie

Recommended Posts

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

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 by Guest
Link to comment
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

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...