• 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 [tfs 1x+] reflect

theduck

Member
Joined
Dec 6, 2018
Messages
246
Reaction score
20
when the player attacks monster X with any type of attack, the damage received by that monster will go to monster Y
 
Last edited:
Solution
no error on the console just does not work
try with prints.

Lua:
local effects = {
    [COMBAT_PHYSICALDAMAGE] = CONST_ME_DRAWBLOOD,
    [COMBAT_ENERGYDAMAGE] = CONST_ME_ENERGYAREA,
    [COMBAT_EARTHDAMAGE] = CONST_ME_POISONAREA,
    [COMBAT_FIREDAMAGE] = CONST_ME_FIREAREA,
    [COMBAT_ICEDAMAGE] = CONST_ME_ICEAREA,
    [COMBAT_HOLYDAMAGE] = CONST_ME_HOLYAREA,
    [COMBAT_DEATHDAMAGE] = CONST_ME_MORTAREA,
    [COMBAT_HEALING] = CONST_ME_MAGIC_GREEN
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    print(1)
    print(creature:getName():lower())
    if Monster(creature) and creature:getName():lower() == "rat" then
        print(2)
        print(primaryType)
        if primaryType ~= COMBAT_HEALING then
            print(3)
            print(special.creatures.boss.cave_rat[1])...
Server ver?
Melee attack? Spell?
 
Server ver?
Melee attack? Spell?




edited post
 
Code:
function onThink(creature)
    local health, difference, boss, pos = 0, 0, Tile(Position(33732, 31559, 12)):getTopCreature(), creature:getPosition()
 

        local spectators = Game.getSpectators(Position(33735, 31559, 12), false, false, 12, 12, 12, 12)
        for i = 1, #spectators do
            local spec = spectators[i]
            if spec:getName():lower() == 'boss' then
            
                health = spec:getHealth()
                
                difference = (boss:getMaxHealth() - boss:getHealth())
                 
                spec:addHealth( - difference)
             
                spec:say('test', TALKTYPE_MONSTER_SAY)
                return true
            end
         
    end
end

I thought about doing it like this but it’s not working properly the second monster is dying faster than the monster that’s covering the damage
 
Last edited:
I still haven't played around with TFS 1.3 yet, but I know you'd want to do this with
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

So whenever it takes damage, you simply just find monster y, and send the damage to them instead.

How you go about finding monster y is up to you though.

without more information about the event / script requirements it's impossible to help.
 
I still haven't played around with TFS 1.3 yet, but I know you'd want to do this with
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

So whenever it takes damage, you simply just find monster y, and send the damage to them instead.

How you go about finding monster y is up to you though.

without more information about the event / script requirements it's impossible to help.
hello, no more requirements.
all damage that monster 1 takes monster 2 will take the same damage.
 
hello, no more requirements.
all damage that monster 1 takes monster 2 will take the same damage.
You don't seem to understand at all. lmao

Monster 2 is the crux of the issue. If we don't know the requirements required to find monster 2, it's impossible to script.

Is monster 2 stationary?
Can there be multiple monster 2's?
Is it only in 1 location / room where monster 2 can exist?

We need to know what scenario we are dealing with, and then we can script it for that scenario.

Hence..

without more information about the event / script requirements it's impossible to help.
 
You don't seem to understand at all. lmao

Monster 2 is the crux of the issue. If we don't know the requirements required to find monster 2, it's impossible to script.

Is monster 2 stationary?
Can there be multiple monster 2's?
Is it only in 1 location / room where monster 2 can exist?

We need to know what scenario we are dealing with, and then we can script it for that scenario.

Hence..

without more information about the event / script requirements it's impossible to help.
this I said in the post, you need a scenario I explain in the topic
-
a room 2 monster player attack 1 monster damage all damage that monster takes monster 2 will take the same damage.
monster two is in the room.
just what I need is this creaturescript of damage


 
Last edited:
this I said in the post, you need a scenario I explain in the topic
-
a room 2 monster player attack 1 monster damage all damage that monster takes monster 2 will take the same damage.
monster two is in the room.
just what I need is this creaturescript of damage


So, only 1 creature.

Hold the creatureid in a global storage or temporary table whenever it is spawned.

confirm when monster1 takes damage via onHealthChange, then
Send damage to that monster2 via whatever method you want, after confirming that monster2 still exists.
Post automatically merged:

---------------------------------------
bandicam-2020-07-25-14-12-35-487.gif

data/events/events.xml -- make sure this is enabled.
XML:
<event class="Monster" method="onSpawn" enabled="1" />
data/events/scripts/monster.lua
Lua:
function findBossId(position)
    local spectators = Game.getSpectators(position, false)
    for i = 1, #spectators do
        if Monster(spectators[i]) then
            if spectators[i]:getName():lower() == "cave rat" then
                local temp_id = spectators[i]:getId()
                if temp_id > special.creatures.boss.cave_rat[1] then
                    special.creatures.boss.cave_rat[1] = temp_id
                end
            end
        end
    end
end

function Monster:onSpawn(position, startup, artificial)
    -- boss
    if self:getName():lower() == "cave rat" then
        addEvent(findBossId, 0, position)
    end
    -- creature that hurts boss
    if self:getName():lower() == "rat" then
        self:registerEvent("onHealthChange")
    end
    return true
end
data/creaturescripts/creaturescripts.xml
XML:
<event type="healthchange" name="onHealthChange" script="onHealthChange.lua" />
data/creaturescripts/scripts/onHealthChange.lua
Lua:
local effects = {
    [COMBAT_PHYSICALDAMAGE] = CONST_ME_DRAWBLOOD,
    [COMBAT_ENERGYDAMAGE] = CONST_ME_ENERGYAREA,
    [COMBAT_EARTHDAMAGE] = CONST_ME_POISONAREA,
    [COMBAT_FIREDAMAGE] = CONST_ME_FIREAREA,
    [COMBAT_ICEDAMAGE] = CONST_ME_ICEAREA,
    [COMBAT_HOLYDAMAGE] = CONST_ME_HOLYAREA,
    [COMBAT_DEATHDAMAGE] = CONST_ME_MORTAREA,
    [COMBAT_HEALING] = CONST_ME_MAGIC_GREEN
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if Monster(creature) and creature:getName():lower() == "rat" then
        if primaryType ~= COMBAT_HEALING then
            local boss_monster = Monster(special.creatures.boss.cave_rat[1])
            if boss_monster then
                doTargetCombat(attacker, boss_monster, primaryType, -primaryDamage, -primaryDamage, effects[primaryType])
                doTargetCombat(attacker, boss_monster, secondaryType, -secondaryDamage, -secondaryDamage, effects[secondaryType])
                return creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin
            end
        end
    end
    return creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end
data/lib/core/core.lua
Lua:
dofile('data/lib/core/xikini_tables.lua')
data/lib/core/xikini_tables.lua
Lua:
special = {
    creatures = {
        boss = {
            cave_rat = {0} -- (boss_creatureid)
        }
    }
}
 
Last edited:
@Xikini
attempt to call global 'doTargetCombat' (a nil value)
stack traceback:
[C]: in function 'doTargetCombat'

doTargetCombat(attacker, boss_monster, primaryType, -primaryDamage, -primaryDamage, effects[primaryType])
doTargetCombat(attacker, boss_monster, secondaryType, -secondaryDamage, -secondaryDamage, effects[secondaryType])
 
Code:
int LuaScriptInterface::luaDoTargetCombatHealth(lua_State* L)
{
    //doTargetCombatHealth(cid, target, type, min, max, effect[, origin = ORIGIN_SPELL])
    Creature* creature = getCreature(L, 1);
    if (!creature && (!isNumber(L, 1) || getNumber<uint32_t>(L, 1) != 0)) {
        reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
        pushBoolean(L, false);
        return 1;
    }

    Creature* target = getCreature(L, 2);
    if (!target) {
        reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND));
        pushBoolean(L, false);
        return 1;
    }

    CombatType_t combatType = getNumber<CombatType_t>(L, 3);

    CombatParams params;
    params.combatType = combatType;
    params.impactEffect = getNumber<uint8_t>(L, 6);

    CombatDamage damage;
    damage.origin = getNumber<CombatOrigin>(L, 7, ORIGIN_SPELL);
    damage.primary.type = combatType;
    damage.primary.value = normal_random(getNumber<int32_t>(L, 4), getNumber<int32_t>(L, 5));

    Combat::doCombatHealth(creature, target, damage, params);
    pushBoolean(L, true);
    return 1;
}
mine is different I moved to it, without console error but I was not successful
 
