if isInRange or Area

Adix910

Banned User
Joined
Aug 14, 2015
Messages
24
Best answers
0
Likes
0
#1
Hello, how to use if isInRange or Area on lua e.g select left top corner and right bottom corner?
 

ruth

Active Member
Joined
Aug 3, 2009
Messages
502
Best answers
2
Likes
160
#2
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
 

Adix910

Banned User
Joined
Aug 14, 2015
Messages
24
Best answers
0
Likes
0
#5
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"/>
 

sick7

Relentless
Joined
Apr 3, 2011
Messages
262
Best answers
3
Likes
30
Location
South Korea
#6
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
 

Adix910

Banned User
Joined
Aug 14, 2015
Messages
24
Best answers
0
Likes
0
#7
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
..
 

Xikini

I whore myself out for likes
Joined
Nov 17, 2010
Messages
3,878
Best answers
122
Likes
2,010
#8
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:
Top