Jump to content

gambling timer


marty000123

Recommended Posts

Posted

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 :P

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

560x95_FFFFFF_FF9900_000000_000000.png

Posted

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
) 

 

Clan war system http://sh.st/7r4nI

 

Posted

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?

560x95_FFFFFF_FF9900_000000_000000.png

Posted (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 by loki2143
Posted
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

Interested on a paid 3D modder?

My Skype: awdsasda.sdasdaad

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

560x95_FFFFFF_FF9900_000000_000000.png

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