no error on the console just does not work
try with prints.

Lua:
local effects = {
    [COMBAT_PHYSICALDAMAGE] = CONST_ME_DRAWBLOOD,
    [COMBAT_ENERGYDAMAGE] = CONST_ME_ENERGYAREA,
    [COMBAT_EARTHDAMAGE] = CONST_ME_POISONAREA,
    [COMBAT_FIREDAMAGE] = CONST_ME_FIREAREA,
    [COMBAT_ICEDAMAGE] = CONST_ME_ICEAREA,
    [COMBAT_HOLYDAMAGE] = CONST_ME_HOLYAREA,
    [COMBAT_DEATHDAMAGE] = CONST_ME_MORTAREA,
    [COMBAT_HEALING] = CONST_ME_MAGIC_GREEN
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    print(1)
    print(creature:getName():lower())
    if Monster(creature) and creature:getName():lower() == "rat" then
        print(2)
        print(primaryType)
        if primaryType ~= COMBAT_HEALING then
            print(3)
            print(special.creatures.boss.cave_rat[1])
            local boss_monster = Monster(special.creatures.boss.cave_rat[1])
            if boss_monster then
                print(4)
                doTargetCombatHealth(attacker, boss_monster, primaryType, -primaryDamage, -primaryDamage, effects[primaryType])
                doTargetCombatHealth(attacker, boss_monster, secondaryType, -secondaryDamage, -secondaryDamage, effects[secondaryType])
                return creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin
            end
        end
    end
    return creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end
 
Solution
try with prints.

Lua:
local effects = {
    [COMBAT_PHYSICALDAMAGE] = CONST_ME_DRAWBLOOD,
    [COMBAT_ENERGYDAMAGE] = CONST_ME_ENERGYAREA,
    [COMBAT_EARTHDAMAGE] = CONST_ME_POISONAREA,
    [COMBAT_FIREDAMAGE] = CONST_ME_FIREAREA,
    [COMBAT_ICEDAMAGE] = CONST_ME_ICEAREA,
    [COMBAT_HOLYDAMAGE] = CONST_ME_HOLYAREA,
    [COMBAT_DEATHDAMAGE] = CONST_ME_MORTAREA,
    [COMBAT_HEALING] = CONST_ME_MAGIC_GREEN
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    print(1)
    print(creature:getName():lower())
    if Monster(creature) and creature:getName():lower() == "rat" then
        print(2)
        print(primaryType)
        if primaryType ~= COMBAT_HEALING then
            print(3)
            print(special.creatures.boss.cave_rat[1])
            local boss_monster = Monster(special.creatures.boss.cave_rat[1])
            if boss_monster then
                print(4)
                doTargetCombatHealth(attacker, boss_monster, primaryType, -primaryDamage, -primaryDamage, effects[primaryType])
                doTargetCombatHealth(attacker, boss_monster, secondaryType, -secondaryDamage, -secondaryDamage, effects[secondaryType])
                return creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin
            end
        end
    end
    return creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin
end
rat
2
1
3
1073824432
 
Back
Top