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

reflect system

_M4G0_

Intermediate OT User
Joined
Feb 6, 2016
Messages
540
Solutions
16
Reaction score
106
i have add part of the code CreatureEvent - [TFS 1.2] Conditions: Resist, Absorb, Reflect, Deflect (https://otland.net/threads/tfs-1-2-conditions-resist-absorb-reflect-deflect.233406/) in my custom system, but i have this error after a time
LUA:
local refs = {
    [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_DROWNDAMAGE] = CONST_ME_LOSEENERGY,
    [COMBAT_DEATHDAMAGE] = CONST_ME_MORTAREA
}

function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if isInArray({ORIGIN_MELEE, ORIGIN_RANGED, ORIGIN_SPELL}, origin) and primaryType ~= COMBAT_HEALING then
        local attr = SlotSystem.getPlayerAttributes(creature)
        local protect = 0
        local reflect = 0
        for k, v in pairs(attr) do
            protect = SlotSystem.Attributes[k].ElementProtect[primaryType] and protect+(SlotSystem.Attributes[k].ElementProtect[primaryType]*v) or protect
            if attacker then
               reflect = SlotSystem.Attributes[k].ElementReflect[primaryType] and reflect+(SlotSystem.Attributes[k].ElementReflect[primaryType]*v) or reflect
                -- local a = primaryDamage * (reflect / 100)
                local a = ((primaryDamage*reflect)/100)
                    --local m = MonsterType(attacker:getName())
                if attacker:isMonster() then
                    local m = MonsterType(attacker:getName())
                    local e = m:getElementList()
                    local f = m:getCombatImmunities()
                    if type(f) == "number" then
                        if f == primaryType then
                            a = 0
                        end
                    else
                        for i, j in pairs(f) do
                            if i == primaryType then
                                a = 0
                            end
                        end
                    end
                    if type(e) == "number" then
                        if e == primaryType then
                            if e > 0 then
                                a = (a - (a * (e / 100)))
                            else
                                a = (a + (a * ((e * -1) / 100)))
                            end
                        end
                    else
                        for i, j in pairs(e) do
                            if i == primaryType then
                                if j > 0 then
                                    a = (a - (a * (j / 100)))
                                else
                                    a = (a + (a * ((j * -1) / 100)))
                                end
                            end
                        end
                    end
                end
                doTargetCombatHealth(creature, attacker, primaryType, a, a)
                if m ~= nil then
                else
                    local position = creature:getPosition()
                    print(position.x, position.y, position.z)
                end
            end
        end
        primaryDamage = primaryDamage-((protect*primaryDamage)/100)
    end
    if primaryDamage == 0 and secondaryDamage == 0 and creature:isPlayer() then
        creature:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

LUA:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/custom/slot system.lua:onHealthChange
data/creaturescripts/scripts/custom/slot system.lua:26: attempt to index local 'm' (a nil value)
stack traceback:
    [C]: in function '__index'
    data/creaturescripts/scripts/custom/slot system.lua:26: in function <data/creaturescripts/scripts/custom/slot system.lua:13>
 
Last edited:
thanks for help
in test
error:confused:
Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/custom/slot system.lua:onHealthChange
data/creaturescripts/scripts/custom/slot system.lua:25: attempt to index local 'm' (a nil value)
stack traceback:
    [C]: in function '__index'
    data/creaturescripts/scripts/custom/slot system.lua:25: in function <data/creaturescripts/scripts/custom/slot system.lua:13>
 
Try changing:
line 23

local m = MonsterType(attacker:getName())

to

local m = MonsterType(Monster(attacker):getName())

if that doesn't work I am lost.
 
Are you using ninja's 8.6 tfs 1.2? If so, that's your problem, MonsterType class isn't in that distro.
last try, but don't work 100%
in monster reflect and protect cause damage =x
LUA:
function onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
     if isInArray({ORIGIN_MELEE, ORIGIN_RANGED, ORIGIN_SPELL}, origin) and primaryType ~= COMBAT_HEALING then
        local attr = SlotSystem.getPlayerAttributes(creature)
        local protect = 0
        local reflect = 0
        for k, v in pairs(attr) do
            protect = SlotSystem.Attributes[k].ElementProtect[primaryType] and protect+(SlotSystem.Attributes[k].ElementProtect[primaryType]*v) or protect
            if attacker then
            reflect = SlotSystem.Attributes[k].ElementReflect[primaryType] and reflect+(SlotSystem.Attributes[k].ElementReflect[primaryType]*v) or reflect
                a = ((primaryDamage*reflect)/100)
                doTargetCombatHealth(creature, attacker, primaryType, a, a)
            end
        end
            primaryDamage = primaryDamage-((protect*primaryDamage)/100)
    end
    if primaryDamage == 0 and secondaryDamage == 0 and creature:isPlayer() then
        creature:getPosition():sendMagicEffect(CONST_ME_POFF)
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
tfs 1.2
C++:
// Monster
    registerClass("Monster", "Creature", LuaScriptInterface::luaMonsterCreate);
    registerMetaMethod("Monster", "__eq", LuaScriptInterface::luaUserdataCompare);

    registerMethod("Monster", "isMonster", LuaScriptInterface::luaMonsterIsMonster);

    registerMethod("Monster", "getType", LuaScriptInterface::luaMonsterGetType);

    registerMethod("Monster", "getSpawnPosition", LuaScriptInterface::luaMonsterGetSpawnPosition);
    registerMethod("Monster", "isInSpawnRange", LuaScriptInterface::luaMonsterIsInSpawnRange);

    registerMethod("Monster", "isIdle", LuaScriptInterface::luaMonsterIsIdle);
    registerMethod("Monster", "setIdle", LuaScriptInterface::luaMonsterSetIdle);

    registerMethod("Monster", "isTarget", LuaScriptInterface::luaMonsterIsTarget);
    registerMethod("Monster", "isOpponent", LuaScriptInterface::luaMonsterIsOpponent);
    registerMethod("Monster", "isFriend", LuaScriptInterface::luaMonsterIsFriend);

    registerMethod("Monster", "addFriend", LuaScriptInterface::luaMonsterAddFriend);
    registerMethod("Monster", "removeFriend", LuaScriptInterface::luaMonsterRemoveFriend);
    registerMethod("Monster", "getFriendList", LuaScriptInterface::luaMonsterGetFriendList);
    registerMethod("Monster", "getFriendCount", LuaScriptInterface::luaMonsterGetFriendCount);

    registerMethod("Monster", "addTarget", LuaScriptInterface::luaMonsterAddTarget);
    registerMethod("Monster", "removeTarget", LuaScriptInterface::luaMonsterRemoveTarget);
    registerMethod("Monster", "getTargetList", LuaScriptInterface::luaMonsterGetTargetList);
    registerMethod("Monster", "getTargetCount", LuaScriptInterface::luaMonsterGetTargetCount);

    registerMethod("Monster", "selectTarget", LuaScriptInterface::luaMonsterSelectTarget);
    registerMethod("Monster", "searchTarget", LuaScriptInterface::luaMonsterSearchTarget);
    registerMethod("Monster", "setSpawnPosition", LuaScriptInterface::luaMonsterSetSpawnPosition);
C++:
// MonsterType
    registerClass("MonsterType", "", LuaScriptInterface::luaMonsterTypeCreate);
    registerMetaMethod("MonsterType", "__eq", LuaScriptInterface::luaUserdataCompare);

    registerMethod("MonsterType", "isAttackable", LuaScriptInterface::luaMonsterTypeIsAttackable);
    registerMethod("MonsterType", "isConvinceable", LuaScriptInterface::luaMonsterTypeIsConvinceable);
    registerMethod("MonsterType", "isSummonable", LuaScriptInterface::luaMonsterTypeIsSummonable);
    registerMethod("MonsterType", "isIllusionable", LuaScriptInterface::luaMonsterTypeIsIllusionable);
    registerMethod("MonsterType", "isHostile", LuaScriptInterface::luaMonsterTypeIsHostile);
    registerMethod("MonsterType", "isPushable", LuaScriptInterface::luaMonsterTypeIsPushable);
    registerMethod("MonsterType", "isHealthShown", LuaScriptInterface::luaMonsterTypeIsHealthShown);

    registerMethod("MonsterType", "isPet", LuaScriptInterface::luaMonsterTypeIsPet);
    registerMethod("MonsterType", "isPassive", LuaScriptInterface::luaMonsterTypeIsHostile);
    registerMethod("MonsterType", "isRewardBoss", LuaScriptInterface::luaMonsterTypeIsRewardBoss);
    registerMethod("MonsterType", "isBoss", LuaScriptInterface::luaMonsterTypeIsRewardBoss);

    registerMethod("MonsterType", "canPushItems", LuaScriptInterface::luaMonsterTypeCanPushItems);
    registerMethod("MonsterType", "canPushCreatures", LuaScriptInterface::luaMonsterTypeCanPushCreatures);

    registerMethod("MonsterType", "getName", LuaScriptInterface::luaMonsterTypeGetName);
    registerMethod("MonsterType", "getNameDescription", LuaScriptInterface::luaMonsterTypeGetNameDescription);

    registerMethod("MonsterType", "getHealth", LuaScriptInterface::luaMonsterTypeGetHealth);
    registerMethod("MonsterType", "getMaxHealth", LuaScriptInterface::luaMonsterTypeGetMaxHealth);
    registerMethod("MonsterType", "getRunHealth", LuaScriptInterface::luaMonsterTypeGetRunHealth);
    registerMethod("MonsterType", "getExperience", LuaScriptInterface::luaMonsterTypeGetExperience);

    registerMethod("MonsterType", "getCombatImmunities", LuaScriptInterface::luaMonsterTypeGetCombatImmunities);
    registerMethod("MonsterType", "getConditionImmunities", LuaScriptInterface::luaMonsterTypeGetConditionImmunities);

    registerMethod("MonsterType", "getAttackList", LuaScriptInterface::luaMonsterTypeGetAttackList);
    registerMethod("MonsterType", "getDefenseList", LuaScriptInterface::luaMonsterTypeGetDefenseList);
    registerMethod("MonsterType", "getElementList", LuaScriptInterface::luaMonsterTypeGetElementList);

    registerMethod("MonsterType", "getVoices", LuaScriptInterface::luaMonsterTypeGetVoices);
    registerMethod("MonsterType", "getLoot", LuaScriptInterface::luaMonsterTypeGetLoot);
    registerMethod("MonsterType", "getCreatureEvents", LuaScriptInterface::luaMonsterTypeGetCreatureEvents);

    registerMethod("MonsterType", "getSummonList", LuaScriptInterface::luaMonsterTypeGetSummonList);
    registerMethod("MonsterType", "getMaxSummons", LuaScriptInterface::luaMonsterTypeGetMaxSummons);

    registerMethod("MonsterType", "getArmor", LuaScriptInterface::luaMonsterTypeGetArmor);
    registerMethod("MonsterType", "getDefense", LuaScriptInterface::luaMonsterTypeGetDefense);
    registerMethod("MonsterType", "getOutfit", LuaScriptInterface::luaMonsterTypeGetOutfit);
    registerMethod("MonsterType", "getRace", LuaScriptInterface::luaMonsterTypeGetRace);
    registerMethod("MonsterType", "getCorpseId", LuaScriptInterface::luaMonsterTypeGetCorpseId);
    registerMethod("MonsterType", "getManaCost", LuaScriptInterface::luaMonsterTypeGetManaCost);
    registerMethod("MonsterType", "getBaseSpeed", LuaScriptInterface::luaMonsterTypeGetBaseSpeed);
    registerMethod("MonsterType", "getLight", LuaScriptInterface::luaMonsterTypeGetLight);

    registerMethod("MonsterType", "getStaticAttackChance", LuaScriptInterface::luaMonsterTypeGetStaticAttackChance);
    registerMethod("MonsterType", "getTargetDistance", LuaScriptInterface::luaMonsterTypeGetTargetDistance);
    registerMethod("MonsterType", "getYellChance", LuaScriptInterface::luaMonsterTypeGetYellChance);
    registerMethod("MonsterType", "getYellSpeedTicks", LuaScriptInterface::luaMonsterTypeGetYellSpeedTicks);
    registerMethod("MonsterType", "getChangeTargetChance", LuaScriptInterface::luaMonsterTypeGetChangeTargetChance);
    registerMethod("MonsterType", "getChangeTargetSpeed", LuaScriptInterface::luaMonsterTypeGetChangeTargetSpeed);
 
Last edited:
Back
Top