Jump to content

bet system


#Paper

Recommended Posts

  
-- first you create a table to hold your bet info: 
bets = {} 
  
-- when someone bets on someone, you save it. 
-- guy = the player/name on which the bet is placed 
-- amount = the cash 
bets[player] = {guy, amount} 
  
-- when someone wins in game, you check the winners: 
-- winner = lets say its the player who won 
for player, bet in pairs(bets) do 
  if bet[1] == winner then -- check if player won the bet 
    givePlayerMoney(player, bet[2]*2) -- example, givex 2x the amount of bet 
  end 
end 
bets = {} -- clear all bets 
  

Link to comment
  
-- first you create a table to hold your bet info: 
bets = {} 
  
-- when someone bets on someone, you save it. 
-- guy = the player/name on which the bet is placed 
-- amount = the cash 
bets[player] = {guy, amount} 
  
-- when someone wins in game, you check the winners: 
-- winner = lets say its the player who won 
for player, bet in pairs(bets) do 
  if bet[1] == winner then -- check if player won the bet 
    givePlayerMoney(player, bet[2]*2) -- example, givex 2x the amount of bet 
  end 
end 
bets = {} -- clear all bets 
  

Don't works T_T

Link to comment

here's:

function onPlaceBet (playerSource, cmd, guy, amount) 
if amount < getElementData(playerSource, "Points") then 
outputChatBox("#00FF00<#9370DBServer#00FF00>#ff0000: #9ACD32Not enough Points!", playerSource, 255,255,255, true) 
else 
if not guy or amount then 
outputChatBox("#00FF00<#9370DBServer#00FF00>#ff0000: #9ACD32Syntax: /bet [playerID] [betAmount]", playerSource, 255,255,255, true) 
else 
--ADD THE BET 
outputChatBox("#00FF00<#9370DBServer#00FF00>#ff0000: #9ACD32"..getPlayerName(playerSource).." #9ACD32Place a bet on "..getPlayerName(getPlayerFromID(guy)).."#9ACD32!", getRootElement(), 255,255,255, true) 
end 
end 
end 
  
addEvent("onRaceStateChanging") 
function removeCmd ()  
outputChatBox("#00FF00<#9370DBServer#00FF00>#ff0000: #9ACD32Bets Closeds!", getRootElement(), 255,255,255, true)  
removeCommandHandler("bet", onPlaceBet) 
end 
addEventHandler("onRaceStateChanging",getRootElement(),removeCmd) 
  
addEvent("onGamemodeMapStart") 
function addCmd () 
outputChatBox("#00FF00<#9370DBServer#00FF00>#ff0000: #9ACD32Place now your bets: /bet [thePlayer] [betAmount] ", getRootElement(), 255,255,255, true) 
addCommandHandler("bet", onPlaceBet) 
end 
addEventHandler("onGamemodeMapStart", getRootElement(), showMsg) 
  
function onPlayerEx (theWinner) 
--THAT FUNCTION IS CALLED BY WIN FUNC 
--GIVE POINTS TO THE BETTER 
end 

Link to comment

1. there's nothing here that's actually processes the bets.

2. «if not guy or amount then» is wrong. it will be true if amount is not nil/false, use «if not guy or not amount then». use ( and ) if you're getting lost in conditions.

3. you should place «not amount» check before comparing it with something.

Link to comment
  
-- first you create a table to hold your bet info: 
bets = {} 
  
function onPlaceBet (playerSource, cmd, guy, amount) 
  guy = getPlayerFromID(guy) 
  amount = tonumber(amount) 
  if (guy and amount) and amount > 0 then -- check so players wont bet negative amounts 
    local points = tonumber(getElementData(playerSource, "Points")) 
    if points < amount then  
      outputChatBox("#00FF00<#9370DBServer#00FF00>#ff0000: #9ACD32Not enough Points!", playerSource, 255,255,255, true) 
    else    
      --ADD THE BET 
      bets[playerSource] = {guy, amount} 
      setElementData(playerSource, "Points", points - amount) -- accept the bet and take the points 
      outputChatBox("#00FF00<#9370DBServer#00FF00>#ff0000: #9ACD32"..getPlayerName(playerSource).." #9ACD32Placed a bet on "..getPlayerName(guy).."#9ACD32!", getRootElement(), 255,255,255, true) 
    end 
  else 
    outputChatBox("#00FF00<#9370DBServer#00FF00>#ff0000: #9ACD32Syntax: /bet [playerID] [betAmount]", playerSource, 255,255,255, true) 
  end 
end 
  
addEvent("onRaceStateChanging") 
function removeCmd () 
  outputChatBox("#00FF00<#9370DBServer#00FF00>#ff0000: #9ACD32Bets Closed!", getRootElement(), 255,255,255, true) 
  removeCommandHandler("bet", onPlaceBet) 
end 
addEventHandler("onRaceStateChanging", getRootElement(), removeCmd) 
  
addEvent("onGamemodeMapStart") 
function addCmd () 
  outputChatBox("#00FF00<#9370DBServer#00FF00>#ff0000: #9ACD32Place now your bets: /bet [thePlayer] [betAmount] ", getRootElement(), 255,255,255, true) 
  addCommandHandler("bet", onPlaceBet) 
end 
addEventHandler("onGamemodeMapStart", getRootElement(), addCmd) 
  
function onPlayerEx (theWinner) 
  --THAT FUNCTION IS CALLED BY WIN FUNC 
  --GIVE POINTS TO THE BETTER 
  for player, bet in pairs(bets) do 
    if isElement(player) then -- check if a player still there 
      local points = tonumber(getElementData(player, "Points")) 
      if bet[1] == theWinner then -- check if player won the bet 
        setElementData(player, "Points", points + bet[2]*2) -- give him 2x the points 
        outputChatBox("#00FF00<#9370DBServer#00FF00>#ff0000: #9ACD32Your bet won: "..(bet[2]*2).." point(s) earned!", player, 255,255,255, true) 
      end 
    end   
  end 
  
  -- clear the bets list 
  bets = {}  
end 
  

Link to comment
function onPlayerEx (theWinner) 
  --THAT FUNCTION IS CALLED BY WIN FUNC 
  --GIVE POINTS TO THE BETTER 
  for player, bet in pairs(bets) do 
    if isElement(player) then -- check if a player still there 
      local points = tonumber(getElementData(player, "Points")) 
      if bet[1] == theWinner then -- check if player won the bet 
        setElementData(player, "Points", points + bet[2]*2) -- give him 2x the points 
        outputChatBox("#00FF00<#9370DBServer#00FF00>#ff0000: #9ACD32Your bet won: "..(bet[2]*2).." point(s) earned!", player, 255,255,255, true) 
      end 
    end   
  end 
  -- clear the bets list 
  bets = {}  
end 
  

don't works this func T_T

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