• 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!

if isInRange or Area

Adix910

New Member
Joined
Aug 14, 2015
Messages
37
Reaction score
1
Hello, how to use if isInRange or Area on lua e.g select left top corner and right bottom corner?
 
Code:
function isInArea(pos, fromPos, toPos)
    if pos.x >= fromPos.x and pos.x <= toPos.x then
        if pos.y >= fromPos.y and pos.y <= toPos.y then
            if pos.z >= fromPos.z and pos.z <= toPos.z then
                return true
            end
        end
    end
    return false
end
 
I want so that if the condition is fulfilled, it will display a message once.

function onThink(interval, lastExecution)
for _, name in ipairs(getOnlinePlayers()) do
local cid = getPlayerByName(name)
if(isInRange(getThingPos(cid), config.fromPos, config.toPos)) then
doPlayerSendTextMessage(cid, 19, "You today mission is: XXX")

<globalevent name="message" interval="2000" event="script" value="messages.lua"/>
 
put the function ruth posted in one of your libs if you don't have it yet

Lua:
local area = {
    tl = {x = 32364, y = 32187, z = 7},
    br = {x = 32369, y = 32190, z = 7}
}

function onThink(interval, lastExecution)
    for _, cid in pairs(getPlayersOnline()) do
        if isInArea(getPlayerPosition(cid), area.tl, area.br) then
            doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "You today mission is: XXX")
        end
    end
    return true
end
 
Thanks but I have spam messages every 2 seconds

22:45 You today mission is: XXX
22:45 You today mission is: XXX
22:45 You today mission is: XXX
..
 
Thanks but I have spam messages every 2 seconds

22:45 You today mission is: XXX
22:45 You today mission is: XXX
22:45 You today mission is: XXX
..
Because that is the interval you have set.
The code above was to show you how to use the function you were asking about.

If you want something different to happen, you'll want to add more code. xP

For example,
This edit would show the message to each player only once per server save.

Lua:
local area = {
    tl = {x = 32364, y = 32187, z = 7},
    br = {x = 32369, y = 32190, z = 7}
}

local received_message = {}
function onThink(interval, lastExecution)
    for _, cid in pairs(getPlayersOnline()) do
        if not received_message[cid] then
            if isInArea(getPlayerPosition(cid), area.tl, area.br) then
                doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "You today mission is: XXX")
                received_message[cid] = 1
            end
        end
    end
    return true
end
 
Last edited:
Back
Top