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

Lua Problem with isInArea script.

Apoccalypse

New Member
Joined
Apr 15, 2017
Messages
114
Solutions
2
Reaction score
4
Hello guys,
I have the following script and it works perfectly:
(I am using tfs 0.3.6, client 8.6)

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)

local onePerQuest = "yes"

local npos = {x=329,  y=278,  z=11}
local areaPosition =
{
        {x=330, y=270, z=11, stackpos = 255},
        {x=344, y=286, z=11, stackpos = 255}
}
    
if item.uid == 9413 then
     
        if onePerQuest == "yes" then
                local players = getPlayersOnline()
                        for _, pid in ipairs(players) do
                        if isInArea(getCreaturePosition(pid), areaPosition[1], areaPosition[2]) then
                                doPlayerSendCancel(cid, "Wait until " .. getCreatureName(pid) .. " finish the quest.")
                                return true
                        end
                        end
                end
     
        doTeleportThing(cid, npos)
        doSendMagicEffect(npos,29)
        doPlayerSendTextMessage(cid, 21,"Congratulation! Don't forget to take a piece from the tomb!")


return true
end

end


I wanted to remake it to works when the defined boss is inside area instead of x player online.

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)



local npos = {x=329,  y=278,  z=11}
local areaPosition =
{
        {x=330, y=270, z=11, stackpos = 255},
        {x=344, y=286, z=11, stackpos = 255}
}

local boss1 = {
"Rahemos"
}
    
if item.uid == 9413 then
     
     
 for _, pid in ipairs(boss1) do
  if isInArea(getCreaturePosition(pid), areaPosition[1], areaPosition[2]) then
  doPlayerSendCancel(cid, "You have to kill Rahemos to eneter the tomb!")
   return true
     end
     end
             
     
        doTeleportThing(cid, npos)
        doSendMagicEffect(npos,29)
        doPlayerSendTextMessage(cid, 21,"Congratulation! Don't forget to take a piece from the tomb!")


return true
end

end

But the console returns an error:

Code:
[16:29:00.491] [Error - Action Interface]
[16:29:00.491] data/actions/scripts/Ancient Quest/AncientArea.lua:onUse
[16:29:00.491] Description:
[16:29:00.491] (luaGetThingPosition) Thing not found

[16:29:00.507] [Error - Action Interface]
[16:29:00.507] data/actions/scripts/Ancient Quest/AncientArea.lua:onUse
[16:29:00.507] Description:
[16:29:00.507] data/lib/032-position.lua:2: attempt to index local 'position' (a boolean value)
[16:29:00.507] stack traceback:
[16:29:00.522]  data/lib/032-position.lua:2: in function 'isInArea'
[16:29:00.522]  data/actions/scripts/Ancient Quest/AncientArea.lua:20: in function <data/actions/scripts/Ancient Quest/AncientArea.lua:1>

@The solution:

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
   local config = {
       item_uid = 9413,
       monster_name = "Rahemos",
       position = {x = 329, y = 278, z = 11},
       center_pos = {x = 330, y = 270, z = 11},
       effect = CONST_ANI_EARTH,
       cancel_message = "You have to kill Rahemos to enter the tomb!",
       congrat_message = "Congratulation! Don't forget to take a piece from the tomb!",
       rangeX = 10,
       rangeY = 10
   }
   if item.uid == config.item_uid then
       if getSpectators(config.center_pos, config.rangeX, config.rangeY) then
           for _, m in ipairs(getSpectators(config.center_pos, config.rangeX, config.rangeY)) do
               if isMonster(m) and string.lower(getCreatureName(m)) == string.lower(config.monster_name) then
                   doPlayerSendCancel(cid, config.cancel_message)
                   return true
               end
           end
           doTeleportThing(cid, config.position)
           doSendMagicEffect(config.position, config.effect)
           doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, config.congrat_message)
        end
   end
   return true
end
 
Last edited:
Solution
because you are inside and if getSpectators(config.center_pos, config.rangeX, config.rangeY) then that line is always executed

test this one

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
   local config = {
       item_uid = 9413,
       monster_name = "Rahemos",
       position = {x = 329, y = 278, z = 11},
       center_pos = {x = 330, y = 270, z = 11},
       effect = CONST_ANI_EARTH,
       cancel_message = "You have to kill Rahemos to enter the tomb!",
       congrat_message = "Congratulation! Don't forget to take a piece from the tomb!",
       rangeX = 10,
       rangeY = 10
   }
 
   if item.uid == config.item_uid then
       if getSpectators(config.center_pos, config.rangeX, config.rangeY) then
           for...
