• 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+ Creature On Top (UH Trap)

T

Tinkz

Guest
Hello!

i'm using TFS 1.2 and i'm having an issue with creature on top and creature on bottom. I'm interested in adding the feature uh trap which means that the last guy on a player stack should be on top of everyone. Right now it is reversed, meaning on my server the last person that enters a stack of player becomes the last.


I'm sure it is this piece of source code found in tile.cpp

C++:
Creature* Tile::getTopCreature() const
{
    if (const CreatureVector* creatures = getCreatures()) {
        if (!creatures->empty()) {
            return *creatures->begin();
        }
    }
    return nullptr;
}

const Creature* Tile::getBottomCreature() const
{
    if (const CreatureVector* creatures = getCreatures()) {
        if (!creatures->empty()) {
            return *creatures->rbegin();
        }
    }
    return nullptr;
}

Creature* Tile::getTopVisibleCreature(const Creature* creature) const
{
    if (const CreatureVector* creatures = getCreatures()) {
        if (creature) {
            const Player* player = creature->getPlayer();
            if (player && player->isAccessPlayer()) {
                return getTopCreature();
            }

            for (Creature* tileCreature : *creatures) {
                if (creature->canSeeCreature(tileCreature)) {
                    return tileCreature;
                }
            }
        } else {
            for (Creature* tileCreature : *creatures) {
                if (!tileCreature->isInvisible()) {
                    const Player* player = tileCreature->getPlayer();
                    if (!player || !player->isInGhostMode()) {
                        return tileCreature;
                    }
                }
            }
        }
    }
    return nullptr;
}

const Creature* Tile::getBottomVisibleCreature(const Creature* creature) const
{
    if (const CreatureVector* creatures = getCreatures()) {
        if (creature) {
            const Player* player = creature->getPlayer();
            if (player && player->isAccessPlayer()) {
                return getBottomCreature();
            }

            for (auto it = creatures->rbegin(), end = creatures->rend(); it != end; ++it) {
                if (creature->canSeeCreature(*it)) {
                    return *it;
                }
            }
        } else {
            for (auto it = creatures->rbegin(), end = creatures->rend(); it != end; ++it) {
                if (!(*it)->isInvisible()) {
                    const Player* player = (*it)->getPlayer();
                    if (!player || !player->isInGhostMode()) {
                        return *it;
                    }
                }
            }
        }
    }
    return nullptr;
}
 
I can't test this, but see if this works.
Lua:
--[[
    TFS 1.2
    Combination script of Ultimate Healing Rune & Animated Dead Rune.
]]

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
-- combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onGetFormulaValues(player, level, maglevel)
    local min = (level / 5) + (maglevel * 7.3) + 42
    local max = (level / 5) + (maglevel * 12.4) + 90
    return min, max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant, isHotkey)
    local position = Variant.getPosition(variant)
    local tile = Tile(position)
    if tile then
        local bottomCreature = tile:getBottomCreature()
        if bottomCreature then
            return combat:execute(bottomCreature, variant)
        end
    end
    return
end
 
In onCastSpell you need to have:
Lua:
    if Tile(var:getPosition()):getTopCreature() then
        return combat:execute(creature, var)
    end

Overall UH prepared for TFS 1.3 for 7.4 with "uh trap":
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, 1)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)

function onGetFormulaValues(cid, level, maglevel)
    local min, max
    if (((level * 2) + (maglevel * 3)) * 2.8) < 250 then
        max = 250
    else
        max = ((level * 2) + (maglevel * 3)) * 2.8
    end

    if (((level * 2) + (maglevel * 3)) * 2) < 250 then
        min = 250
    else
        min = ((level * 2) + (maglevel * 3)) * 2
    end

    return min, max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
function onCastSpell(creature, var)
    if Tile(var:getPosition()):getTopCreature() then
        return combat:execute(creature, var)
    end

    creature:sendCancelMessage("You can only use this rune on creatures.")
    creature:getPosition():sendMagicEffect(CONST_ME_POFF)
end
 
In onCastSpell you need to have:
Lua:
    if Tile(var:getPosition()):getTopCreature() then
        return combat:execute(creature, var)
    end

Overall UH prepared for TFS 1.3 for 7.4 with "uh trap":
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, 0)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, 1)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)

function onGetFormulaValues(cid, level, maglevel)
    local min, max
    if (((level * 2) + (maglevel * 3)) * 2.8) < 250 then
        max = 250
    else
        max = ((level * 2) + (maglevel * 3)) * 2.8
    end

    if (((level * 2) + (maglevel * 3)) * 2) < 250 then
        min = 250
    else
        min = ((level * 2) + (maglevel * 3)) * 2
    end

    return min, max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
