LabiVila Posted August 10, 2014 Share Posted August 10, 2014 bets = {} function bet (source, cmd, betted, amount) betted = getPlayerFromName (betted) amount = tonumber (amount) if (betted and amount) and amount > 0 then local money = getPlayerMoney (source) if money < amount then outputChatBox ("No enough money") else bets [source] = {betted, amount} takePlayerMoney (source, amount) outputChatBox ("BEtted") end end end function removeCmd (state) if (state == "Running") then outputChatBox ("Best closed") removeCommandHandler ("bet", bet) end end addEvent ("onRaceStateChanging") addEventHandler ("onRaceStateChanging", getRootElement(), removeCmd) function addCmd () outputChatBox ("Place bets") addCommandHandler ("bet", bet) end addEventHandler ("onGamemodeMapStart", getRootElement(), addCmd) function winner () winner = getPlayerName(source) outputChatBox (winner.." won wthe round") if winner == betted then outputChatBox ("Great job") givePlayerMoney (source, amount*2) end end addEvent ("onPlayerWinDD", true) addEventHandler ("OnPlayerWinDD", getRootElement(), winner) https://forum.multitheftauto.com/viewtopic.php?f=91&t=31731 - I was actually based on this. But what's not working up there? There's no debugscript 3 message as well... thanks further Link to comment
xXMADEXx Posted August 10, 2014 Share Posted August 10, 2014 You did nothing to even explain your problem... Link to comment
Et-win Posted August 10, 2014 Share Posted August 10, 2014 function addCmd () outputChatBox ("Place bets") addCommandHandler ("bet", bet) end addEventHandler ("onGamemodeMapStart", getRootElement(), addCmd) You forgot 'addEvent'. Link to comment
LabiVila Posted August 10, 2014 Author Share Posted August 10, 2014 Thanks for the reply Etwin my dude but sadly that's not the only problem as I see... here's a better explanation: This is a bet system, for DM gamemode, and something is not working on it. Everything works cool but I think I haven't got the winner in the proper way, so he doesn't get the reward if the betted player won the map. Thanks further.. Link to comment
xXMADEXx Posted August 10, 2014 Share Posted August 10, 2014 Try running this code, although I didn't test it bets = {} function bet (source, cmd, betted, amount) if ( bets [ source ] ) then return outputChatBox ( "You already have a bet placed", source ) end local a = tonumber( amount ) if ( not a ) then return outputChatBox ( "Invalid number", source ) end if ( getPlayerMoney ( source ) < a ) then return outputChatBox ( "You don't have enough money", source ) end local betted = getPlayerFromName ( betted or "" ) if ( not betted ) then return outputChatBox ( "Invalid player", source ) end takePlayerMoney ( source, amount ) bets [ source ] = { player = betted, amount = amount } outputChatBox ( "You placed a bet of $"..tostring(amount).." on "..getPlayerName ( betted ), source ) end function removeCmd (state) if (state == "Running") then outputChatBox ("Betting closed") removeCommandHandler ("bet", bet) end end addEvent ("onRaceStateChanging") addEventHandler ("onRaceStateChanging", getRootElement(), removeCmd) function addCmd () outputChatBox ("Place bets") addCommandHandler ("bet", bet) end addEvnet ( "onGamemodeMapStart", addCmd ) addEventHandler ("onGamemodeMapStart", getRootElement(), addCmd) function winner () winner = getPlayerName(source) outputChatBox (winner.." won wthe round") for i, v in pairs ( bets ) do if ( isElement ( i ) ) then if ( source == v.player ) then givePlayerMoney ( i, v.amount * 2 ) outputChatBox ( "You won a bet of $"..v.amount.." placed on "..getPlayerName ( source ), i ) end end end bets = { } end addEvent ("onPlayerWinDD", true) addEventHandler ("OnPlayerWinDD", getRootElement(), winner) Link to comment
LabiVila Posted August 10, 2014 Author Share Posted August 10, 2014 Thanks for the answer again, fixed all debugscript until they didn't came anymore :v however, I think this part of the script isn't working: function winner () winner = getPlayerName(source) outputChatBox (winner.." won wthe round") for i, v in pairs ( bets ) do if ( isElement ( i ) ) then if ( source == v.player ) then givePlayerMoney ( i, v.amount * 2 ) outputChatBox ( "You won a bet of $"..v.amount.." placed on "..getPlayerName ( source ), i ) end end end bets = { } end addEvent ("onPlayerWinDD", true) addEventHandler ("OnPlayerWinDD", getRootElement(), winner) it doesn't output the chatbox, nor get the winner or give the price. Link to comment
xXMADEXx Posted August 11, 2014 Share Posted August 11, 2014 (edited) Thanks for the answer again, fixed all debugscript until they didn't came anymore :v however, I think this part of the script isn't working: function winner () winner = getPlayerName(source) outputChatBox (winner.." won wthe round") for i, v in pairs ( bets ) do if ( isElement ( i ) ) then if ( source == v.player ) then givePlayerMoney ( i, v.amount * 2 ) outputChatBox ( "You won a bet of $"..v.amount.." placed on "..getPlayerName ( source ), i ) end end end bets = { } end addEvent ("onPlayerWinDD", true) addEventHandler ("OnPlayerWinDD", getRootElement(), winner) it doesn't output the chatbox, nor get the winner or give the price. My bad, there was a typo in my code. I put "OnPlayerWinDD" instead of "onPlayerWinDD" Try this function winner () local winner = getPlayerName(source) outputChatBox (winner.." won wthe round") for i, v in pairs ( bets ) do if ( isElement ( i ) ) then if ( source == v.player ) then givePlayerMoney ( i, v.amount * 2 ) outputChatBox ( "You won a bet of $"..v.amount.." placed on "..getPlayerName ( source ), i ) end end end bets = { } end addEvent ("onPlayerWinDD", true) addEventHandler ("onPlayerWinDD", getRootElement(), winner) Edited August 11, 2014 by Guest Link to comment
Et-win Posted August 11, 2014 Share Posted August 11, 2014 If it doesn't work by then, change function name because you have it the same a variable. (Not totally sure or that matters) Link to comment
xXMADEXx Posted August 11, 2014 Share Posted August 11, 2014 If it doesn't work by then, change function name because you have it the same a variable. (Not totally sure or that matters) Oh, I didn't notice that. Yes, it would redefine the winner function to the player name, since the variable wasn't locally created. I fixed it in my code from my previous post. Link to comment
LabiVila Posted August 11, 2014 Author Share Posted August 11, 2014 Working perfectly, thank you so much guys, I really appreciate your help 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