try changing
Lua:
if isInArea(getCreaturePosition(pid), areaPosition[1], areaPosition[2]) then
to
Lua:
if isPlayer(pid) and isInArea(getPlayerPosition(pid), areaPosition[1], areaPosition[2]) then
 
Hello guys,
I have the following script and it works perfectly:
(I am using tfs 0.3.6, client 8.6)

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)

local onePerQuest = "yes"

local npos = {x=329,  y=278,  z=11}
local areaPosition =
{
        {x=330, y=270, z=11, stackpos = 255},
        {x=344, y=286, z=11, stackpos = 255}
}
     
if item.uid == 9413 then
      
        if onePerQuest == "yes" then
                local players = getPlayersOnline()
                        for _, pid in ipairs(players) do
                        if isInArea(getCreaturePosition(pid), areaPosition[1], areaPosition[2]) then
                                doPlayerSendCancel(cid, "Wait until " .. getCreatureName(pid) .. " finish the quest.")
                                return true
                        end
                        end
                end
      
        doTeleportThing(cid, npos)
        doSendMagicEffect(npos,29)
        doPlayerSendTextMessage(cid, 21,"Congratulation! Don't forget to take a piece from the tomb!")


return true
end

end


I wanted to remake it to works when the defined boss is inside area instead of x player online.

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)



local npos = {x=329,  y=278,  z=11}
local areaPosition =
{
        {x=330, y=270, z=11, stackpos = 255},
        {x=344, y=286, z=11, stackpos = 255}
}

local boss1 = {
"Rahemos"
}
     
if item.uid == 9413 then
      
      
 for _, pid in ipairs(boss1) do
  if isInArea(getCreaturePosition(pid), areaPosition[1], areaPosition[2]) then
  doPlayerSendCancel(cid, "You have to kill Rahemos to eneter the tomb!")
   return true
     end
     end
              
      
        doTeleportThing(cid, npos)
        doSendMagicEffect(npos,29)
        doPlayerSendTextMessage(cid, 21,"Congratulation! Don't forget to take a piece from the tomb!")


return true
end

end

But the console returns an error:

Code:
[16:29:00.491] [Error - Action Interface]
[16:29:00.491] data/actions/scripts/Ancient Quest/AncientArea.lua:onUse
[16:29:00.491] Description:
[16:29:00.491] (luaGetThingPosition) Thing not found

[16:29:00.507] [Error - Action Interface]
[16:29:00.507] data/actions/scripts/Ancient Quest/AncientArea.lua:onUse
[16:29:00.507] Description:
[16:29:00.507] data/lib/032-position.lua:2: attempt to index local 'position' (a boolean value)
[16:29:00.507] stack traceback:
[16:29:00.522]  data/lib/032-position.lua:2: in function 'isInArea'
[16:29:00.522]  data/actions/scripts/Ancient Quest/AncientArea.lua:20: in function <data/actions/scripts/Ancient Quest/AncientArea.lua:1>

If anyone would take a look on it that would be great :)
Solved - isInArea not working (0.3.6)
 
No errors but does not work.
Player is teleported no matter that the boss is inside area.
The same for:
if isCreature(pid) and isInArea(getCreaturePosition(pid), areaPosition[1], areaPosition[2]) then


They used the function onpreparedeath which is unfortunately useless for me.
 
Last edited by a moderator:
maybe test this one.
Lua:
local bosses = {
    ["Rahemos"] = {
        centerPos = {x=330, y=270, z=11},
        npos = {x=329,  y=278,  z=11}
    }
}

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.uid == 9413 then
        for name, pos in pairs(bosses) do
            if isInArea(getCreatureName(name):lower(), pos.centerPos, 20, 20) then
                doPlayerSendCancel(cid, "You have to kill Rahemos to enter the tomb!")
                return true
            end
            doTeleportThing(cid, pos.npos)
            doSendMagicEffect(pos.npos, 29)
            doPlayerSendTextMessage(cid, 21, "Congratulation! Don't forget to take a piece from the tomb!")
        end
    return true
    end
end
 
