marty000123 Posted November 15, 2016 Share Posted November 15, 2016 Hi folks. This is my gambling script. local gambling = createMarker ( 2322.7568359375, 2088.5502929688, 34.055694580078, "checkpoint", 1, 255, 0, 0, 255 ) addEventHandler("onMarkerHit",gambling, function(player) if getElementType(player) == "player" then if getPlayerMoney(player) >= 5000 then if math.random() < 1/2 then outputChatBox ("#0000ffWelcome to the Dragon Gambling House Dice! Would you like to play?",player, r, g, b, true) outputChatBox ("#ffffff*The dealer rolls the dice*",player, r, g, b, true) outputChatBox ("#00ff00Congratulations! You have won 5000$!",player, r, g, b, true) givePlayerMoney(player,5000) else outputChatBox ("#ff0000Welcome to the Dragon Gambling House Dice! Would you like to play?",player, r, g, b, true) outputChatBox ("#ffffff*The dealer rolls the dice*",player, r, g, b, true) outputChatBox ("#00ff00Aww, too bad! You have lost 6000$!",player, r, g, b, true) takePlayerMoney(player,6000) end else outputChatBox("#0000ffYou do not have enough money.",player) end end end ) I've tried multiple ways to put a timer on this, but I kept failing. I want it to have a timer for 30 seconds, so you can only gamble every 30 seconds. Selfexplainatory But after putting a timer on it, it didn't work.. Do you guys have a solution? If you enter the marker before the 30 seconds have passed, it will say ''You have to wait 30 seconds!''. - Marty Link to comment
Gravestone Posted November 15, 2016 Share Posted November 15, 2016 You can do that by inserting the timer attached to player in a table. local timers = {} local gambling = createMarker ( 2322.7568359375, 2088.5502929688, 34.055694580078, "checkpoint", 1, 255, 0, 0, 255 ) addEventHandler("onMarkerHit",gambling, function(player) if getElementType(player) == "player" then if not timers[player] then if getPlayerMoney(player) >= 5000 then if math.random() < 1/2 then outputChatBox ("#0000ffWelcome to the Dragon Gambling House Dice! Would you like to play?",player, r, g, b, true) outputChatBox ("#ffffff*The dealer rolls the dice*",player, r, g, b, true) outputChatBox ("#00ff00Congratulations! You have won 5000$!",player, r, g, b, true) givePlayerMoney(player,5000) table.insert(timers, player) setTimer(table.remove, 30000, 1, player) else outputChatBox ("#ff0000Welcome to the Dragon Gambling House Dice! Would you like to play?",player, r, g, b, true) outputChatBox ("#ffffff*The dealer rolls the dice*",player, r, g, b, true) outputChatBox ("#00ff00Aww, too bad! You have lost 6000$!",player, r, g, b, true) takePlayerMoney(player,6000) table.insert(timers, player) setTimer(table.remove, 30000, 1, player) end else outputChatBox("#0000ffYou do not have enough money.",player) end else outputChatBox("#0000ffYou must wait 30 seconds before gambling again", player) end end end ) Link to comment
marty000123 Posted November 15, 2016 Author Share Posted November 15, 2016 Hi. That didn't work, and it shows no errors or warnings on debugscript 3. I can simply run into the marker, run out, run into it again and it'll keep giving or taking me/my money. I see no timer effects, help? Link to comment
Mr.Loki Posted November 15, 2016 Share Posted November 15, 2016 (edited) something like this local playerTimer ={} local gambling = createMarker ( 0, 0, 3, "cylinder", 1, 255, 0, 0, 255 ) addEventHandler("onMarkerHit",gambling, function(player) if getElementType(player) == "player" then if getPlayerMoney(player) >= 5000 then local ptimer=playerTimer[player] if isTimer(ptimer) then outputChatBox ("#00ff00I'm sorry but you need to wait "..math.ceil(getTimerDetails( ptimer )/1000).." seconds before you can play again.",player, r, g, b, true) return else playerTimer[player]=setTimer(function()end,30000,1) end if math.random() < 1/2 then outputChatBox ("#0000ffWelcome to the Dragon Gambling House Dice! Would you like to play?",player, r, g, b, true) outputChatBox ("#ffffff*The dealer rolls the dice*",player, r, g, b, true) outputChatBox ("#00ff00Congratulations! You have won 5000$!",player, r, g, b, true) givePlayerMoney(player,5000) else outputChatBox ("#ff0000Welcome to the Dragon Gambling House Dice! Would you like to play?",player, r, g, b, true) outputChatBox ("#ffffff*The dealer rolls the dice*",player, r, g, b, true) outputChatBox ("#00ff00Aww, too bad! You have lost 6000$!",player, r, g, b, true) takePlayerMoney(player,6000) end else outputChatBox("#0000ffYou do not have enough money.",player) end end end ) Edited November 15, 2016 by loki2143 Link to comment
ManeXi Posted November 15, 2016 Share Posted November 15, 2016 local timers = {} local gambling = createMarker ( 2322.7568359375, 2088.5502929688, 34.055694580078, "checkpoint", 1, 255, 0, 0, 255 ) addEventHandler("onMarkerHit",gambling, function(player) if (getElementType(player) == "player") then if not timers[player] then if getPlayerMoney(player) >= 5000 then if math.random() < 1/2 then outputChatBox ("#0000ffWelcome to the Dragon Gambling House Dice! Would you like to play?",player, r, g, b, true) outputChatBox ("#ffffff*The dealer rolls the dice*",player, r, g, b, true) outputChatBox ("#00ff00Congratulations! You have won 5000$!",player, r, g, b, true) givePlayerMoney(player, 5000) timers[player] = setTimer(function() timers[player] = nil end, 30000, 1) else outputChatBox ("#ff0000Welcome to the Dragon Gambling House Dice! Would you like to play?",player, r, g, b, true) outputChatBox ("#ffffff*The dealer rolls the dice*",player, r, g, b, true) outputChatBox ("#00ff00Aww, too bad! You have lost 6000$!",player, r, g, b, true) takePlayerMoney(player, 6000) timers[player] = setTimer(function() timers[player] = nil end, 30000, 1) end else outputChatBox("#0000ffYou do not have enough money.",player) end else outputChatBox("#0000ffYou must wait 30 seconds before gambling again", player) end end end) Try out this one Link to comment
marty000123 Posted November 15, 2016 Author Share Posted November 15, 2016 16 minutes ago, loki2143 said: something like this local playerTimer ={} local gambling = createMarker ( 0, 0, 3, "cylinder", 1, 255, 0, 0, 255 ) addEventHandler("onMarkerHit",gambling, function(player) if getElementType(player) == "player" then if getPlayerMoney(player) >= 5000 then local ptimer=playerTimer[player] if isTimer(ptimer) then outputChatBox ("#00ff00I'm sorry but you need to wait "..math.ceil(getTimerDetails( ptimer )/1000).." seconds before you can play again.",player, r, g, b, true) return else playerTimer[player]=setTimer(function()end,30000,1) end if math.random() < 1/2 then outputChatBox ("#0000ffWelcome to the Dragon Gambling House Dice! Would you like to play?",player, r, g, b, true) outputChatBox ("#ffffff*The dealer rolls the dice*",player, r, g, b, true) outputChatBox ("#00ff00Congratulations! You have won 5000$!",player, r, g, b, true) givePlayerMoney(player,5000) else outputChatBox ("#ff0000Welcome to the Dragon Gambling House Dice! Would you like to play?",player, r, g, b, true) outputChatBox ("#ffffff*The dealer rolls the dice*",player, r, g, b, true) outputChatBox ("#00ff00Aww, too bad! You have lost 6000$!",player, r, g, b, true) takePlayerMoney(player,6000) end else outputChatBox("#0000ffYou do not have enough money.",player) end end end ) [2016-11-15 11:44:25] ERROR: gambling\server.lua:21: bad argument #1 to '?' (table expected, got userdata) [2016-11-15 11:44:29] ERROR: gambling\server.lua:14: bad argument #1 to '?' (table expected, got userdata) [2016-11-15 11:44:31] ERROR: gambling\server.lua:21: bad argument #1 to '?' (table expected, got userdata) 11 minutes ago, OverMind said: local timers = {} local gambling = createMarker ( 2322.7568359375, 2088.5502929688, 34.055694580078, "checkpoint", 1, 255, 0, 0, 255 ) addEventHandler("onMarkerHit",gambling, function(player) if (getElementType(player) == "player") then if not timers[player] then if getPlayerMoney(player) >= 5000 then if math.random() < 1/2 then outputChatBox ("#0000ffWelcome to the Dragon Gambling House Dice! Would you like to play?",player, r, g, b, true) outputChatBox ("#ffffff*The dealer rolls the dice*",player, r, g, b, true) outputChatBox ("#00ff00Congratulations! You have won 5000$!",player, r, g, b, true) givePlayerMoney(player, 5000) timers[player] = setTimer(function() timers[player] = nil end, 30000, 1) else outputChatBox ("#ff0000Welcome to the Dragon Gambling House Dice! Would you like to play?",player, r, g, b, true) outputChatBox ("#ffffff*The dealer rolls the dice*",player, r, g, b, true) outputChatBox ("#00ff00Aww, too bad! You have lost 6000$!",player, r, g, b, true) takePlayerMoney(player, 6000) timers[player] = setTimer(function() timers[player] = nil end, 30000, 1) end else outputChatBox("#0000ffYou do not have enough money.",player) end else outputChatBox("#0000ffYou must wait 30 seconds before gambling again", player) end end end) Try out this one This works, thanks! 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