Jump to content

[HELP] getTickCount


queenshe

Recommended Posts

How to add time limit?
 

elseif source == can then
		if getPlayerMoney() >= 5000 then
			if getElementHealth(localPlayer) ~= 100 then
				setElementHealth(localPlayer,100)
				triggerServerEvent("TakeMoney",localPlayer)
				outputChatBox("#888888 5000$ #FFFFFFkarşılığında canın dolduruldu!",0,255,0,true)
			else
				outputChatBox("Canın zaten dolu!",255,0,0,true)
			end
		else
			outputChatBox("Paran yetmiyor!",255,0,0,true)
		end
		setTimer(guiSetPosition,50,5,canimg,g-132,2,false)
		setTimer(guiSetPosition,60,5,canimg,g-128,1,false)

and

elseif source == zirh then
		if getPlayerMoney() >= 5000 then
			if getPedArmor(localPlayer) ~= 100 then
				triggerServerEvent("setPlayerArmor",localPlayer)
				outputChatBox("#888888 5000$ #FFFFFFkarşılığında çelik yelek giydin!",0,255,0,true)
			else
				outputChatBox("Çelik yeleğin zaten sağlam!",255,0,0,true)
			end
		else
			outputChatBox("Paran yetmiyor!",255,0,0,true)
		end
		setTimer(guiSetPosition,50,5,zirhimg,g-132,2,false)
		setTimer(guiSetPosition,60,5,zirhimg,g-128,1,false)

 

Link to comment

Client version

-- Create a var to hold a timer.
local pTimer

addCommandHandler( "yo", function( plr, cmd, ... )
	-- Check if there is no timer.
	if not isTimer( pTimer ) then 
		-- Create a timer of 5 seconds for the player and assign it to the var.
		pTimer = setTimer(function()end,5000,1)
		-- Execute code
		outputChatBox( "All good bro B)")
	else
		outputChatBox( "Pls chill. You used this less than 5 seconds ago.")
	end
end )

Server version

-- Create a table to hold a timer for each player.
local pTimer = {} 

addCommandHandler( "yo", function( plr, cmd, ... )
-- Check if there is no timer for the player.
	if not isTimer( pTimer[plr] ) then 
		-- Create a timer of 5 seconds for the player and put it int the table.
		pTimer[plr] = setTimer(function() pTimer[plr]=nil end,5000,1)
		-- Execute code
		outputChatBox( "All good bro B)")
	else
		outputChatBox( "Pls chill. You used this less than 5 seconds ago.")
	end
end )

 

Link to comment

Your title does say "getTickCount" so I'm just gonna throw this in there even though setTimer works too.. :P

For client you can use variables rather than tables so name your variables:

local limit_armor, limit_health

Then apply them to the code

elseif source == can then
        if getPlayerMoney() >= 5000 then
            if getElementHealth(localPlayer) ~= 100 then
                if (limit_health) and (getTickCount()-limit_health < 300000) then outputChatBox("You need to wait 5 minutes before using this again...", 255, 0, 0) return end
                limit_health = getTickCount()
                setElementHealth(localPlayer,100)
                triggerServerEvent("TakeMoney",localPlayer)
                outputChatBox("#888888 5000$ #FFFFFFkarşılığında canın dolduruldu!",0,255,0,true)
            else
                outputChatBox("Canın zaten dolu!",255,0,0,true)
            end
        else
            outputChatBox("Paran yetmiyor!",255,0,0,true)
        end
        setTimer(guiSetPosition,50,5,canimg,g-132,2,false)
        setTimer(guiSetPosition,60,5,canimg,g-128,1,false)
elseif source == zirh then
        if getPlayerMoney() >= 5000 then
            if getPedArmor(localPlayer) ~= 100 then
                if (limit_armor) and (getTickCount()-limit_armor < 300000) then outputChatBox("You need to wait 5 minutes before using this again...", 255, 0, 0) return end
                limit_armor = getTickCount()
                triggerServerEvent("setPlayerArmor",localPlayer)
                outputChatBox("#888888 5000$ #FFFFFFkarşılığında çelik yelek giydin!",0,255,0,true)
            else
                outputChatBox("Çelik yeleğin zaten sağlam!",255,0,0,true)
            end
        else
            outputChatBox("Paran yetmiyor!",255,0,0,true)
        end
        setTimer(guiSetPosition,50,5,zirhimg,g-132,2,false)
        setTimer(guiSetPosition,60,5,zirhimg,g-128,1,false)
	

