Jump to content

Why it needs refresh to check money?


papam77

Recommended Posts

  
function boughtSM ( button ) 
    if button == "left" then 
    if ( g_Money == 15 ) or ( g_Money > 15 ) then 
    outputChatBox ("#ffffffYou bought Salad Meal", 255,255,255, true ) 
    takePlayerMoney (15) 
    else 
    outputChatBox ("#ff0000Sorry, you have no enough money", 255,255,255, true ) 
    takePlayerMoney (0) 
    end         
    end 
end 
  

Why it needs restart script to check money again?

Because When I set my money to 15, I need then restart this script to check it again, because without restart it writes You've no enough money...

Where's the problem?

Link to comment

g_Money is a variable somewhere. You have to make sure you keep g_Money updated, or just replace g_Money with getPlayerMoney(). You should also take under consideration that client-side money actions only affect the client and not the server - therefore it doesn't synchronize and they can abuse the code quite easily.

Link to comment
But I defined g_Money like getPlayerMoney()

local g_Money = getPlayerMoney()

  
function boughtSM ( button ) 
    if button == "left" then 
    local g_Money = getPlayerMoney() -- define it inside the function. 
    if ( g_Money >= 15 ) then -- >= greater than or equal to. 
    outputChatBox ("#ffffffYou bought Salad Meal", 255,255,255, true ) 
    takePlayerMoney (15) 
    else 
    outputChatBox ("#ff0000Sorry, you have no enough money", 255,255,255, true ) 
     -- takePlayerMoney (0) -- no need for this. 
    end         
    end 
end 
  

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