if isInRange or Area

Discussion in 'Support' started by Adix910, Nov 10, 2018.

  1. Adix910

    Adix910 Banned User

    Joined:
    Aug 14, 2015
    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Hello, how to use if isInRange or Area on lua e.g select left top corner and right bottom corner?
     
  2. ruth

    ruth Active Member

    Joined:
    Aug 3, 2009
    Messages:
    447
    Likes Received:
    123
    Best Answers:
    2
    Code (Text):
    1. function isInArea(pos, fromPos, toPos)
    2.     if pos.x >= fromPos.x and pos.x <= toPos.x then
    3.         if pos.y >= fromPos.y and pos.y <= toPos.y then
    4.             if pos.z >= fromPos.z and pos.z <= toPos.z then
    5.                 return true
    6.             end
    7.         end
    8.     end
    9.     return false
    10. end
     
  3. Adix910

    Adix910 Banned User

    Joined:
    Aug 14, 2015
    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    How use this function in function onThink(interval, lastExecution)?
     
  4. Xikini

    Xikini I whore myself out for likes

    Joined:
    Nov 17, 2010
    Messages:
    3,766
    Likes Received:
    1,977
    Best Answers:
    108
    We would need to know what you are trying to do.
     
  5. Adix910

    Adix910 Banned User

    Joined:
    Aug 14, 2015
    Messages:
    24
    Likes Received:
    0
    Best Answers:
    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"/>
     
  6. sick7

    sick7 Relentless

    Joined:
    Apr 3, 2011
    Messages:
    249
    Likes Received:
    33
    Best Answers:
    1
    put the function ruth posted in one of your libs if you don't have it yet

    Code (Lua):
    1. local area = {
    2.     tl = {x = 32364, y = 32187, z = 7},
    3.     br = {x = 32369, y = 32190, z = 7}
    4. }
    5.  
    6. function onThink(interval, lastExecution)
    7.     for _, cid in pairs(getPlayersOnline()) do
    8.         if isInArea(getPlayerPosition(cid), area.tl, area.br) then
    9.             doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "You today mission is: XXX")
    10.         end
    11.     end
    12.     return true
    13. end
     
  7. Adix910

    Adix910 Banned User

    Joined:
    Aug 14, 2015
    Messages:
    24
    Likes Received:
    0
    Best Answers:
    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
    ..
     
  8. Xikini

    Xikini I whore myself out for likes

    Joined:
    Nov 17, 2010
    Messages:
    3,766
    Likes Received:
    1,977
    Best Answers:
    108
    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.

    Code (Lua):
    1. local area = {
    2.     tl = {x = 32364, y = 32187, z = 7},
    3.     br = {x = 32369, y = 32190, z = 7}
    4. }
    5.  
    6. local received_message = {}
    7. function onThink(interval, lastExecution)
    8.     for _, cid in pairs(getPlayersOnline()) do
    9.         if not received_message[cid] then
    10.             if isInArea(getPlayerPosition(cid), area.tl, area.br) then
    11.                 doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, "You today mission is: XXX")
    12.                 received_message[cid] = 1
    13.             end
    14.         end
    15.     end
    16.     return true
    17. end
     
    Last edited: Nov 11, 2018
    GhostWD likes this.

Share This Page

Loading...