• 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 [0.X]Temple TP Script

potinho

Advanced OT User
Joined
Oct 11, 2009
Messages
1,403
Solutions
17
Reaction score
151
Location
Brazil
Hello guys,

I have this teleport script to the temple, but I would like to improve it:

  • cooldown (in hours)
  • put message on screen when using
  • Item disappears when used


can you help me?

Lua:
function onUse(cid, item, frompos, item2, topos)
ppos = getPlayerPosition(cid)
temple = getPlayerMasterPos(cid)
if (getCreatureCondition(cid, CONDITION_INFIGHT) == FALSE) then
doTeleportThing(cid, temple, TRUE)
doSendMagicEffect(ppos,66)
doSendAnimatedText(frompos,'Teleport!',16)
else
doPlayerSendCancel(cid,"You can't teleport immediately after fight.")
doSendMagicEffect(ppos,2)
end
return 1
end
 
Solution
Lua:
local config = {
    storage = 999999,
    time = 120, -- minutes
    removeOnUse = true,
    messageType = MESSAGE_INFO_DESCR
}
function onUse(cid, item, frompos, item2, topos)
    local time = getPlayerStorageValue(cid, config.storage) - os.time()
    if time > 0 then
        return doPlayerSendTextMessage(cid, config.messageType, "Wait " .. getTimeString(time) .. " to be able to use this item again.")
    end
    if (getCreatureCondition(cid, CONDITION_INFIGHT) == true) then
        doSendMagicEffect(getThingPosition(cid), CONST_ME_POFF)
        return doPlayerSendCancel(cid, "You can\'t teleport immediately after fight.")
    end
    if config.removeOnUse then
        doRemoveItem(item.uid, 1)
    end...
Lua:
local config = {
    storage = 999999,
    time = 120, -- minutes
    removeOnUse = true,
    messageType = MESSAGE_INFO_DESCR
}
function onUse(cid, item, frompos, item2, topos)
    local time = getPlayerStorageValue(cid, config.storage) - os.time()
    if time > 0 then
        return doPlayerSendTextMessage(cid, config.messageType, "Wait " .. getTimeString(time) .. " to be able to use this item again.")
    end
    if (getCreatureCondition(cid, CONDITION_INFIGHT) == true) then
        doSendMagicEffect(getThingPosition(cid), CONST_ME_POFF)
        return doPlayerSendCancel(cid, "You can\'t teleport immediately after fight.")
    end
    if config.removeOnUse then
        doRemoveItem(item.uid, 1)
    end
    doSendMagicEffect(getThingPosition(cid), CONST_ME_POFF)
    doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
    doSendMagicEffect(getThingPosition(cid), 66)
    doSendAnimatedText(getThingPosition(cid), 'Teleport!', 16)
    setPlayerStorageValue(cid, config.storage, os.time() + config.time * 60)
    return true
end

function getTimeString(self)
    local format = {
        {'day', self / 60 / 60 / 24},
        {'hour', self / 60 / 60 % 24},
        {'minute', self / 60 % 60},
        {'second', self % 60}
    }
    
    local out = {}
    for k, t in ipairs(format) do
        local v = math.floor(t[2])
        if(v > 0) then
            table.insert(out, (k < #format and (#out > 0 and ', ' or '') or ' and ') .. v .. ' ' .. t[1] .. (v ~= 1 and 's' or ''))
        end
    end
    local ret = table.concat(out)
    if ret:len() < 16 and ret:find('second') then
        local a, b = ret:find(' and ')
        ret = ret:sub(b+1)
    end
    return ret
end
 
Solution
Lua:
local config = {
    storage = 999999,
    time = 120, -- minutes
    removeOnUse = true,
    messageType = MESSAGE_INFO_DESCR
}
function onUse(cid, item, frompos, item2, topos)
    local time = getPlayerStorageValue(cid, config.storage) - os.time()
    if time > 0 then
        return doPlayerSendTextMessage(cid, config.messageType, "Wait " .. getTimeString(time) .. " to be able to use this item again.")
    end
    if (getCreatureCondition(cid, CONDITION_INFIGHT) == true) then
        doSendMagicEffect(getThingPosition(cid), CONST_ME_POFF)
        return doPlayerSendCancel(cid, "You can\'t teleport immediately after fight.")
    end
    if config.removeOnUse then
        doRemoveItem(item.uid, 1)
    end
    doSendMagicEffect(getThingPosition(cid), CONST_ME_POFF)
    doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
    doSendMagicEffect(getThingPosition(cid), 66)
    doSendAnimatedText(getThingPosition(cid), 'Teleport!', 16)
    setPlayerStorageValue(cid, config.storage, os.time() + config.time * 60)
    return true
end

function getTimeString(self)
    local format = {
        {'day', self / 60 / 60 / 24},
        {'hour', self / 60 / 60 % 24},
        {'minute', self / 60 % 60},
        {'second', self % 60}
    }
   
    local out = {}
    for k, t in ipairs(format) do
        local v = math.floor(t[2])
        if(v > 0) then
            table.insert(out, (k < #format and (#out > 0 and ', ' or '') or ' and ') .. v .. ' ' .. t[1] .. (v ~= 1 and 's' or ''))
        end
    end
    local ret = table.concat(out)
    if ret:len() < 16 and ret:find('second') then
        local a, b = ret:find(' and ')
        ret = ret:sub(b+1)
    end
    return ret
end
amazing Alberto, thanks
 
Back
Top