If you need to use the same technique server sided, you'll need tables, which would look like this:

		
local limit = {
	armor = {},
	health = {},
}		
if (limit.armor[thePlayer]) and (getTickCount()-limit.armor[thePlayer] < 300000) then outputChatBox("You need to wait 5 minutes before using this again...", thePlayer, 255, 0, 0) return end
limit.armor[thePlayer] = getTickCount()		
if (limit.health[thePlayer]) and (getTickCount()-limit.health[thePlayer] < 300000) then outputChatBox("You need to wait 5 minutes before using this again...", thePlayer, 255, 0, 0) return end
limit.health[thePlayer] = getTickCount()		
		

 

Edited by Ab-47
Link to comment

 

http://prntscr.com/mwx0eq

http://prntscr.com/mwx0rf

how to problem fix? 

@Ab-47 @Mr.Loki

 

elseif source == can then
        if getPlayerMoney() >= 5000 then
            if getElementHealth(localPlayer) ~= 100 then
                if (limit_health) and (getTickCount()-limit_health < 300000) then outputChatBox("You need to wait 5 minutes before using this again...", 255, 0, 0) return end
                limit_health = getTickCount()
                setElementHealth(localPlayer,100)
                triggerServerEvent("TakeMoney",localPlayer)
                outputChatBox("#888888 5000$ #FFFFFFkarşılığında canın dolduruldu!",0,255,0,true)
            else
                outputChatBox("Canın zaten dolu!",255,0,0,true)
            end
        else
            outputChatBox("Paran yetmiyor!",255,0,0,true)
        end
        setTimer(guiSetPosition,50,5,canimg,g-132,2,false)
        setTimer(guiSetPosition,60,5,canimg,g-128,1,false)
elseif source == zirh then
        if getPlayerMoney() >= 5000 then
            if getPedArmor(localPlayer) ~= 100 then
                if (limit_armor) and (getTickCount()-limit_armor < 300000) then outputChatBox("You need to wait 5 minutes before using this again...", 255, 0, 0) return end
                limit_armor = getTickCount()
                triggerServerEvent("setPlayerArmor",localPlayer)
                outputChatBox("#888888 5000$ #FFFFFFkarşılığında çelik yelek giydin!",0,255,0,true)
            else
                outputChatBox("Çelik yeleğin zaten sağlam!",255,0,0,true)
            end
        else
            outputChatBox("Paran yetmiyor!",255,0,0,true)
        end
        setTimer(guiSetPosition,50,5,zirhimg,g-132,2,false)
        setTimer(guiSetPosition,60,5,zirhimg,g-128,1,false)

 

Link to comment

Test it please example

elseif source == can then
		if getTickCount() < (__FIRST_TICK_DELAY or 0) then
			return outputChatBox("please wait!", 0, 255, 0, true)
		end
		if getPlayerMoney() >= 5000 then
			if getElementHealth(localPlayer) ~= 100 then
				setElementHealth(localPlayer,100)
				triggerServerEvent("TakeMoney",localPlayer)
				outputChatBox("#888888 5000$ #FFFFFFkarşılığında canın dolduruldu!",0,255,0,true)
				__FIRST_TICK_DELAY = getTickCount() + 500 -- timed out (delay)
			else
				outputChatBox("Canın zaten dolu!",255,0,0,true)
			end
		else
			outputChatBox("Paran yetmiyor!",255,0,0,true)
		end
		setTimer(guiSetPosition,50,5,canimg,g-132,2,false)
		setTimer(guiSetPosition,60,5,canimg,g-128,1,false)

and rewrite the code manually, can sometimes give errors that there is some kind of symbol (but visually it is not visible). I got from this rofl when I copied my own, the lost code from here

Link to comment
7 hours ago, queenshe said:

 

http://prntscr.com/mwx0eq

http://prntscr.com/mwx0rf

how to problem fix? 

