• 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 exit command

Lbtg

Advanced OT User
Joined
Nov 22, 2008
Messages
2,398
Reaction score
165
Hello is it posible to make if players is on area 111/111/1-999/999/12 players are able to use the command EXIT with teleports you back to main city or main pos

any help needed :p

edit:Tfs im using 0.3.6
 
Last edited:
if its TFS 1.x make talkaction !exit and write something like this:
Code:
local zone = {
    xS = 111,
    xE = 999,
    yS = 111,
    yE - 999,
    zS = 6,
    zE = 9,
}
function onSay()
local playerPos = player:getPosition()
   
    for x=zone.xS, zone.xE do
        for y=zone.yS, zone.yE do
            for z=zone.zS, zpne.zE do
                if comparePos(playerPos, {x=x, y=y, z=z}) then
                    return false, player:teleportTo(player:getTown():getTemplePosition())
                end
            end
        end
    end
return false
end
 
@whitevo That script looks really bad. It loops through every single SQM in configured range?

And isn't there already an inrange function?

This should be waaaaaaaay more efficient:
LUA:
local zone = {
    from = {x = 111, y = 111, z = 6}
    to = {x = 999, y = 999, z = 9}
}

-- Add function to global.lua to allow it to be used in other scripts as well.
function inrange(playerPos, zone)

    -- If player X position is between configured zone (from X) and (to X)
    if playerPos.x >= zone.from.x and playerPos.x <= zone.to.x then

        -- If player Y position is between configured zone (from Y) and (to Y)
        if playerPos.y >= zone.from.y and playerPos.y <= zone.to.y then

            -- If player Z position is between configured zone (from Z) and (to Z)
            if playerPos.z >= zone.from.z and playerPos.z <= zone.to.z then
                return true
            end -- Z
        end -- Y
    end -- X
    return false
end

function onSay()
    if inrange(player:getPosition(), zone) == true then
        player:teleportTo(player:getTown():getTemplePosition())
    end
    return false
    -- I think you can use return true here if you don't want chat to contain the talkaction word.
end
 
Last edited:
true, I just didn't think about it when I answered to this post xD
never needed to use isInRange in such way yet.
 
Forgot to mention 0.3.6 :( sorry guys :(

Replace the onSay function with this, think it should work with 0.3.6:
Code:
function onSay(cid)
    if inrange(getCreaturePosition(cid), zone) == true then
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
    end
    return false
    -- I think you can use return true here if you don't want chat to contain the talkaction word.
end

PS: Don't use 0.3.6.
 
Why dont use 0.3.6 if i could easily convert my server to 1,2 i would do that but most of the scripts wont work :(
 
well teted the script diferently , it doesnt work but im not getting any errors aswell i just say !exit and nothing happeens inside zone

talkactions
Code:
<talkaction words="!exit" value="exitas.lua"/>

script
Code:
local zone = {
    from = {x = 1003, y = 996, z = 7}
    to = {x = 1004, y = 997, z = 7}
}

-- Add function to global.lua to allow it to be used in other scripts as well.
function inrange(playerPos, zone)

    -- If player X position is between configured zone (from X) and (to X)
    if playerPos.x >= zone.from.x and playerPos.x <= zone.to.x then

        -- If player Y position is between configured zone (from Y) and (to Y)
        if playerPos.y >= zone.from.y and playerPos.y <= zone.to.y then

            -- If player Z position is between configured zone (from Z) and (to Z)
            if playerPos.z >= zone.from.z and playerPos.z <= zone.to.z then
                return true
            end -- Z
        end -- Y
    end -- X
    return false
end

function onSay(cid)
    if inrange(getCreaturePosition(cid), zone) == true then
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
    end
return true
end
 
No idea, try:

Code:
local config = {
    fromPosition = {x = 1003, y = 996, z = 7},
    toPosition = {x = 1004, y = 997, z = 7}
}

function onSay(cid, words, param)
    if isInRange(getCreaturePosition(cid), config.fromPosition, config.toPosition) then
        doTeleportThing(cid, getTownTemplePosition(getPlayerTown(cid)))
    end

    return true
end
 
Back
Top