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

elite monsters question for tfs 1.2

Jpstafe

Well-Known Member
Joined
Aug 8, 2011
Messages
581
Reaction score
78
Good morning otland community, I want to know how I can make it so that when you kill certain monsters the same monster with a green or red or black skull can spawn... and that each one has its own difficulty? I have searched here in the forum but I didn't find anything, I found a way to put levels on the monsters but not skulls... on my server I was able to put skulls on the monsters:

skui.png

This is an example of what I would like to do:
ejemplo.png
Post automatically merged:

up
 
Last edited:
LUA:
function onKill(cid, target)

    local player = Player(cid)

    local targetName = getCreatureName(target)

    if isMonster(target) then

        local storageKey = "kills_" .. targetName

        local totalKills = player:getStorageValue(storageKey) or 0

        totalKills = totalKills + 1

        player:setStorageValue(storageKey, totalKills)

        local message = player:getName() .. " has killed a " .. targetName .. "! Total monsters killed: " .. totalKills

        for _, targetPlayer in ipairs(Game.getPlayers()) do

            targetPlayer:sendTextMessage(MESSAGE_EVENT_DEFAULT, message)

        end

     

   

    end

    return true

end

edit this add chance and getmonstername and then create monster according to the quality :p i added debugging stuff and totalkills you can make something like % 100 so every 100 it will spawn x monster based on what monster you killed its probably best to have like troll1 troll2 troll3 so u can just add number to the name and it will spawn different level monster
Post automatically merged:

LUA:
function onKill(cid, target)
    -- Get the player who killed the target
    local player = Player(cid)
    -- Get the name of the killed target
    local targetName = getCreatureName(target)

    -- Check if the killed target is a monster
    if isMonster(target) then
        -- Create a storage key specific to the killed monster
        local storageKey = "kills_" .. targetName
        -- Get the total number of kills for the current monster for the player
        local totalKills = player:getStorageValue(storageKey) or 0

        -- Check if totalKills is negative and set it to 0
        if totalKills < 0 then
            totalKills = 0
            player:setStorageValue(storageKey, totalKills)
        end

        -- Increment the kill count for the current monster
        totalKills = totalKills + 1
        player:setStorageValue(storageKey, totalKills)

        -- Construct a message indicating the kill
        local message = player:getName() .. " has killed a " .. targetName .. "! Total monsters killed: " .. totalKills

        -- Send the kill message to all players online
        for _, targetPlayer in ipairs(Game.getPlayers()) do
            targetPlayer:sendTextMessage(MESSAGE_EVENT_DEFAULT, message)
        end

        -- Check if the player has killed a multiple of 200 of the same monster
        if totalKills % 200 == 0 then
            -- Define the second monster to spawn
            local monsterToSpawn = "monstername2"
            -- Get the position of the killed monster
            local targetPosition = target:getPosition()
            -- Spawn the second monster at the position of the killed monster
            Game.createMonster(monsterToSpawn, targetPosition)
            -- Send a message to the player indicating the spawn of the second monster
            player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "Congratulations! You've killed " .. totalKills .. " " .. targetName .. " and summoned " .. monsterToSpawn .. "!")
        end
    end

    -- Always return true to allow the kill event to proceed
    return true
end

sending message to all players online is optional however it is nice feature for Evo otses since Default channel pretty much has no use in this game anyways.
Post automatically merged:

PS chatgpt wrote that.
 
Last edited:
LUA:
function onKill(cid, target)

    local player = Player(cid)

    local targetName = getCreatureName(target)

    if isMonster(target) then

        local storageKey = "kills_" .. targetName

        local totalKills = player:getStorageValue(storageKey) or 0

        totalKills = totalKills + 1

        player:setStorageValue(storageKey, totalKills)

        local message = player:getName() .. " has killed a " .. targetName .. "! Total monsters killed: " .. totalKills

        for _, targetPlayer in ipairs(Game.getPlayers()) do

            targetPlayer:sendTextMessage(MESSAGE_EVENT_DEFAULT, message)

        end

    

  

    end

    return true

end

