• 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:
Easy. Whenever you have cid, you will now receive a player metatable. You can change, for instance:
Code:
getCreaturePosition(cid)
for:
Code:
player:getPosition()
Just rename cid to player in the parameters.

That's the pattern. Good luck!
 
Looks like i must try milion times till i finish it because nobody care and you say only obvious things.
I know functions and how to change cid to player. It's not the problem.
Maybe if i use check player and something like stopEvent(event) when false server will not crash after logout while counting.
 
Looks like i must try milion times till i finish it because nobody care and you say only obvious things.
I know functions and how to change cid to player. It's not the problem.
Maybe if i use check player and something like stopEvent(event) when false server will not crash after logout while counting.

Any solution? =(
 
Code:
local tele_time = 60 -- time before teleport
local tmp_storage = 40101

function onSay(cid, words, param, channel)
    if getPlayerStorageValue(cid, tmp_storage) >= 1 then
        doPlayerSendCancel(cid, "You can only use this once every 60 seconds.")
    return true
    end

    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendCancel(cid, "You cannot teleport while in combat.")
    return true
    end
   
    setPlayerStorageValue(cid, tmp_storage, 1)
    addEvent(count, 0, cid)

    return true
end

function count(cid)
if getPlayerStorageValue(cid, temp_storage) ~= tele_time + 1 then
setPlayerStorageValue(cid, tmp_storage + 1)
doCreatureSay(cid, getPlayerStorageValue(cid, tmp_storage), TALKTYPE_ORANGE_1)
addEvent(count, 1000, cid)
else
addEvent(teleportPlayer, 0, cid)
end
end


function teleportPlayer(cid)
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doCreatureSay(cid,"You are in combat! Teleport failed.",TALKTYPE_ORANGE_1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You can't teleport while in combat.")
    else
        local tmp = getPlayerTown(cid)
        local pos = getTownTemplePosition(tmp, false)

        if(doTeleportThing(cid, pos) and not isPlayerGhost(cid)) then
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
        end
    end
end
 
Script is working but always crash when log out while timer is counting.

And if no log out there is no crash but this error, script is working.
Code:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
LuaScriptInterface::luaAddEvent(). callback parameter should be a function.
stack traceback:
        [C]: in function 'addEvent'
        data/talkactions/scripts/exit.lua:16: in function 'stop'
        data/talkactions/scripts/exit.lua:40: in function <data/talkactions/scripts/exit.lua:34>
Code:
function onSay(player, words, param, channel)
if(not checkExhausted(player, 555, 5)) then
    return true
end
local c = player:getGroup():getId()
    if c ~= 4 then
        return true
    end
    if not player then
        return
    end
   
local czas = 5 -- time before teleport

function stop()
    addEvent(player:sendCancelMessage("Time before teleport: 0."),150)
    addEvent(teleport,1000)
end

function teleport()
    if player:getCondition(CONDITION_INFIGHT) then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You can't teleport while in combat.")
    else
        local tmp = player:getTown()
        local pos = player:getTown():getTemplePosition()

        if player:teleportTo(pos) and not player:isInGhostMode() then
            doSendMagicEffect(tmp, CONST_ME_POFF)
            doSendMagicEffect(pos, CONST_ME_TELEPORT)
        end
    end
end
   
function minusTime()
    if czas > 0 then
        player:sendCancelMessage("Time before teleport: "..czas..".")
        czas = czas - 1
        addEvent(minusTime,1000)
    elseif czas == 0 then
    stop()
    end
end
    minusTime()
    return false
end
 
Code:
local tele_time = 60 -- time before teleport
local tmp_storage = 40101

function onSay(cid, words, param, channel)
    if getPlayerStorageValue(cid, tmp_storage) >= 1 then
        doPlayerSendCancel(cid, "You can only use this once every 60 seconds.")
    return true
    end

    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendCancel(cid, "You cannot teleport while in combat.")
    return true
    end
   
    setPlayerStorageValue(cid, tmp_storage, 1)
    addEvent(count, 0, cid)

    return true
end

function count(cid)
if not isPlayer(cid) then
stopEvent(count)
end
if getPlayerStorageValue(cid, temp_storage) ~= tele_time + 1 then
setPlayerStorageValue(cid, tmp_storage + 1)
doCreatureSay(cid, getPlayerStorageValue(cid, tmp_storage), TALKTYPE_ORANGE_1)
addEvent(count, 1000, cid)
else
addEvent(teleportPlayer, 0, cid)
end
end


function teleportPlayer(cid)
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doCreatureSay(cid,"You are in combat! Teleport failed.",TALKTYPE_ORANGE_1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You can't teleport while in combat.")
    else
        local tmp = getPlayerTown(cid)
        local pos = getTownTemplePosition(tmp, false)

        if(doTeleportThing(cid, pos) and not isPlayerGhost(cid)) then
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
        end
    end
end


try this
 
if it's just a timer, why don't you just set a storage value to os.time() + 60*1000 and use an onThink creaturescript to check the time? That way there are no addEvent functions and thus no crashing.
 
sorry i seen an error let me fix

Code:
local tele_time = 60 -- time before teleport
local tmp_storage = 40101

function onSay(cid, words, param, channel)
    if getPlayerStorageValue(cid, tmp_storage) >= 1 then
        doPlayerSendCancel(cid, "You can only use this once every 60 seconds.")
    return true
    end

    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doPlayerSendCancel(cid, "You cannot teleport while in combat.")
    return true
    end
   
    setPlayerStorageValue(cid, tmp_storage, 1)
    addEvent(count, 0, cid)

    return true
end

function count(cid)
if not isPlayer(cid) then
stopEvent(count)
end
if getPlayerStorageValue(cid, tmp_storage) ~= tele_time + 1 then
setPlayerStorageValue(cid, tmp_storage + 1)
doCreatureSay(cid, getPlayerStorageValue(cid, tmp_storage), TALKTYPE_ORANGE_1)
addEvent(count, 1000, cid)
else
addEvent(teleportPlayer, 0, cid)
end
end


function teleportPlayer(cid)
    if getCreatureCondition(cid, CONDITION_INFIGHT) then
        doCreatureSay(cid,"You are in combat! Teleport failed.",TALKTYPE_ORANGE_1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You can't teleport while in combat.")
    else
        local tmp = getPlayerTown(cid)
        local pos = getTownTemplePosition(tmp, false)

        if(doTeleportThing(cid, pos) and not isPlayerGhost(cid)) then
            doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
        end
    end
end
 
Last edited by a moderator:
still same, this not gonna work i see many mistakes in this script. Like
setPlayerStorageValue(cid, tmp_storage, 1)
or
if getPlayerStorageValue(cid, tmp_storage) >= 1 then
Mine script works but addevent cause crash when character is offline and i need to skip that.
 
Then add

Code:
if (not isPlayer(cid)) then
stopEvent(eventname)
end

at the begining of the event

it works on my distro though
 
Last edited by a moderator:
i checked that multiple times
example
if not player then
return true
end

event seem to be unstoppable on tfs 1.2 so i need to use something else than addevent.
 
I believe this should work. I've also taken the liberty of converting it all to metatables.
Talkaction:
Code:
function onSay(player, words, param)
    local time = 60 -- time before teleport
    if player:getStorageValue(10) < 0 or player:getStorageValue(10) + (time * 1000) < os.time() then
        if not player:getCondition(CONDITION_INFIGHT) then
            player:registerEvent("tpTimer")
            player:setStorageValue(10, os.time() + (time * 1000))
            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
    else
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You can only use this once every " .. time .." seconds.")
        return false
    end
    return true
end

Creaturescript:
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: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()) * 1000
    player:sendTextMessage(MESSAGE_STATUS_SMALL, "Time before teleport: "..remaining..".")
    return true
end

register the creaturescript in creaturescripts.xml as so:
Code:
<event type="think" name="tpTimer" script="tptimer.lua" />

Won't crash because it doesn't use addEvent.

Let me know how it goes.
 
Back
Top Bottom