#Paper Posted July 5, 2011 Share Posted July 5, 2011 (edited) onPlayerEx doesn't work: bets = {} function onPlaceBet (playerSource, cmd, guy, amount) if isGuestAccount(getPlayerAccount(playerSource)) == false then if tonumber(amount) >= tonumber(getAccountData(getPlayerAccount(playerSource), "cash")) then _outputChatBox("#0fc0fcNot enough Cash!", playerSource) else if tonumber(amount) < 1000 and tonumber(amount) > 100 then if not guy or not amount then _outputChatBox("#0fc0fcSyntax: /#0fc0fcbet [playerID] [betAmount]", playerSource) else if getPlayerFromParticalName(guy) then bets[playerSource] = {getPlayerFromParticalName(guy), tonumber(amount)} else _outputChatBox("#0fc0fcInvalid Player!", playerSource) end addStat(getPlayerAccount(playerSource), "cash", -tonumber(amount)) _outputChatBox("#ffffff"..getPlayerName(playerSource).." #0fc0fcbetted "..amount.."$ on #ffffff"..getPlayerName(getPlayerFromParticalName(guy)).."!", getRootElement()) end else _outputChatBox("#0fc0fcMin. amount is 100$ and max amount is 1000$!", playerSource) end end end end addEvent("onRaceStateChanging") function removeCmd (state) if state == "Running" then _outputChatBox("#0fc0fcBets Closeds!", getRootElement()) removeCommandHandler("bet", onPlaceBet) end end addEventHandler("onRaceStateChanging",getRootElement(),removeCmd) addEvent("onGamemodeMapStart") function addCmd () _outputChatBox("#0fc0fcPlace now your bets: /#0fc0fcbet [thePlayer] [betAmount] ", getRootElement()) addCommandHandler("bet", onPlaceBet) end addEventHandler("onGamemodeMapStart", getRootElement(), addCmd) function onPlayerEx (theWinner) for player, bet in ipairs(bets) do if not bets == nil and isElement(player) then if bet[1] == theWinner then outputDebugString("Winning bet from:".. getPlayerName(player)) if isGuestAccount(getPlayerAccount(player)) == false then addStat(getPlayerAccount(player), "cash", bet[2]*2) _outputChatBox("#0fc0fcYour bet won: "..(bet[2]*2).."$ earned!", player) end end end end bets = {} end P.S: theWinner in onPlayerEx is called by the win function P.P.S: _outputChatBox is a custom function, don't worry Edited July 5, 2011 by Guest Link to comment
JR10 Posted July 5, 2011 Share Posted July 5, 2011 onPlayerEx is not called any where in your script. Link to comment
#Paper Posted July 5, 2011 Author Share Posted July 5, 2011 I didn't post whole code: it is Link to comment
#Paper Posted July 7, 2011 Author Share Posted July 7, 2011 <_< thanks all for help... Link to comment
Deltanic Posted July 7, 2011 Share Posted July 7, 2011 ok ty oh.. if not bets == nil and isElement(player) then 'if not bets == nil'? lmao, that's basically the same as 'if bet', unless you want to filter 'false' out. But since this is a table (as you're using this var to loop), you have to put this check ABOVE the loop, not in it. It will never be called if the variable 'bets' isn't a table since there's nothing to loop then. Also, if bet[1] == theWinner then Why do you need a loop then? You only check bet[1], not all other bets. And you're counting bet[2] up to you stats, but what if the second bet won? Then the loser gets cash? Doesn't seem right for me Also try debugstrings. Output stuff like tostring(bets) or type(bets) to see if bets exists properly, and tostring(bet) to see if the bet is correct. And more like this. Debugging like this might solve the problem too Link to comment
#Paper Posted July 7, 2011 Author Share Posted July 7, 2011 ok tyoh.. if not bets == nil and isElement(player) then 'if not bets == nil'? lmao, that's basically the same as 'if bet', unless you want to filter 'false' out. But since this is a table (as you're using this var to loop), you have to put this check ABOVE the loop, not in it. It will never be called if the variable 'bets' isn't a table since there's nothing to loop then. Also, if bet[1] == theWinner then Why do you need a loop then? You only check bet[1], not all other bets. And you're counting bet[2] up to you stats, but what if the second bet won? Then the loser gets cash? Doesn't seem right for me Also try debugstrings. Output stuff like tostring(bets) or type(bets) to see if bets exists properly, and tostring(bet) to see if the bet is correct. And more like this. Debugging like this might solve the problem too ty bro, i'll try 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