function onCastSpell(creature, var)
    if Tile(var:getPosition()):getTopCreature() then
        return combat:execute(creature, var)
    end

    creature:sendCancelMessage("You can only use this rune on creatures.")
    creature:getPosition():sendMagicEffect(CONST_ME_POFF)
end
not working for tfs 1.5 can sombody upgrade it?
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, 1)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)

function onGetFormulaValues(player, level, magicLevel)
    local base = 250
    local variation = 0

    local min = math.max((base - variation), ((3 * magicLevel + 2 * level) * (base - variation) / 100))
    local max = math.max((base + variation), ((3 * magicLevel + 2 * level) * (base + variation) / 100))

    return min, max
end


setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")


--setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
 if Tile(var:getPosition()):getTopCreature() then
    return doCombat(cid, combat, var)
end


Code:
Lua Script Error: [Spell Interface]
data/spells/scripts/healing/ultimate_healing_rune.lua:onCastSpell
data/spells/scripts/healing/ultimate_healing_rune.lua:23: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/spells/scripts/healing/ultimate_healing_rune.lua:23: in function <data/spells/scripts/healing/ultimate_healing_rune.lua:22>
 
not working for tfs 1.5 can sombody upgrade it?
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, 1)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)

function onGetFormulaValues(player, level, magicLevel)
    local base = 250
    local variation = 0

    local min = math.max((base - variation), ((3 * magicLevel + 2 * level) * (base - variation) / 100))
    local max = math.max((base + variation), ((3 * magicLevel + 2 * level) * (base + variation) / 100))

    return min, max
end


setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")


--setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
 if Tile(var:getPosition()):getTopCreature() then
    return doCombat(cid, combat, var)
end


Code:
Lua Script Error: [Spell Interface]
data/spells/scripts/healing/ultimate_healing_rune.lua:onCastSpell
data/spells/scripts/healing/ultimate_healing_rune.lua:23: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/spells/scripts/healing/ultimate_healing_rune.lua:23: in function <data/spells/scripts/healing/ultimate_healing_rune.lua:22>
An end in the end
 
An end in the end
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, 1)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)

function onGetFormulaValues(player, level, magicLevel)
    local base = 250
    local variation = 0

    local min = math.max((base - variation), ((3 * magicLevel + 2 * level) * (base - variation) / 100))
    local max = math.max((base + variation), ((3 * magicLevel + 2 * level) * (base + variation) / 100))

    return min, max
end

setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
local position = Variant.getPosition(var)
    local tile = Tile(position)
    if tile then
        local bottomCreature = tile:getBottomCreature()
        if bottomCreature then
            --return combat:execute(bottomCreature, var)
            return doCombat(bottomCreature, combat, var)
    end
        end
   -- end
   if creature:isPlayer() then
     creature:sendCancelMessage("You can only use this rune on creatures.")
    creature:getPosition():sendMagicEffect(CONST_ME_POFF)
end
    return
i get this message "You can only use this rune on creatures " no errors in console but UH is not working

Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, 1)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)

function onGetFormulaValues(player, level, magicLevel)
    local base = 250
    local variation = 0

    local min = math.max((base - variation), ((3 * magicLevel + 2 * level) * (base - variation) / 100))
    local max = math.max((base + variation), ((3 * magicLevel + 2 * level) * (base + variation) / 100))

    return min, max
end

setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")


     function onCastSpell(cid, var)
         if Tile(var:getPosition()):getTopCreature() then
    return doCombat(cid, combat, var)
end

    creature:sendCancelMessage("You can only use this rune on creatures.")
    creature:getPosition():sendMagicEffect(CONST_ME_POFF)
end

with this i get this
Code:
Lua Script Error: [Spell Interface]
data/spells/scripts/healing/ultimate_healing_rune.lua:onCastSpell
data/spells/scripts/healing/ultimate_healing_rune.lua:22: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/spells/scripts/healing/ultimate_healing_rune.lua:22: in function <data/spells/scripts/healing/ultimate_healing_rune.lua:21>
 
Last edited:
bump still can't get this to work tfs 1.5
Try using this fix i did some time ago for Othire.

 
how to make uh trap in lua + and with hotkeys? i mean get this feature working even is there's use in yourself hotkey function. would be possible if so can you show me how please?

uh trap which means that the last guy on a player stack should be on top of everyone.( don't care much about this, but this:
the last guy in stack or the top one, is only one ALLOWED TO HEALHIMSELF AND OTHERS IN THE STACK ( Because runes should affect everyone in the stack

server 8.6 -1.5
this is the healing intense rune file
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onGetFormulaValues(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 3.2) + 20
    local max = (level / 5) + (magicLevel * 5.4) + 40
    return min, max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant, isHotkey)
    return combat:execute(creature, variant)
end
 
Back
Top