• 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 TFS 1.2 !exit

Shadow Dan

Sh4dowDan
Joined
Jun 5, 2010
Messages
344
Reaction score
88
Location
Poland
Here is final script fully working and calculated.
Script made by RazorBlade, thank you.

To make exhaust working you need this:
talkactions/lib/talkactions.lua
Code:
function checkExhausted(cid, storage, seconds)
    local v = exhaustion.get(cid, storage)
    if(not v) then
        exhaustion.set(cid, storage, seconds)
    else
        doPlayerSendCancel(cid, "Please wait " .. v .. " seconds before use that command again.")
        return false
    end

    return true
end

talkactions/talkactions.xml
Code:
<talkaction words="!exit" separator=" " script="exit.lua"/>
talkactions/scripts/exit.lua
Code:
--script made by RazorBlade // otland.net
function onSay(player, words, param)
if(not checkExhausted(player, 777, 70)) then
    return false
end

    local time = 60 -- time before teleport
        if not player:getCondition(CONDITION_INFIGHT) then
            player:registerEvent("tpTimer")
            player:setStorageValue(10, os.time() + time)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You will be teleported in " .. time .. " seconds unless you enter battle.")
            return false
        else
            player:sendTextMessage(MESSAGE_STATUS_WARNING, "You cannot teleport while in battle!")
            return false
        end
    return true
end
creaturescripts/creaturescripts.xml
Code:
<event type="think" name="tpTimer" script="others/tptimer.lua" />
creaturescripts/scripts/tptimer.lua
Code:
--script made by RazorBlade // otland.net
function onThink(creature, interval)
    local player = Player(creature)
    if not Player(player) then
        return creature:unregisterEvent("tpTimer")
    end
    if player:getCondition(CONDITION_INFIGHT) then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You are in combat! Teleport failed.")
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You can't teleport while in combat.")
        return player:unregisterEvent("tpTimer")
    end
    if player:getStorageValue(10) < os.time() then
        player:setStorageValue(10, -1)
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        player:teleportTo(player:getTown():getTemplePosition())
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        return player:unregisterEvent("tpTimer")
    end
    local remaining = math.ceil(player:getStorageValue(10) - os.time())
    player:sendTextMessage(MESSAGE_STATUS_SMALL, "Time before teleport: "..remaining..".")
    return true
end
 
Last edited:
Its perfect, had small math mistakes but its really great.
Your cooldown based on storage and os.time was a mistake because it gives values like 4323749748 and impossible to specify so i used my exhaust which works even after you relog etc.

Here is final script fully working and calculated.

To make exhaust working you need this:
talkactions/lib/talkactions.lua
Code:
function checkExhausted(cid, storage, seconds)
    local v = exhaustion.get(cid, storage)
    if(not v) then
        exhaustion.set(cid, storage, seconds)
    else
        doPlayerSendCancel(cid, "Please wait " .. v .. " seconds before use that command again.")
        return false
    end

    return true
end

talkactions/talkactions.xml
Code:
<talkaction words="!exit" separator=" " script="exit.lua"/>
talkactions/scripts/exit.lua
Code:
function onSay(player, words, param)
if(not checkExhausted(player, 777, 70)) then
    return false
end

    local time = 60 -- time before teleport
        if not player:getCondition(CONDITION_INFIGHT) then
            player:registerEvent("tpTimer")
            player:setStorageValue(10, os.time() + time)
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You will be teleported in " .. time .. " seconds unless you enter battle.")
            return false
        else
            player:sendTextMessage(MESSAGE_STATUS_WARNING, "You cannot teleport while in battle!")
            return false
        end
    return true
end
creaturescripts/creaturescripts.xml
Code:
<event type="think" name="tpTimer" script="others/tptimer.lua" />
creaturescripts/scripts/tptimer.lua
Code:
function onThink(creature, interval)
    local player = Player(creature)
    if not Player(player) then
        return creature:unregisterEvent("tpTimer")
    end
    if player:getCondition(CONDITION_INFIGHT) then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You are in combat! Teleport failed.")
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You can't teleport while in combat.")
        return player:unregisterEvent("tpTimer")
    end
    if player:getStorageValue(10) < os.time() then
        player:setStorageValue(10, -1)
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        player:teleportTo(player:getTown():getTemplePosition())
        player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        return player:unregisterEvent("tpTimer")
    end
    local remaining = math.ceil(player:getStorageValue(10) - os.time())
    player:sendTextMessage(MESSAGE_STATUS_SMALL, "Time before teleport: "..remaining..".")
    return true
end
 
4323749748 is a timestamp in milliseconds. If you add 60000 to it, that's one minute in the future. Checking if os.time() is > that storage means it's past the old time + 60 seconds.
 
When i tested with 5 seconds i couldn't use this script. Used my test script to see what actual storage is and it was long line of numbers. Easier is to setup with
checkExhausted function, very simple for me and global function.
 
Back
Top