@Ab-47 @Mr.Loki

 


elseif source == can then
        if getPlayerMoney() >= 5000 then
            if getElementHealth(localPlayer) ~= 100 then
                if (limit_health) and (getTickCount()-limit_health < 300000) then outputChatBox("You need to wait 5 minutes before using this again...", 255, 0, 0) return end
                limit_health = getTickCount()
                setElementHealth(localPlayer,100)
                triggerServerEvent("TakeMoney",localPlayer)
                outputChatBox("#888888 5000$ #FFFFFFkarşılığında canın dolduruldu!",0,255,0,true)
            else
                outputChatBox("Canın zaten dolu!",255,0,0,true)
            end
        else
            outputChatBox("Paran yetmiyor!",255,0,0,true)
        end
        setTimer(guiSetPosition,50,5,canimg,g-132,2,false)
        setTimer(guiSetPosition,60,5,canimg,g-128,1,false)
elseif source == zirh then
        if getPlayerMoney() >= 5000 then
            if getPedArmor(localPlayer) ~= 100 then
                if (limit_armor) and (getTickCount()-limit_armor < 300000) then outputChatBox("You need to wait 5 minutes before using this again...", 255, 0, 0) return end
                limit_armor = getTickCount()
                triggerServerEvent("setPlayerArmor",localPlayer)
                outputChatBox("#888888 5000$ #FFFFFFkarşılığında çelik yelek giydin!",0,255,0,true)
            else
                outputChatBox("Çelik yeleğin zaten sağlam!",255,0,0,true)
            end
        else
            outputChatBox("Paran yetmiyor!",255,0,0,true)
        end
        setTimer(guiSetPosition,50,5,zirhimg,g-132,2,false)
        setTimer(guiSetPosition,60,5,zirhimg,g-128,1,false)

 

I just figured out the illegal character thing as XasKel pointed out lol "then" is not actually "then", it has an invisible illegal character that the system can identify but not you, leading it to not be a correct statement.

I've created a workaround for your code for testing purposes and removed all the illegal characters, take the code from what I've pasted below and make sure you eliminate all the illegal characters. 

function checkWhatever(cmd, string)
    if string == "can" then
        if getPlayerMoney(localPlayer) >= 5000 then
            if getElementHealth(localPlayer) ~= 100 then
                if (limit_health) and (getTickCount()-limit_health < 300000) then outputChatBox("You need to wait 5 minutes before using this again...", 255, 0, 0) return end
                limit_health = getTickCount()
                setElementHealth(localPlayer,100)
                triggerServerEvent("TakeMoney",localPlayer)
                outputChatBox("#888888 5000$ #FFFFFFkarşılığında canın dolduruldu!",0,255,0,true)
            else
                outputChatBox("Canın zaten dolu!",255,0,0,true)
            end
        else
            outputChatBox("Paran yetmiyor!",255,0,0,true)
        end
        setTimer(guiSetPosition,50,5,canimg,g-132,2,false)
        setTimer(guiSetPosition,60,5,canimg,g-128,1,false)
    elseif string == "zrich" then
        if getPlayerMoney(localPlayer) >= 5000 then
            if getPedArmor(localPlayer) ~= 100 then
                if (limit_armor) and (getTickCount()-limit_armor < 300000) then outputChatBox("You need to wait 5 minutes before using this again...", 255, 0, 0) return end
                limit_armor = getTickCount()
                triggerServerEvent("setPlayerArmor",localPlayer)
                outputChatBox("#888888 5000$ #FFFFFFkarşılığında çelik yelek giydin!",0,255,0,true)
            else
                outputChatBox("Çelik yeleğin zaten sağlam!",255,0,0,true)
            end
        else
            outputChatBox("Paran yetmiyor!",255,0,0,true)
        end
        setTimer(guiSetPosition,50,5,zirhimg,g-132,2,false)
        setTimer(guiSetPosition,60,5,zirhimg,g-128,1,false)
    end
end
addCommandHandler("hello", checkWhatever)

Command: hello can or hello zrich, didn't know what either were so converted them to string to enter on the cmd. Make sure you change that back and the if to elseif to put back into your code. 

 

 

Edited by Ab-47
Link to comment

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