• Minor technical glitch has been resolved. Logging in and posting is now possible again!
  • Congratulations to new Staff Members on their promotion!

if isInRange or Area

Adix910

New Member
Joined
Aug 14, 2015
Messages
24
Best answers
0
Reaction score
0
Hello, how to use if isInRange or Area on lua e.g select left top corner and right bottom corner?
 

ruth

Excellent OT User
Joined
Aug 3, 2009
Messages
554
Best answers
2
Reaction score
230
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
 
OP
A

Adix910

New Member
Joined
Aug 14, 2015
Messages
24
Best answers
0
Reaction score
0
How use this function in function onThink(interval, lastExecution)?
 

Xikini

I whore myself out for likes
Premium User
Joined
Nov 17, 2010
Messages
4,131
Best answers
164
Reaction score
2,201
OP
A

Adix910

New Member
Joined
Aug 14, 2015
Messages
24
Best answers
0
Reaction score
0
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
276
Best answers
5
Reaction score
36
Location
South Korea
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
 
OP
A

Adix910

New Member
Joined
Aug 14, 2015
Messages
24
Best answers
0
Reaction score
0
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
Premium User
Joined
Nov 17, 2010
Messages
4,131
Best answers
164
Reaction score
2,201
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