The same error like at my first post.When I add :
isCreature(pid) and (...)
then no errors but player is teleported no matter that the boss is inside again :(
 
StreamSide I think that the issue with getting monster id is done but for some reason there is still a problem with the area:
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)



local npos = {x=329,  y=278,  z=11}
local tele = {
        a = {x=330, y=270, z=11},
        b = {x=344, y=286, z=11}
        }
 
if item.uid == 9413 then
      
      

                      
                        if isCreature(getCreatureByName("Rahemos")) and isInArea(getCreatureByName("Rahemos"), tele.a, tele.b) then
                                doPlayerSendCancel(cid, "You have to kill Rahemos to eneter the tomb!")
                                return true
                        end
                      
              
      
        doTeleportThing(cid, npos)
        doSendMagicEffect(npos,29)
        doPlayerSendTextMessage(cid, 21,"Congratulation! Don't forget to take a piece from the tomb!")


return true
end

end

And the error:
Code:
[18:42:45.318] [Error - Action Interface]
[18:42:45.333] data/actions/scripts/Ancient Quest/AncientArea.lua:onUse
[18:42:45.333] Description:
[18:42:45.333] data/lib/032-position.lua:2: attempt to index local 'position' (a number value)
[18:42:45.333] stack traceback:
[18:42:45.333]  data/lib/032-position.lua:2: in function 'isInArea'
[18:42:45.333]  data/actions/scripts/Ancient Quest/AncientArea.lua:17: in function <data/actions/scripts/Ancient Quest/AncientArea.lua:1>
 
welp test this one

