#Paper Posted February 2, 2011 Share Posted February 2, 2011 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? Link to comment
Aibo Posted February 2, 2011 Share Posted February 2, 2011 -- 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
#Paper Posted February 3, 2011 Author Share Posted February 3, 2011 -- 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
Castillo Posted February 3, 2011 Share Posted February 3, 2011 Show us what your code. Link to comment
#Paper Posted February 3, 2011 Author Share Posted February 3, 2011 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
Aibo Posted February 3, 2011 Share Posted February 3, 2011 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
#Paper Posted February 4, 2011 Author Share Posted February 4, 2011 1. there's nothing here that's actually processes the bets. can you insert the bet function in my code? pls Link to comment
Aibo Posted February 4, 2011 Share Posted February 4, 2011 -- 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
#Paper Posted February 4, 2011 Author Share Posted February 4, 2011 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
proracer Posted February 4, 2011 Share Posted February 4, 2011 Type /debugscript 3 and tell us your errors. Link to comment
#Paper Posted February 4, 2011 Author Share Posted February 4, 2011 Type /debugscript 3 and tell us your errors. the win func does not show any error T_T Link to comment
Castillo Posted February 5, 2011 Share Posted February 5, 2011 Maybe you should try to fix it before asking for help? Link to comment
#Paper Posted February 5, 2011 Author Share Posted February 5, 2011 Maybe you should try to fix it before asking for help? idk why you think that i didn't try to fix it <_< Link to comment
Izam Posted February 6, 2011 Share Posted February 6, 2011 hes saying you need to fix it and not them Link to comment
Castillo Posted February 6, 2011 Share Posted February 6, 2011 lol, you got me wrong, i said YOU SHOULD TRY TO FIX IT before asking for help. Link to comment
#Paper Posted February 6, 2011 Author Share Posted February 6, 2011 lol, you got me wrong, i said YOU SHOULD TRY TO FIX IT before asking for help. i tryed... Link to comment
Castillo Posted February 6, 2011 Share Posted February 6, 2011 Okay then, show what you tryied. Link to comment
Izam Posted February 6, 2011 Share Posted February 6, 2011 lol, you got me wrong, i said YOU SHOULD TRY TO FIX IT before asking for help. Dont you see he cant? Link to comment
#Paper Posted February 7, 2011 Author Share Posted February 7, 2011 Okay then, show what you tryied. np, i fixxed it works 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