• 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 0.X Check if there is a item on effect SQM spell

warriorfrog

Active Member
Joined
Jul 29, 2015
Messages
334
Reaction score
35
I have this spell that pull/push other players for their back...
It already check if this SQM is valid but i would like to check other think:

I would like to have a list of items for example [2595, 2103] (PARCEL/HONEYFLOWER)
That if there is some of this items on the SQM player would be teleported, it blocks the teleport...
How to do it?

Code:
local config = {
    effect = 2,
    dir = {
        [0] = 2,
        [1] = 3,
        [2] = 0,
        [3] = 1
    }
}

local function isWalkable(cid, pos)
    if isCreature(getTopCreature(pos).uid) then
        return true
    end

    if not pos or type(pos) ~= "table" then
        return false
    end
    pos.stackpos = 0
    if not getThingFromPos(pos) then
        return false
    end
    if getTileThingByPos(pos).uid ~= 0 then
    local n = getTileInfo(pos)
        if (doTileQueryAdd(cid, pos) == 1) then
            return true
        end
    return false
    end
    if getThingFromPos(pos) and getThingFromPos(pos).uid > 0 and getThingFromPos(pos).itemid > 0 then
        if hasProperty(getThingFromPos(pos).uid, 2) then
            return false
        end
    end
    if getThingFromPos(pos) and getThingFromPos(pos).uid > 0 and getThingFromPos(pos).itemid > 0 then
        if getTilePzInfo(pos) then  
            return false
        end
    end
    return true
end

function onCastSpell(cid, var)
    local target = variantToNumber(var)
    if isCreature(cid) and isCreature(target) then
        local lookDir = getCreatureLookDirection(target)
        local jPos = getPositionByDirection(getThingPos(target), config.dir[lookDir], 1)
        if (isWalkable(cid, jPos) == false) then
            doPlayerSendCancel(cid, "Back position is not reachable.")
            return false
        elseif (isWalkable(cid, jPos) == true) then
            doSendMagicEffect(getThingPos(target), config.effect)
            doTeleportThing(target, jPos)
            return true
        end
    end
    return true
end
 
Solution
Lua:
if getTileItemById(jPos, 2595).uid > 0 or getTileItemById(jPos, 2103).uid > 0 then
    -- tile has parcel/honeyflower
else
    -- tile does not have those items
end

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,612
Solutions
395
Reaction score
3,729
Lua:
if getTileItemById(jPos, 2595).uid > 0 or getTileItemById(jPos, 2103).uid > 0 then
    -- tile has parcel/honeyflower
else
    -- tile does not have those items
end
 
Solution

Xikini

I whore myself out for likes
Support Team
Joined
Nov 17, 2010
Messages
5,612
Solutions
395
Reaction score
3,729
Yes, also crates,boxes..
Thanks to you help, that i can do ;)
ah, if there is that many things.. do either one of these

Lua:
local prohibitedPushItems = {2595, 2103, 1111, 2222}
local prohibitedPushItemOnTile = false
for i = 1, #prohibitedPushItems do
    if getTileItemById(jPos, prohibitedPushItems[i]).uid > 0 then
        prohibitedPushItemOnTile = true
        break
    end
end

if not prohibitedPushItemOnTile then
    -- none of those items on tile.
else
    -- one or more of those items on tile
end
Lua:
local prohibitedPushItems = {2595, 2103, 1111, 2222}
for i = 1, #prohibitedPushItems do
    if getTileItemById(jPos, prohibitedPushItems[i]).uid > 0 then
        -- one or more of those items on tile (end script)
        return false
    end
end

-- none of those items on tile. (continue in script)
 
OP
OP
warriorfrog

warriorfrog

Active Member
Joined
Jul 29, 2015
Messages
334
Reaction score
35
ah, if there is that many things.. do either one of these

Lua:
local prohibitedPushItems = {2595, 2103, 1111, 2222}
local prohibitedPushItemOnTile = false
for i = 1, #prohibitedPushItems do
    if getTileItemById(jPos, prohibitedPushItems[i]).uid > 0 then
        prohibitedPushItemOnTile = true
        break
    end
end

if not prohibitedPushItemOnTile then
    -- none of those items on tile.
else
    -- one or more of those items on tile
end
Lua:
local prohibitedPushItems = {2595, 2103, 1111, 2222}
for i = 1, #prohibitedPushItems do
    if getTileItemById(jPos, prohibitedPushItems[i]).uid > 0 then
        -- one or more of those items on tile (end script)
        return false
    end
end

-- none of those items on tile. (continue in script)

better then i thought, thank u again ;)
 
Top