• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Timer on Teleportscroll

mpa

Member
Joined
Oct 8, 2008
Messages
319
Reaction score
13
Location
Sweden
This timer on the teleportscroll isn't working. When I use it i only get the cancelmessage "You can only use this scroll once every hour."

What's wrong with the timer?
PHP:
function onUse(cid, item)
    local compareTime = 60 * 60 * 1000
    local scroll = 1959
    local currentValue = getPlayerStorageValue(cid, 9897)
    
    if currentValue == -1 then
        currentValue = os.time()
    end

    if hasCondition(cid, CONDITION_INFIGHT) == TRUE and item.itemid == scroll then
        doPlayerSendCancel(cid, "You may not use this scroll while in-fight!")
        return FALSE
    end

    if (os.time() - currentValue) >= compareTime and hasCondition(cid, CONDITION_INFIGHT) == FALSE and item.itemid == scroll then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)), FALSE)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
        doPlayerSendTextMessage(cid,19,"You have been teleported to your home town!")
        setPlayerStorageValue(cid, 9897, os.time())
    else
        doPlayerSendCancel(cid, "You can only use this scroll once every hour.")
end
return TRUE
end
 
PHP:
os.time() - currentValue >= compareTime
should be like
PHP:
os.time() >= compareTime + currentValue
 
PHP:
function onUse(cid, item)
    local compareTime = 60 * 60 * 1000
    local scroll = 1959
    local currentValue = getPlayerStorageValue(cid, 9897)
    
    if currentValue == -1 then
        currentValue = os.time()
    end

    if hasCondition(cid, CONDITION_INFIGHT) == TRUE and item.itemid == scroll then
        doPlayerSendCancel(cid, "You may not use this scroll while in-fight!")
        return FALSE
    end

    if os.time() >= compareTime + currentValue and hasCondition(cid, CONDITION_INFIGHT) == FALSE and item.itemid == scroll then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)), FALSE)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
        doPlayerSendTextMessage(cid,19,"You have been teleported to your home town!")
        setPlayerStorageValue(cid, 9897, os.time())
    else
        doPlayerSendCancel(cid, "You can only use this scroll once every hour.")
end
return TRUE
end

Still not working :(
 
Try adding this line:
PHP:
doPlayerSendTextMessage(cid, 24, os.time() .. " => " .. currentValue + compareTime)
below
PHP:
    if currentValue == -1 then
        currentValue = os.time()
    end
then show me the result, thank you
 
try adding this line:
PHP:
doplayersendtextmessage(cid, 24, os.time() .. " => " .. Currentvalue + comparetime)
below
PHP:
    if currentvalue == -1 then
        currentvalue = os.time()
    end
then show me the result, thank you

1233761914 => 1237361914
 
As you can see, the os.time() [first column] is not greater or equal to the player storage [second column], wait a few more minutes and see if it works.

@up

L0lzor if you continue doing that he'll get an entirely different script :eek:;) You will add this and this and this and this and this and this and this and then it's perfect... oh wait and this... Lo0ol kewll xD Let him figure that out himself? It's better for him to learn LUA better if he made the thing itself.. Like 'you should try to add a line what says like "..."'.. Would be better for him

No offence, macro~, I know you're a great scripter, just telling you this ^_^
Hehe, no offence taken. My line was basically just showing him the current timestamp in seconds and the player storage value. Not modifying the script in any way. ; )
 
@Up

Sorry for my post above.. Didn't know you wanted to test the script.. sorryyy

Rep for sorry

np :thumbup:


Is it possible to
Code:
doPlayerSendTextMessage(cid,19,"Cooldown remaining: xx minutes.")
?

btw: It's still not working..
Code:
1233762767 => 1237362767
 
Last edited:
Yeah it is indeed possible, try something like this.
PHP:
local minutes = (os.time() - (currentValue + compareTime)) / 60
 
Lmao, my math skills isn't the best to be honest. I'll give it a try later on as I am working on my upcoming AAC atm.
 
Lmao, my math skills isn't the best to be honest. I'll give it a try later on as I am working on my upcoming AAC atm.
Ok thanks! rep ++ :D




Can anyone else help me to get this to work?
This timer on the teleportscroll isn't working. When I use it i only get the cancelmessage "You can only use this scroll once every hour."

