SkrillexX Posted February 28, 2014 Share Posted February 28, 2014 Greetings , i've been recently learning how to script and as my first script , i tried to make something simple. A command that would give you money if your money is between 1000$ and 5000$. This is my lua code. function giveMoney(cmd , thePlayer) number = math.random (1000,5000) money = getPlayerMoney(thePlayer) if money == number then givePlayerMoney(thePlayer, 1000) else outputChatBox ("You already have enough money , fool" ,getRootElement(),250 ,250 ,0 ) end addCommandHandler ("money" ,giveMoney ) end Please , if any you see an error try to notify me it. Thanks. Link to comment
Castillo Posted February 28, 2014 Share Posted February 28, 2014 function giveMoney ( thePlayer ) local number = math.random ( 1000, 5000 ) local money = getPlayerMoney ( thePlayer ) if ( money == number ) then givePlayerMoney ( thePlayer, 1000 ) else outputChatBox ( "You already have enough money , fool", thePlayer, 250, 250, 0 ) end end addCommandHandler ( "money", giveMoney ) By the way, this script will check if your money is EXACTLY the same amount as math.random returned. Link to comment
SkrillexX Posted February 28, 2014 Author Share Posted February 28, 2014 Thanks but how to make it check if its between 1000$ and 5000$ ? Link to comment
Castillo Posted February 28, 2014 Share Posted February 28, 2014 function giveMoney ( thePlayer ) local money = getPlayerMoney ( thePlayer ) if ( money < 5000 ) then givePlayerMoney ( thePlayer, 1000 ) else outputChatBox ( "You already have enough money , fool", thePlayer, 250, 250, 0 ) end end addCommandHandler ( "money", giveMoney ) Link to comment
SkrillexX Posted February 28, 2014 Author Share Posted February 28, 2014 Alright , thanks a lot. Link to comment
Moderators Citizen Posted February 28, 2014 Moderators Share Posted February 28, 2014 Thanks but how to make it check if its between 1000$ and 5000$ ? Well the if statement you wanted was: if ( money > 1000 and money < 5000 ) then 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