Lua:
function checkAreaUid(pos, area, showP, showM) -- By Wantedzin(Perdigs)
    local creaturesList = {}
    local center = {}
    center.y = math.floor(#area/2)+1
    for y = 1, #area do
        for x = 1, #area[y] do
            local number = area[y][x]
            if number > 0 then
                center.x = math.floor(table.getn(area[y])/2)+1
                local pos =  getTopCreature {x = pos.x + x - center.x, y = pos.y + y - center.y, z = pos.z, stackpos = STACKPOS_TOP_CREATURE}
                if (pos.type == 1 and showP == 1) or (pos.type == 2 and showM == 1) then
                table.insert(creaturesList, pos.uid)
                end
            end
        end
    end
    return creaturesList
end

local centerPos, nPos = {x=330, y=270, z=11}, {x=329,  y=278,  z=11}
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.uid == 9413 then
        local area = checkAreaUid(centerPos, 10, false, true)
        for i = 1, #area do
            if getCreatureName(area[i]):lower() == "Rahemos" then
                doPlayerSendCancel(cid, "You have to kill Rahemos to enter the tomb!")
                return true
            end
            break
        end
        doTeleportThing(cid, nPos)
        doSendMagicEffect(nPos, 29)
        doPlayerSendTextMessage(cid, 21, "Congratulation! Don't forget to take a piece from the tomb!")
    end
    return true
end
 
Code:
[19:40:24.422] [Error - Action Interface]
[19:40:24.422] data/actions/scripts/Ancient Quest/AncientArea.lua:onUse
[19:40:24.422] Description:
[19:40:24.422] data/actions/scripts/Ancient Quest/AncientArea.lua:4: attempt to get length of local 'area' (a number value)
[19:40:24.422] stack traceback:
[19:40:24.422]  data/actions/scripts/Ancient Quest/AncientArea.lua:4: in function 'checkAreaUid'
[19:40:24.422]  data/actions/scripts/Ancient Quest/AncientArea.lua:23: in function <data/actions/scripts/Ancient Quest/AncientArea.lua:21>

I think it can work but we have to correct the line 4.
 
Move this:
Code:
local centerPos, nPos = {x=330, y=270, z=11}, {x=329,  y=278,  z=11}
under this:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
 
function checkAreaUid(pos, area, showP, showM) -- By Wantedzin(Perdigs)
local creaturesList = {}
local center = {}
center.y = math.floor(#area/2)+1
for y = 1, #area do
for x = 1, #area[y] do
local number = area[y][x]
if number > 0 then
center.x = math.floor(table.getn(area[y])/2)+1
local pos = getTopCreature {x = pos.x + x - center.x, y = pos.y + y - center.y, z = pos.z, stackpos = STACKPOS_TOP_CREATURE}
if (pos.type == 1 and showP == 1) or (pos.type == 2 and showM == 1) then
table.insert(creaturesList, pos.uid)
end
end
end
end
return creaturesList
end


function onUse(cid, item, fromPosition, itemEx, toPosition)
if item.uid == 9413 then

local centerPos, nPos = {x=330, y=270, z=11}, {x=329, y=278, z=11}
print(checkAreaUid(centerPos, 10, false, true))
local area = checkAreaUid(centerPos, 10, false, true)
for i = 1, #area do
if getCreatureName(area):lower() == "Rahemos" then
doPlayerSendCancel(cid, "You have to kill Rahemos to enter the tomb!")
return true
end
break
end
doTeleportThing(cid, nPos)
doSendMagicEffect(nPos, 29)
doPlayerSendTextMessage(cid, 21, "Congratulation! Don't forget to take a piece from the tomb!")
end
return true
end


Code:
[20:4:28.175] [Error - Action Interface]
[20:4:28.182] data/actions/scripts/Ancient Quest/AncientArea.lua:onUse
[20:4:28.183] Description:
[20:4:28.184] data/actions/scripts/Ancient Quest/AncientArea.lua:4: attempt to get length of local 'area' (a number value)
[20:4:28.185] stack traceback:
[20:4:28.186]   data/actions/scripts/Ancient Quest/AncientArea.lua:4: in function 'checkAreaUid'
[20:4:28.189]   data/actions/scripts/Ancient Quest/AncientArea.lua:25: in function <data/actions/scripts/Ancient Quest/AncientArea.lua:21>
 
Try this one:
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
   local config = {
       item_uid = 9413,
       monster_name = "Rahemos",
       position = {x = 329, y = 278, z = 11},
       center_pos = {x = 330, y = 270, z = 11},
       effect = CONST_ANI_EARTH,
       cancel_message = "You have to kill Rahemos to enter the tomb!",
       congrat_message = "Congratulation! Don't forget to take a piece from the tomb!",
       rangeX = 10,
       rangeY = 10
   }
   
   if item.uid == config.item_uid then
       if getSpectators(config.center_pos, config.rangeX, config.rangeY) then
           for _, m in ipairs(getSpectators(config.center_pos, config.rangeX, config.rangeY)) do
               if isMonster(m) and string.lower(getCreatureName(m)) == string.lower(config.monster_name) then
                   doPlayerSendCancel(cid, config.cancel_message)
                   return true
               end
           end
       end
       doTeleportThing(cid, config.position)
       doSendMagicEffect(config.position, config.effect)
       doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, config.congrat_message)
   end
   return true
end
 
Last edited:
you missing the uid on getCreaturePosition also i think that getCreaturePosition should be the center pos of the room not the player current position
btw didnt remember that function lmao
 
When Rahemos is inside it gives the message: "You have to kill Rahemos to enter the tomb!" , after killing him there is no message but the teleportation does not work.
 
because you are inside and if getSpectators(config.center_pos, config.rangeX, config.rangeY) then that line is always executed

test this one

Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
   local config = {
       item_uid = 9413,
       monster_name = "Rahemos",
       position = {x = 329, y = 278, z = 11},
       center_pos = {x = 330, y = 270, z = 11},
       effect = CONST_ANI_EARTH,
       cancel_message = "You have to kill Rahemos to enter the tomb!",
       congrat_message = "Congratulation! Don't forget to take a piece from the tomb!",
       rangeX = 10,
       rangeY = 10
   }
 
   if item.uid == config.item_uid then
       if getSpectators(config.center_pos, config.rangeX, config.rangeY) then
           for _, m in ipairs(getSpectators(config.center_pos, config.rangeX, config.rangeY)) do
               if isMonster(m) and string.lower(getCreatureName(m)) == string.lower(config.monster_name) then
                   doPlayerSendCancel(cid, config.cancel_message)
                   return true
               end
           end
           doTeleportThing(cid, config.position)
           doSendMagicEffect(config.position, config.effect)
           doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, config.congrat_message)
        end
   end
   return true
end
all credits to @GarQet
 
Last edited by a moderator:
Solution
you missing the uid on getCreaturePosition also i think that getCreaturePosition should be the center pos of the room not the player current position
btw didnt remember that function lmao
Did u take updated script?

#Up
Its the same as mine, but I edited it 10 minutes ago xd
 
Back
Top