Jump to content

How to make a money betting system?


TimeTraveller

Recommended Posts

Posted

I would like to know how to do that, for example, you place a command like /bet, place an amount of money that you want but that you have, and that money is discounted or doubled when you place it, randomly.

Posted

Well something like this could work i never did one such system but u need something like math.random() or some kind of function to get some random numbers

 function bet_some_money(thePlayer,CommandName,amount)
  	if source == thePlayer then  -- check for player
    	local playerMoney = getPlayerMoney(thePlayer) -- get how much money has the player who calls the command 
    	if amount ~= nil and type(amount) == "number" then  -- check if amount is not nil and also if it is a number
    		if amount <= playerMoney then  -- chek if amount is not more than all the money he has at him now 
      			takePlayerMoney(thePlayer,amount) -- take the money 
      		  local number = math.random(0,1) -- a random number also u can use a table with numbers or %
      			if number == 0 then 
        		  outputChatBox("[BET] You lose this time, maybe u have more luck next time!",thePlayer,255,104,104)
      		  elseif number == 1 then 
        		outputChatBox("[BET] You won gg man :D",thePlayer,104,255,104)
        		givePlayerMoney(thePlayer,2*amount) -- give player 2 x amount
              end
       	   end 
      	end
    end
 end

also this code is not tested!!!

Posted
function bet(player, cmd, amount)
    amount = tonumber(amount)
    if not amount or amount <= 0 then
        outputChatBox("Invalid bet amount.", player, 255, 0, 0, true)
        return
    end

    local money = getPlayerMoney(player)
    if money < amount then
        outputChatBox("You don't have enough money to make that bet.", player, 255, 0, 0, true)
        return
    end

    local win = math.random(0, 1) == 1
    if win then
        givePlayerMoney(player, amount*2)
        outputChatBox("You won your bet of $" .. amount .. "!", player, 0, 255, 0, true)
    else
        takePlayerMoney(player, amount)
        outputChatBox("You lost your bet of $" .. amount .. ".", player, 255, 0, 0, true)
    end
end
addCommandHandler("bet", bet)

 

  • Like 1

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