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

Trap Rune problem

jareczekjsp

Member
Joined
Jan 30, 2023
Messages
264
Solutions
1
Reaction score
22
GitHub
Jarek123
I use tfs 1.3 tibia 8.6 I try make trap rune but player must be max 1sqm from (Target Player ) but i would like when have distance 5 sqm can use rune and make trap


LUA:
trapRuneId = 31194  -- ID runy, którą gracz używa (zmień na odpowiednią)
local bushId = 1499  -- ID krzaków, które mają pojawić się (zmień na odpowiedni obiekt)

function onUse(player, item, fromPosition, target, toPosition)
    -- Sprawdzamy, czy celem jest gracz
    if target:isPlayer() then
        -- Pobieramy pozycję celu
        local targetPosition = target:getPosition()

        -- Umieszczamy krzaki wokół gracza w promieniu 3 pól (np. w promieniu 3x3)
        for x = -1, 1 do
            for y = -1, 1 do
                if x ~= 0 or y ~= 0 then  -- Nie stawiamy krzaków na samej pozycji gracza
                    local position = {x = targetPosition.x + x, y = targetPosition.y + y, z = targetPosition.z}
                    -- Tworzymy krzaki w określonej pozycji
                    local bush = Game.createItem(bushId, 1, position)
                end
            end
        end

        -- Możesz dodać dodatkowe efekty, np. animacje, komunikaty itd.
        -- Dla przykładu: wyświetlamy wiadomość, że trap został aktywowany.
        player:say("The bushes have appeared around the target!", TALKTYPE_MONSTER_SAY)
    else
        -- Jeżeli celem nie jest gracz, skrypt nic nie robi
        player:say("You cannot use this rune on this object.", TALKTYPE_MONSTER_SAY)
    end
    return true
end
 
Solution
data/scripts/trapRune.lua - Revscripts
LUA:
local trapRuneId = 31194  -- ID runy, którą gracz używa (zmień na odpowiednią)
local bushId = 1499  -- ID krzaków, które mają pojawić się (zmień na odpowiedni obiekt)
local maxDistance = 5

local trapRune = Action()
function trapRune.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not target:isPlayer() then
        player:say("You can only use this rune on a player.", TALKTYPE_MONSTER_SAY)
        return true
    end

    local playerPos = player:getPosition()
    local targetPos = target:getPosition()
    local distance = math.max(math.abs(playerPos.x - targetPos.x), math.abs(playerPos.y - targetPos.y))

    if distance > maxDistance then
        player:say("You are too...
data/scripts/trapRune.lua - Revscripts
LUA:
local trapRuneId = 31194  -- ID runy, którą gracz używa (zmień na odpowiednią)
local bushId = 1499  -- ID krzaków, które mają pojawić się (zmień na odpowiedni obiekt)
local maxDistance = 5

local trapRune = Action()
function trapRune.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not target:isPlayer() then
        player:say("You can only use this rune on a player.", TALKTYPE_MONSTER_SAY)
        return true
    end

    local playerPos = player:getPosition()
    local targetPos = target:getPosition()
    local distance = math.max(math.abs(playerPos.x - targetPos.x), math.abs(playerPos.y - targetPos.y))

    if distance > maxDistance then
        player:say("You are too far to use this rune. Get closer!", TALKTYPE_MONSTER_SAY)
        return true
    end

    if playerPos.z ~= targetPos.z then
        player:say("You cannot use this rune on a different floor.", TALKTYPE_MONSTER_SAY)
        return true
    end

    for x = -1, 1 do
        for y = -1, 1 do
            if x ~= 0 or y ~= 0 then
                local pos = Position(targetPos.x + x, targetPos.y + y, targetPos.z)
                local tile = Tile(pos)
                if tile and tile:getGround() and not tile:hasFlag(TILESTATE_BLOCKSOLID) then
                    Game.createItem(bushId, 1, pos)
                end
            end
        end
    end

    player:say("The bushes have appeared around the target!", TALKTYPE_MONSTER_SAY)
    return true
end
trapRune:id(trapRuneId)
trapRune:allowFarUse(maxDistance > 1)
trapRune:register()
 
Last edited by a moderator:
Solution
not workinf on distance 5 sqm ;/
Post automatically merged:

The player who casts the rune must be close to the other player, does not work at a distance.
 
Last edited:
Why dont you use function?
LUA:
function rune.onCastSpell(creature, var)
?
I have spell script

LUA:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGY)
setCombatParam(combat, COMBAT_PARAM_CREATEITEM, 1499)

local arr = {
{1, 1, 1},
{1, 2, 1},
{1, 1, 1}
}

local area = createCombatArea(arr)
setCombatArea(combat, area)

function onCastSpell(cid, var)
    return doCombat(cid, combat, var)
end
but I can not use on player when I try trap 1 sqm is free;/
 
sorry Where I have add this ? Like that ??

LUA:
local trapRuneId = 31194  -- ID runy, która gracz uzywa (zmien na odpowiednia)
local bushId = 1499  -- ID krzaków, które maja pojawic sie (zmien na odpowiedni obiekt)
local maxDistance = 5
trapRune:allowFarUse(maxDistance > 1)

local trapRune = Action()
function trapRune.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if not target:isPlayer() then
        player:say("You can only use this rune on a player.", TALKTYPE_MONSTER_SAY)
        return true
    end

    local playerPos = player:getPosition()
    local targetPos = target:getPosition()
    local distance = math.max(math.abs(playerPos.x - targetPos.x), math.abs(playerPos.y - targetPos.y))

    if distance > maxDistance then
        player:say("You are too far to use this rune. Get closer!", TALKTYPE_MONSTER_SAY)
        return true
    end

    if playerPos.z ~= targetPos.z then
        player:say("You cannot use this rune on a different floor.", TALKTYPE_MONSTER_SAY)
        return true
    end

    for x = -1, 1 do
        for y = -1, 1 do
            if x ~= 0 or y ~= 0 then
                local pos = Position(targetPos.x + x, targetPos.y + y, targetPos.z)
                local tile = Tile(pos)
                if tile and tile:getGround() and not tile:hasFlag(TILESTATE_BLOCKSOLID) then
                    Game.createItem(bushId, 1, pos)
                end
            end
        end
    end

    player:say("The bushes have appeared around the target!", TALKTYPE_MONSTER_SAY)
    return true
end
trapRune:id(trapRuneId)
trapRune:register()
 
yes I add to data/scripts but not working on distance ;/ when i click on player I walk to player no use rune from 5 sqm
Post automatically merged:

I mean where I have Put
LUA:
trapRune:allowFarUse(maxDistance > 1)
because not working when I put to script is the same
Post automatically merged:

 
Last edited:
Back
Top