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
We would need to know what you are trying to do.How use this function in function onThink(interval, lastExecution)?
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
Because that is the interval you have set.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
..
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