What's wrong with the timer?
PHP:
function onUse(cid, item)
    local compareTime = 60 * 60 * 1000
    local scroll = 1959
    local currentValue = getPlayerStorageValue(cid, 9897)
    
    if currentValue == -1 then
        currentValue = os.time()
    end

    if hasCondition(cid, CONDITION_INFIGHT) == TRUE and item.itemid == scroll then
        doPlayerSendCancel(cid, "You may not use this scroll while in-fight!")
        return FALSE
    end

    if (os.time() - currentValue) >= compareTime and hasCondition(cid, CONDITION_INFIGHT) == FALSE and item.itemid == scroll then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)), FALSE)
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
        doPlayerSendTextMessage(cid,19,"You have been teleported to your home town!")
        setPlayerStorageValue(cid, 9897, os.time())
    else
        doPlayerSendCancel(cid, "You can only use this scroll once every hour.")
end
return TRUE
end
 
PHP:
local compareTime = 60 * 60
local scroll = 1959
local currentValue = getPlayerStorageValue(cid, 9897)
if(currentValue ~= TRUE) then
    currentValue = os.time()
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if(hasCondition(cid, CONDITION_INFIGHT) == FALSE) then
		if(item.itemid == scroll) then
			if((os.time() - currentValue) >= compareTime) then
				doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)), FALSE)
				doPlayerSendTextMessage(cid, 19, "You have been teleported to your home town!")
				setPlayerStorageValue(cid, 9897, os.time())
			else
				doPlayerSendCancel(cid, "You still have to wait " ..(os.time() - (currentValue + compareTime)).. " minutes to teleport to your home town again!")
			end
		end
	else
		doPlayerSendCancel(cid, "You can't teleport to your hometown during or shortly after a fight!")
	end
	return TRUE
end

I THINK this should work... Give it a try ^_^
 
PHP:
local compareTime = 60 * 60
local scroll = 1959
local currentValue = getPlayerStorageValue(cid, 9897)
if(currentValue ~= TRUE) then
    currentValue = os.time()
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(hasCondition(cid, CONDITION_INFIGHT) == FALSE) then
        if(item.itemid == scroll) then
            if((os.time() - currentValue) >= compareTime) then
                doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)), FALSE)
                doPlayerSendTextMessage(cid, 19, "You have been teleported to your home town!")
                setPlayerStorageValue(cid, 9897, os.time())
            else
                doPlayerSendCancel(cid, "You still have to wait " ..(os.time() - (currentValue + compareTime)).. " minutes to teleport to your home town again!")
            end
        end
    else
        doPlayerSendCancel(cid, "You can't teleport to your hometown during or shortly after a fight!")
    end
    return TRUE
end
I THINK this should work... Give it a try ^_^


It didn't work :(
I got "You still have to wait -60 minutes."

I don't understand how to add a timer to scripts :s
I need timer on other scripts aswell.
 
PHP:
local compareTime = 60 * 60
local scroll = 1959
local currentValue = getPlayerStorageValue(cid, 9897)
if(currentValue ~= TRUE) then
    currentValue = os.time()
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(hasCondition(cid, CONDITION_INFIGHT) == FALSE) then
        if(item.itemid == scroll) then
            if((os.time() - currentValue) >= compareTime) then
                doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)), FALSE)
                doPlayerSendTextMessage(cid, 19, "You have been teleported to your home town!")
                setPlayerStorageValue(cid, 9897, os.time())
            else
                doPlayerSendCancel(cid, "You still have to wait " ..(os.time() + compareTime).. " minutes to teleport to your home town again!")
            end
        end
    else
        doPlayerSendCancel(cid, "You can't teleport to your hometown during or shortly after a fight!")
    end
    return TRUE
end
 
PHP:
local compareTime = 60 * 60
local scroll = 1959
local currentValue = getPlayerStorageValue(cid, 9897)
if(currentValue ~= TRUE) then
    currentValue = os.time()
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(hasCondition(cid, CONDITION_INFIGHT) == FALSE) then
        if(item.itemid == scroll) then
            if((os.time() - currentValue) >= compareTime) then
                doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)), FALSE)
                doPlayerSendTextMessage(cid, 19, "You have been teleported to your home town!")
                setPlayerStorageValue(cid, 9897, os.time())
            else
                doPlayerSendCancel(cid, "You still have to wait " ..(os.time() + compareTime).. " minutes to teleport to your home town again!")
            end
        end
    else
        doPlayerSendCancel(cid, "You can't teleport to your hometown during or shortly after a fight!")
    end
    return TRUE
end

Don't work, any help ?
 
Back
Top