edit this add chance and getmonstername and then create monster according to the quality :p i added debugging stuff and totalkills you can make something like % 100 so every 100 it will spawn x monster based on what monster you killed its probably best to have like troll1 troll2 troll3 so u can just add number to the name and it will spawn different level monster
Post automatically merged:

LUA:
function onKill(cid, target)
    -- Get the player who killed the target
    local player = Player(cid)
    -- Get the name of the killed target
    local targetName = getCreatureName(target)

    -- Check if the killed target is a monster
    if isMonster(target) then
        -- Create a storage key specific to the killed monster
        local storageKey = "kills_" .. targetName
        -- Get the total number of kills for the current monster for the player
        local totalKills = player:getStorageValue(storageKey) or 0

        -- Check if totalKills is negative and set it to 0
        if totalKills < 0 then
            totalKills = 0
            player:setStorageValue(storageKey, totalKills)
        end

        -- Increment the kill count for the current monster
        totalKills = totalKills + 1
        player:setStorageValue(storageKey, totalKills)

        -- Construct a message indicating the kill
        local message = player:getName() .. " has killed a " .. targetName .. "! Total monsters killed: " .. totalKills

        -- Send the kill message to all players online
        for _, targetPlayer in ipairs(Game.getPlayers()) do
            targetPlayer:sendTextMessage(MESSAGE_EVENT_DEFAULT, message)
        end

        -- Check if the player has killed a multiple of 200 of the same monster
        if totalKills % 200 == 0 then
            -- Define the second monster to spawn
            local monsterToSpawn = "monstername2"
            -- Get the position of the killed monster
            local targetPosition = target:getPosition()
            -- Spawn the second monster at the position of the killed monster
            Game.createMonster(monsterToSpawn, targetPosition)
            -- Send a message to the player indicating the spawn of the second monster
            player:sendTextMessage(MESSAGE_EVENT_DEFAULT, "Congratulations! You've killed " .. totalKills .. " " .. targetName .. " and summoned " .. monsterToSpawn .. "!")
        end
    end

    -- Always return true to allow the kill event to proceed
    return true
end

sending message to all players online is optional however it is nice feature for Evo otses since Default channel pretty much has no use in this game anyways.
Post automatically merged:

PS chatgpt wrote that.
Thanks for providing me with the codes! now I'll try it
 
inside monsters.xml add 3 additional frost dragons, but name them
"Frost Dragon (green)"
"Frost Dragon (red)"
"Frost Dragon (black)"

Copy original frost dragon file and rename, etcetera.. then adjust their values to how you want them. (so they are 'stronger')

Inside the original frost dragon.. (just above loot) put the script trigger
XML:
<script>
    <event name="onDeath_eliteRespawn" />
</script>
in creaturescripts.xml
XML:
<event type="death" name="onDeath_eliteRespawn" script="onDeath_eliteRespawn.lua"/>

and creaturescripts/scripts/
LUA:
local monsters = {
    ["frost dragon"] = {chance = 50, -- make sure to type in lowercase for monster names
        elites = {
            {"frost dragon (green)", effect = CONST_ME_POISONAREA, skullType = SKULL_GREEN}, -- green might not work. try white if it doesn't.
            {"frost dragon (red)", effect = CONST_ME_FIREAREA, skullType = SKULL_RED},
            {"frost dragon (black)", effect = CONST_ME_MORTAREA, skullType = SKULL_BLACK}
        }
    }
}

local function spawnCreatureWithSkull(monsterName, position, skullType)
    local monster = Game.createMonster(monsterName, position, true, true)
    if monster then
        monster:setSkull(skullType)
    end
