• 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 Monster.Element Request

boxxer321

Active Member
Joined
Nov 5, 2011
Messages
110
Reaction score
34
Hey guys!
So, I have a request for you, since my friend ChatGPT and I couldn't do it lol.
I would like each percentage in this monster table, when completing the attack, the monster would release a message, this for each percentage

monster.elements = {
{type = COMBAT_PHYSICALDAMAGE, percent = 30},
{type = COMBAT_DEATHDAMAGE, percent = 30},
{type = COMBAT_ENERGYDAMAGE, percent = 50},
{type = COMBAT_EARTHDAMAGE, percent = 40},
{type = COMBAT_ICEDAMAGE, percent = -10},
{type = COMBAT_HOLYDAMAGE, percent = -10}
}

Example:
If the monster has this percentage, {type = COMBAT_PHYSICALDAMAGE, percent = 30}, it will drop a message saying "this hurt me"
but if he has that percentage {type = COMBAT_PHYSICALDAMAGE, percent = 20}, it will drop a message saying "it almost killed me"

is it possible to do that?
 
you need to explain this better.

"I would like a script with a configurable table where I could edit the messages that correspond to 'percent = 30'.For example, in the monster configuration, if:

monster.elements = {{type = COMBAT_, percent = 30},{type = COMBAT_, percent = 20},

if the percent is 30, the message will be 'hey xxxx'
if the percent is 20, the message will be 'hey yyyy'"
 
Hey guys!
So, I have a request for you, since my friend ChatGPT and I couldn't do it lol.
I would like each percentage in this monster table, when completing the attack, the monster would release a message, this for each percentage

monster.elements = {
{type = COMBAT_PHYSICALDAMAGE, percent = 30},
{type = COMBAT_DEATHDAMAGE, percent = 30},
{type = COMBAT_ENERGYDAMAGE, percent = 50},
{type = COMBAT_EARTHDAMAGE, percent = 40},
{type = COMBAT_ICEDAMAGE, percent = -10},
{type = COMBAT_HOLYDAMAGE, percent = -10}
}

Example:
If the monster has this percentage, {type = COMBAT_PHYSICALDAMAGE, percent = 30}, it will drop a message saying "this hurt me"
but if he has that percentage {type = COMBAT_PHYSICALDAMAGE, percent = 20}, it will drop a message saying "it almost killed me"

is it possible to do that?
Attach an onHealthChange event to that specific monster. You can register the event in the XML/Lua file for the monster, or you can register it directly in any script (i.e if you are spawning the boss).

You can divide the current HP (remember to also negate the upcoming damage) by the creatures max HP, and then check it against a table to send the message.
 
Hey guys!
So, I have a request for you, since my friend ChatGPT and I couldn't do it lol.
I would like each percentage in this monster table, when completing the attack, the monster would release a message, this for each percentage

monster.elements = {
{type = COMBAT_PHYSICALDAMAGE, percent = 30},
{type = COMBAT_DEATHDAMAGE, percent = 30},
{type = COMBAT_ENERGYDAMAGE, percent = 50},
{type = COMBAT_EARTHDAMAGE, percent = 40},
{type = COMBAT_ICEDAMAGE, percent = -10},
{type = COMBAT_HOLYDAMAGE, percent = -10}
}

Example:
If the monster has this percentage, {type = COMBAT_PHYSICALDAMAGE, percent = 30}, it will drop a message saying "this hurt me"
but if he has that percentage {type = COMBAT_PHYSICALDAMAGE, percent = 20}, it will drop a message saying "it almost killed me"

is it possible to do that?
which server version?

onHealthChange is most likely the event you want, depending on which server you are using
Post automatically merged:

Attach an onHealthChange event to that specific monster. You can register the event in the XML/Lua file for the monster, or you can register it directly in any script (i.e if you are spawning the boss).

You can divide the current HP (remember to also negate the upcoming damage) by the creatures max HP, and then check it against a table to send the message.
beat me to it
 
Messy and untested, but should work:
Lua:
local stages = {
    [9] = "",
    [8] = "",
    [7] = "",
    [6] = "",
    [5] = "",
    [4] = "",
    [3] = "this hurt me",            --30% hp
    [2] = "it almost killed me",    --20% hp
    [1] = "im nearly dead :(",       --10% hp
}

local store = {}

local bossTalkStages = CreatureEvent("bossTalkStages")
function bossTalkStages.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    local hp = creature:getHealth() - primaryDamage - (secondaryDamage or 0)
    if hp <= 0 then
        store[cid] = nil
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
 
    local cid = creature:getId()
    local maxHp = creature:getMaxHealth()
    local stage = math.ceil((hp / maxHp) * 10)
 
    if not store[cid] or stage < store[cid] then
        store[cid] = stage
        if stages[stage] then
            local spectators = Game.getSpectators(creature:getPosition(), false, true, 7, 7, 5, 5)
            if #spectators > 0 then
                for _, spectator in ipairs(spectators) do
                    spectator:say(stages[stage], TALKTYPE_MONSTER_SAY, false, spectator, creature:getPosition())
                end
            end
        end
    end
 
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
bossTalkStages:register()
 
Last edited:
Messy and untested, but should work:
Lua:
local stages = {
    [9] = "",
    [8] = "",
    [7] = "",
    [6] = "",
    [5] = "",
    [4] = "",
    [3] = "this hurt me",            --30% hp
    [2] = "it almost killed me",    --20% hp
    [1] = "im nearly dead :(",       --10% hp
}

local store = {}

local bossTalkStages = CreatureEvent("bossTalkStages")
function bossTalkStages.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    local hp = creature:getHealth() - primaryDamage - (secondaryDamage or 0)
    if hp <= 0 then
        store[cid] = nil
        return primaryDamage, primaryType, secondaryDamage, secondaryType
    end
 
    local cid = creature:getId()
    local maxHp = creature:getMaxHealth()
    local stage = math.ceil((hp / maxHp) * 10)
 
    if not store[cid] or stage < store[cid] then
        store[cid] = stage
        if stages[stage] then
            local spectators = Game.getSpectators(creature:getPosition(), false, true, 7, 7, 5, 5)
            if #spectators > 0 then
                for _, spectator in ipairs(spectators) do
                    spectator:say(stages[stage], TALKTYPE_MONSTER_SAY, false, spectator, creature:getPosition())
                end
            end
        end
    end
 
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end
bossTalkStages:register()
Thanks for trying, but that's not exactly what I was saying... I need the message to appear in the equivalent percentage of the "monster.element" table, not in the monster's life percentage in the game...

The monster.element is a table that certain elements will take more or less damage from a monster based on their percentage that is defined in the table, as shown in the examples I gave above
 
You would have to use monsterType:getElementList() , I think

I'm not exactly sure how it returns data, but it should get you in the right direction.

Lua:
local monsterType = MonsterType("demon")
if not monsterType then
    print("Can't find monster 'demon'")
    return
end
local elementList = monsterType:getElementList()
-- loop through and print info?
 
Back
Top