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

TFS 1.X+ monster spell

theduck

Member
Joined
Dec 6, 2018
Messages
246
Reaction score
20
Code:
 function onCastSpell(cid, var)
 
local pos = getCreaturePosition(cid)

            
if  getTileItemById(pos,2725) == 1 then
   doCreatureSay(cid, "ok", TALKTYPE_ORANGE_1)
else
---doCreatureAddHealth(cid,-100)
 
doCreatureSay(cid, "no ok", TALKTYPE_ORANGE_1)
end


end


I'm trying to spell a monster
if you have the item id is next to the monster say 'ok' if not 'no ok'
 
Instead of this:
== 1
Use this:
~= nil

Becouse getTileItemById returns that item not '1' and if it doesnt find that item it will return nil, each object have its own unique id, so your script returns not 1 but something like 8293757481947 (if you convert to number)

And in 14th line you have to put:
return true
Always at the end of your scripts and dont forget it, there are only unique situations when you shouldnt use it.
 
Last edited:
If its TFS 1.x

Code:
function onCastSpell(creature, variant)
     local tile = Tile(creature:getPosition())

     if not tile then return false end

     if tile:getItemById(2725) then
          creature:say("ok", TALKTYPE_MONSTER_SAY)
     else
          creature:say("no ok", TALKTYPE_MONSTER_SAY)
     end
return true
end
 
If its TFS 1.x

Code:
function onCastSpell(creature, variant)
     local tile = Tile(creature:getPosition())

     if not tile then return false end

     if tile:getItemById(2725) then
          creature:say("ok", TALKTYPE_MONSTER_SAY)
     else
          creature:say("no ok", TALKTYPE_MONSTER_SAY)
     end
return true
end
checkboss.png




Good morning I tested your code and it worked more I think I did not explain properly sorry.

In the photo I made the example that I need the monster will check if near him there is the 'ID' of the palm tree if you have next to him he will say 'ok' if you do not have the ID of the palm will say 'no ok'
 
Lua:
function onCastSpell(creature, variant)
    local pos = creature:getPosition()
    pos:getNextPosition(creature:getDirection(), 1)

    local tile = Tile(pos)
    if not tile then return false end

    if tile:getItemById(2725) then
        creature:say("ok", TALKTYPE_MONSTER_SAY)
    else
        creature:say("no ok", TALKTYPE_MONSTER_SAY)
    end
    return true
end



Part:
Lua:
pos:getNextPosition(creature:getDirection(), 1)
is exactly the same as this:
Lua:
    local pos = creature:getPosition()
    local lookDir = creature:getDirection()
    if lookdir = 0 then
        pos.y = pos.y - 1
    elseif lookdir = 1 then
        pos.x = pos.x + 1
    elseif lookdir = 2 then
        pos.y = pos.y + 1
    elseif lookdir = 3 then
        pos.x = pos.x - 1
    end
 
Last edited:
Lua:
function onCastSpell(creature, variant)
    local pos = creature:getPosition()
    pos:getNextPosition(creature:getDirection(), 1)

    local tile = Tile(pos)
    if not tile then return false end

    if tile:getItemById(2725) then
        creature:say("ok", TALKTYPE_MONSTER_SAY)
    else
        creature:say("no ok", TALKTYPE_MONSTER_SAY)
    end
    return true
end



Part:
Lua:
pos:getNextPosition(creature:getDirection(), 1)
is exactly the same as this:
Lua:
    local pos = creature:getPosition()
    local lookDir = creature:getDirection()
    if lookdir = 0 then
        pos.y = pos.y - 1
    elseif lookdir = 1 then
        pos.x = pos.x + 1
    elseif lookdir = 2 then
        pos.y = pos.y + 1
    elseif lookdir = 3 then
        pos.x = pos.x - 1
    end


Code:
function onCastSpell(creature, variant)
    local pos = creature:getPosition()
    pos:getNextPosition(creature:getDirection(), 1)

    local tile = Tile(pos)
    if not tile then return false end

    if tile:getItemById(2725) then
        creature:say("ok", TALKTYPE_MONSTER_SAY)
    else
        creature:say("no ok", TALKTYPE_MONSTER_SAY)
    end
    return true
end


Hello, I tested this code but it keeps pulling only the floor id below the monster it doesn't detect the trees
 
Lua:
local range = 1 -- in sqm

function onCastSpell(creature, variant)
    local pos = creature:getPosition()
    local check = 0

    for x = 0, (range * 2) do
        for y = 0, (range * 2) do
            if check == 0 then
                pos.x = pos.x - range + x
                pos.y = pos.y - range + y
                local tile = Tile(pos)
                if tile then
                    if tile:getItemById(2725) then
                        check = 1
                    end
                end
            end
        end
    end
    
    if check == 1 then
        creature:say("ok", TALKTYPE_MONSTER_SAY)
    else
        creature:say("no ok", TALKTYPE_MONSTER_SAY)            
    end
    return true
end
 
Lua:
local range = 1 -- in sqm

function onCastSpell(creature, variant)
    local pos = creature:getPosition()
    local check = 0

    for x = 0, (range * 2) do
        for y = 0, (range * 2) do
            if check == 0 then
                pos.x = pos.x - range + x
                pos.y = pos.y - range + y
                local tile = Tile(pos)
                if tile then
                    if tile:getItemById(2725) then
                        check = 1
                    end
                end
            end
        end
    end
   
    if check == 1 then
        creature:say("ok", TALKTYPE_MONSTER_SAY)
    else
        creature:say("no ok", TALKTYPE_MONSTER_SAY)           
    end
    return true
end

when he is below he detects the item beside him and when he is above he does not detect the item beside him I put 5 SQM
 

Attachments

Lua:
local range = 1 -- in sqm

function onCastSpell(creature, variant)
    local pos = creature:getPosition()
    local check = 0

    for x = 0, (range * 2) do
        for y = 0, (range * 2) do
            if check == 0 then
                pos.x = pos.x - range + x
                pos.y = pos.y - range + y
                local tile = Tile(pos)
                if tile then
                    if tile:getItemById(2725) then
                        check = 1
                    end
                end
            end
        end
    end
   
    if check == 1 then
        creature:say("ok", TALKTYPE_MONSTER_SAY)
    else
        creature:say("no ok", TALKTYPE_MONSTER_SAY)           
    end
    return true
end

Any idea
 
Hello, hope this work for you, check it...
Lua:
function checkAreaForItem(pos, range, item)
    local from = {x=pos.x-range, y=pos.y-range, z=pos.z}
    local to = {x=pos.x+range, y=pos.y+range, z=pos.z}
    for z = from.z, to.z do
        for y = from.y, to.y do
            for x = from.x, to.x do
                local t = Tile(Position(x, y, z))
                if t:getItemById(item) then
                    return true
                end
            end
        end
    end
end

 -- checkAreaForItem(pos, range, itemId) With this function you can change the range and the itemId what are you looking for.
 -- checkAreaForItem(pos, 2, 2725) In this case, whe are looking for item 2725, 2 sqm arround the position called.


function onCastSpell(cid, var)
    local c = Creature(cid)
    local pos = c:getPosition()
    if checkAreaForItem(pos, 2, 2725) then
        doCreatureSay(cid, "Ok", TALKTYPE_ORANGE_1)
    else
        doCreatureSay(cid, "Ok NO", TALKTYPE_ORANGE_1)
    end
end
 
Back
Top