end

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    if not creature:isMonster() then
        return true
    end
    local monsterName = creature:getName():lower()
    if monsters[monsterName] then
        if math.random(100) <= monsters[monsterName].chance then
            local rand = math.random(#monsters[monsterName].elites)
            local position = creature:getPosition()
            position:sendMagicEffect(monsters[monsterName].elites[rand].effect)
            addEvent(spawnCreatureWithSkull, 333, monsterName, position, monsters[monsterName].elites[rand].skullType)
        end
    end
    return true
end
 
inside monsters.xml add 3 additional frost dragons, but name them
"Frost Dragon (green)"
"Frost Dragon (red)"
"Frost Dragon (black)"

Copy original frost dragon file and rename, etcetera.. then adjust their values to how you want them. (so they are 'stronger')

Inside the original frost dragon.. (just above loot) put the script trigger
XML:
<script>
    <event name="onDeath_eliteRespawn" />
</script>
in creaturescripts.xml
XML:
<event type="death" name="onDeath_eliteRespawn" script="onDeath_eliteRespawn.lua"/>

and creaturescripts/scripts/
LUA:
local monsters = {
    ["frost dragon"] = {chance = 50, -- make sure to type in lowercase for monster names
        elites = {
            {"frost dragon (green)", effect = CONST_ME_POISONAREA, skullType = SKULL_GREEN}, -- green might not work. try white if it doesn't.
            {"frost dragon (red)", effect = CONST_ME_FIREAREA, skullType = SKULL_RED},
            {"frost dragon (black)", effect = CONST_ME_MORTAREA, skullType = SKULL_BLACK}
        }
    }
}

local function spawnCreatureWithSkull(monsterName, position, skullType)
    local monster = Game.createMonster(monsterName, position, true, true)
    if monster then
        monster:setSkull(skullType)
    end
end

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    if not creature:isMonster() then
        return true
    end
    local monsterName = creature:getName():lower()
    if monsters[monsterName] then
        if math.random(100) <= monsters[monsterName].chance then
            local rand = math.random(#monsters[monsterName].elites)
            local position = creature:getPosition()
            position:sendMagicEffect(monsters[monsterName].elites[rand].effect)
            addEvent(spawnCreatureWithSkull, 333, monsterName, position, monsters[monsterName].elites[rand].skullType)
        end
    end
    return true
end
thank you very much it works perfect! tested in tfs 1.5
 
inside monsters.xml add 3 additional frost dragons, but name them
"Frost Dragon (green)"
"Frost Dragon (red)"
"Frost Dragon (black)"

Copy original frost dragon file and rename, etcetera.. then adjust their values to how you want them. (so they are 'stronger')

Inside the original frost dragon.. (just above loot) put the script trigger
XML:
<script>
    <event name="onDeath_eliteRespawn" />
</script>
in creaturescripts.xml
XML:
<event type="death" name="onDeath_eliteRespawn" script="onDeath_eliteRespawn.lua"/>

and creaturescripts/scripts/
LUA:
local monsters = {
    ["frost dragon"] = {chance = 50, -- make sure to type in lowercase for monster names
        elites = {
            {"frost dragon (green)", effect = CONST_ME_POISONAREA, skullType = SKULL_GREEN}, -- green might not work. try white if it doesn't.
            {"frost dragon (red)", effect = CONST_ME_FIREAREA, skullType = SKULL_RED},
            {"frost dragon (black)", effect = CONST_ME_MORTAREA, skullType = SKULL_BLACK}
        }
    }
}

local function spawnCreatureWithSkull(monsterName, position, skullType)
    local monster = Game.createMonster(monsterName, position, true, true)
    if monster then
        monster:setSkull(skullType)
    end
end

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    if not creature:isMonster() then
        return true
    end
    local monsterName = creature:getName():lower()
    if monsters[monsterName] then
        if math.random(100) <= monsters[monsterName].chance then
            local rand = math.random(#monsters[monsterName].elites)
            local position = creature:getPosition()
            position:sendMagicEffect(monsters[monsterName].elites[rand].effect)
            addEvent(spawnCreatureWithSkull, 333, monsterName, position, monsters[monsterName].elites[rand].skullType)
        end
    end
    return true
end

Not working 100%. Someone mentioned there was a small error.

change
LUA:
addEvent(spawnCreatureWithSkull, 333, monsterName, position, monsters[monsterName].elites[rand].skullType)
to
LUA:
addEvent(spawnCreatureWithSkull, 333, monsters[monsterName].elites[rand][1], position, monsters[monsterName].elites[rand].skullType)
 
Not working 100%. Someone mentioned there was a small error.

change
LUA:
addEvent(spawnCreatureWithSkull, 333, monsterName, position, monsters[monsterName].elites[rand].skullType)
to
LUA:
addEvent(spawnCreatureWithSkull, 333, monsters[monsterName].elites[rand][1], position, monsters[monsterName].elites[rand].skullType)
Is there a way that every time an elite monster is generated... depending on whether it is green, red, or black skull... a type of teleport of those colors is generated... and that it blinks two or three times and then is born? as in the photo of the post I made above
 
Is there a way that every time an elite monster is generated... depending on whether it is green, red, or black skull... a type of teleport of those colors is generated... and that it blinks two or three times and then is born? as in the photo of the post I made above
LUA:
local monsters = {
    ["frost dragon"] = {chance = 50, -- make sure to type in lowercase for monster names
        elites = {
            {name = "frost dragon (green)", effect = CONST_ME_POISONAREA, skullType = SKULL_GREEN}, -- green might not work. try white if it doesn't.
            {name = "frost dragon (red)", effect = CONST_ME_FIREAREA, skullType = SKULL_RED},
            {name = "frost dragon (black)", effect = CONST_ME_MORTAREA, skullType = SKULL_BLACK}
        }
    }
}

local function spawnCreatureWithSkull(monsterName, position, skullType, effect, counter)
    if counter < 3 then
        counter = counter + 1
        position:sendMagicEffect(effect)
        addEvent(spawnCreatureWithSkull, 1000, monsterName, position, skullType, effect, counter)
        return
    end
    local monster = Game.createMonster(monsterName, position, true, true)
    if monster then
        monster:setSkull(skullType)
    end
end

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    if not creature:isMonster() then
        return true
    end
    local monsterName = creature:getName():lower()
    if monsters[monsterName] then
        if math.random(100) <= monsters[monsterName].chance then
            local rand = math.random(#monsters[monsterName].elites)
            local position = creature:getPosition()
            local elite = monsters[monsterName].elites[rand]
            addEvent(spawnCreatureWithSkull, 1000, elite.name, position, elite.skullType, elite.effect, 0)
        end
    end
    return true
end
 
hail,in my server the monster appear with skulls but its the same config at de frost dragon stock, i'm create frost dragon green, added on monsters.xml etc but dont change the name and the configs. tfs 1.2
 
LUA:
local monsters = {
    ["frost dragon"] = {chance = 50, -- make sure to type in lowercase for monster names
        elites = {
            {name = "frost dragon (green)", effect = CONST_ME_POISONAREA, skullType = SKULL_GREEN}, -- green might not work. try white if it doesn't.
            {name = "frost dragon (red)", effect = CONST_ME_FIREAREA, skullType = SKULL_RED},
            {name = "frost dragon (black)", effect = CONST_ME_MORTAREA, skullType = SKULL_BLACK}
        }
    }
}

local function spawnCreatureWithSkull(monsterName, position, skullType, effect, counter)
    if counter < 3 then
        counter = counter + 1
        position:sendMagicEffect(effect)
        addEvent(spawnCreatureWithSkull, 1000, monsterName, position, skullType, effect, counter)
        return
    end
    local monster = Game.createMonster(monsterName, position, true, true)
    if monster then
        monster:setSkull(skullType)
    end
end

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    if not creature:isMonster() then
        return true
    end
    local monsterName = creature:getName():lower()
    if monsters[monsterName] then
        if math.random(100) <= monsters[monsterName].chance then
            local rand = math.random(#monsters[monsterName].elites)
            local position = creature:getPosition()
            local elite = monsters[monsterName].elites[rand]
            addEvent(spawnCreatureWithSkull, 1000, elite.name, position, elite.skullType, elite.effect, 0)
        end
    end
    return true
end
hi ::))) as i see the skulled frost dragons is shoud be also custom made monsters in monsters folder right ?

Can it be that First skull is 3x stronger then normal frost (300% increase on this mob, attack, hp, loot, etc),
if second skull is 6x stronger , then normal frost dragon(600%)
third one 10x stronger. <<

To avoid making 10000 bosses xd


Also possible to add for every boss custom possible multiple loot ? would be awesome to edit
 
..
LUA:
local monsters = {
    ["urso"] = {
        chance = 10,
        elites = {
            {
                name = "Urso Enfurecido",
                effect = CONST_ME_TELEPORT,
                skullType = SKULL_GREEN,
                healthMultiplier = 1.2,
                speedBonus = 10
            },
            {
                name = "Urso Faminto",
                effect = CONST_ME_TELEPORT,
                skullType = SKULL_RED,
                healthMultiplier = 1.5,
                speedBonus = 20
            },
        }
    },
    ["anão"] = {
        chance = 10,
        elites = {
            {
                name = "Anão Estressado",
                effect = CONST_ME_TELEPORT,
                skullType = SKULL_GREEN,
                healthMultiplier = 1.2,
                speedBonus = 10
            },
            {
                name = "Anão Furioso",
                effect = CONST_ME_TELEPORT,
                skullType = SKULL_RED,
                healthMultiplier = 1.5,
                speedBonus = 20
            },
        }
    },
    
        ["besouro roxo"] = {
        chance = 10,
        elites = {
            {
                name = "besouro roxo irritado",
                effect = CONST_ME_TELEPORT,
                skullType = SKULL_GREEN,
                healthMultiplier = 1.2,
                speedBonus = 10
            },
            {
                name = "besouro roxo furioso",
                effect = CONST_ME_TELEPORT,
                skullType = SKULL_RED,
                healthMultiplier = 1.5,
                speedBonus = 20
            },
        }
    }
    
    
}

local eliteNames = {}

for _, group in pairs(monsters) do
    for _, elite in ipairs(group.elites) do
        eliteNames[elite.name:lower()] = true
    end
end

local function applyEliteAttributes(uid, elite)
    local monster = Monster(uid)
    if not monster then return end

    monster:setSkull(elite.skullType)

    if elite.healthMultiplier and elite.healthMultiplier > 1 then
        local maxHealth = monster:getMaxHealth()
        monster:setMaxHealth(maxHealth * elite.healthMultiplier)
        monster:addHealth(monster:getMaxHealth())
    end

    if elite.speedBonus and elite.speedBonus ~= 0 then
        monster:changeSpeed(elite.speedBonus)
    end
end

local function spawnCreatureWithSkullAndAttributes(elite, position)
    local monster = Game.createMonster(elite.name, position, true, true)
    if monster then
        addEvent(applyEliteAttributes, 100, monster:getId(), elite)
    end
end

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    if not creature:isMonster() then
        return true
    end

    local creatureName = creature:getName():lower():match("^%s*(.-)%s*$")


    if eliteNames[creatureName] then
        local player = nil
        if killer and killer:isPlayer() then
            player = killer
        elseif mostDamageKiller and mostDamageKiller:isPlayer() then
            player = mostDamageKiller
        end
        if player then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Você recebeu bônus de experiência por derrotar um Elite!")
        end
        return true
    end

 
    local group = monsters[creatureName]
    if group and math.random(100) <= group.chance then
        local elite = group.elites[math.random(#group.elites)]
        local position = creature:getPosition()
        position:sendMagicEffect(elite.effect)
        addEvent(spawnCreatureWithSkullAndAttributes, 333, elite, position)
        
         -- Enviar mensagem de bônus de experiência para o matador
        if killer and killer:isPlayer() then
            killer:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Criatura de Elite Apareceu!")
        elseif mostDamageKiller and mostDamageKiller:isPlayer() then
            mostDamageKiller:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Criatura de Elite Apareceu!")
        end
    end

    return true
end
 

Attachments

It's been always at this post.

So here's the resume, inlcuding other potentially features that you'll seek too:
  • Adding skulls to creatures with level
  • Here's how to add extra experience according to creature level
  • Command to create creature with skull/level
  • Skull randomization
  • Loot increase based on creature level
  • Extra loot depending on HP
 
Back
Top