Jump to content

bet system


#Paper

Recommended Posts

Posted

I'm making a bet system, my question:

-M$P-SuN bets 1000$ on -M$P-Delrey

-M$P-Delrey bets 2000$ on -M$P-Richi^^

-----------------------

-M$P-Delrey wins!-

How i can get the player that had placed his bet on Delrey and give money to he?

mtaubluascripter.png

My skype: skiper964

I helped you? Help me! ^^

Help me bro! ^^

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

?

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

mtaubluascripter.png

My skype: skiper964

I helped you? Help me! ^^

Help me bro! ^^

Posted

Show us what your code.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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 

mtaubluascripter.png

My skype: skiper964

I helped you? Help me! ^^

Help me bro! ^^

Posted

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.

?

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

?

Posted
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

mtaubluascripter.png

My skype: skiper964

I helped you? Help me! ^^

Help me bro! ^^

Posted

Maybe you should try to fix it before asking for help?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

lol, you got me wrong, i said YOU SHOULD TRY TO FIX IT before asking for help.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Okay then, show what you tryied.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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