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

CreatureEvent [TFS 1.2] Boss/Monster Wave System (onDeath)

Jeffro

Alpha
Joined
Jan 17, 2015
Messages
235
Reaction score
262
Location
New York
Detail:
Tested on TFS 1.2 - Works: 06/18/2016
Use this script as you like! If you convert it to any other distributions, share it with this thread.

How The Script Works:
You will have a normal spawn on your map, my case, a bug. On 50% chance when I kill a bug, a poisonous bug(white skull, skull will have to be set in monster file) will spawn on top of that bug. When that poisonous bug is killed, with 50% chance, it will summon a black widow(red skull) on top of the bugs corpse.

Install:
Create a new lua file within your CreatureScripts/Scripts. Copy and past code into lua and save. Register script file in creaturescripts.xml. You will then have to register the eventname within your creaturescript login.lua.

Script:
Here is the script version by tetra20, nothing different, just a clean structure. Thank you, tetra!
Code:
local config = {
["bug"] = {chance = 50000, boss = "Poisonous Bug", msg = "Kreekkk!"}, --50k = 50%
["poisonous bug"] = {chance = 50000, boss = "Black Widow", msg = "Ribbbiitttt!"}, --25k = 25%
}

function onDeath(creature, target, player, corpse, mostDamage)
local random_chance = math.random(100000)
local targetPosition = target:getPosition()
if creature:isMonster() then
local Monster = config[creature:getName():lower()]
if Monster then
if Monster.chance >= random_chance then
target:getPosition():sendMagicEffect(CONST_ME_POFF)
Game.createMonster(Monster.boss:lower(), targetPosition)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, Monster.msg)
end
end
end
return true
end
 
Last edited:
Code:
local l = {
  ["bug"] = {chance = 50000, boss = "Poisonous Bug", msg = "Kreekkk!"}, --50k = 50%
  ["poisonous bug"] = {chance = 50000, boss = "Black Widow", msg = "Ribbbiitttt!"}, --25k = 25%
}

function onDeath(creature, target, player, corpse, mostDamage)

local k = creature:getName():lower()
local j = math.random(100000)
local h = target:getPosition()
  if not creature:isMonster() then return true end --check if creature/monster
local i = l[k]
  if not k == i then return true end --check if creature/monster is in list
  if i.chance <= j then return true end

target:getPosition():sendMagicEffect(CONST_ME_POFF)
Game.createMonster(i.boss:lower(), h)
player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, i.msg)
end


What a mess, xD.
 
Last edited:
Well use names instead of letters for your variables, that should clean it up
like this
Code:
local config = {
  ["bug"] = {chance = 50000, boss = "Poisonous Bug", msg = "Kreekkk!"}, --50k = 50%
  ["poisonous bug"] = {chance = 50000, boss = "Black Widow", msg = "Ribbbiitttt!"}, --25k = 25%
}

function onDeath(creature, target, player, corpse, mostDamage)
local random_chance = math.random(100000)
local targetPosition = target:getPosition()
   if creature:isMonster() then
     local Monster = config[creature:getName():lower()]
     if Monster then
         if Monster.chance >= random_chance then
             target:getPosition():sendMagicEffect(CONST_ME_POFF)
             Game.createMonster(Monster.boss:lower(), targetPosition)
             player:sendTextMessage(MESSAGE_STATUS_CONSOLE_RED, Monster.msg)
         end
     end
   end
   return true
end

And tab it, Anyway Great job xD
 
Hello, i'm trying to use it but it does not work D:
login.lua

Lua:
function onLogin(player)
    local loginStr = "Welcome to " .. configManager.getString(configKeys.SERVER_NAME) .. "!"
    if player:getLastLoginSaved() <= 0 then
        loginStr = loginStr .. " Please choose your outfit."
        player:sendOutfitWindow()
    else
        if loginStr ~= "" then
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
        end

        loginStr = string.format("Your last visit was on %s.", os.date("%a %b %d %X %Y", player:getLastLoginSaved()))
    end
    player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)

    -- Stamina
    nextUseStaminaTime[player.uid] = 0

    -- Promotion
    local vocation = player:getVocation()
    local promotion = vocation:getPromotion()
    if player:isPremium() then
        local value = player:getStorageValue(STORAGEVALUE_PROMOTION)
        if not promotion and value ~= 1 then
            player:setStorageValue(STORAGEVALUE_PROMOTION, 1)
        elseif value == 1 then
            player:setVocation(promotion)
        end
    elseif not promotion then
        player:setVocation(vocation:getDemotion())
    end

    -- Events
    player:registerEvent("PlayerDeath")
    player:registerEvent("DropLoot")
    player:registerEvent("criticoMonstros")
    player:registerEvent("multiMonstros")

    return true
end

creatureScripts

Lua:
<?xml version="1.0" encoding="UTF-8"?>
<creaturescripts>
    <event type="login" name="PlayerLogin" script="login.lua" />
    <event type="logout" name="PlayerLogout" script="logout.lua" />
    <event type="login" name="FirstItems" script="firstitems.lua" />
    <event type="login" name="OfflineTraining" script="offlinetraining.lua" />
    <event type="login" name="RegenerateStamina" script="regeneratestamina.lua" />
    <event type="death" name="PlayerDeath" script="playerdeath.lua" />
    <event type="death" name="DropLoot" script="droploot.lua" />
    <event type="extendedopcode" name="ExtendedOpcode" script="extendedopcode.lua" />

  <!-- Monstros -->
  <event type="death" name="multiMonstros" script="multiMonstros.lua" />
 
  <!-- Critico/Dodge -->
  <event type="HealthChange" name="criticoMonstros" script="criticoMonstros.lua" />
 
  <!-- Loot Encantado -->
  <event type="login" name="statLogin" script="stats.lua"/>
  <event type="healthchange" name="statHP" script="stats.lua"/>
  <event type="manachange" name="statMP" script="stats.lua"/>
  <event type="preparedeath" name="statPVE" script="stats.lua"/>
  <event type="kill" name="statLoot" script="stats.lua"/>
  <event type="death" name="statDeath" script="stats.lua"/>

  <!-- Sistema de Fome -->
  <event type="login" name="HungerLogin" script="hunger.lua" />
  <event type="death" name="HungerDeath" script="hunger.lua" />
  <event type="think" name="Hunger" script="hunger.lua" />
</creaturescripts>
 
The script will never work @Lubinho Fit since its not well coded.

Either you use onDeath and register it to the monster. (So when the monster dies another have the chance to spawn)
or you use onKill and then register it to the player on login.lua. (So when the player kills the monster it has a chance to spawn)

Register onDeath on player, only means when player die, so it doesnt have much sense!
Anyway, good job with the idea.
 
The script will never work @Lubinho Fit since its not well coded.

Either you use onDeath and register it to the monster. (So when the monster dies another have the chance to spawn)
or you use onKill and then register it to the player on login.lua. (So when the player kills the monster it has a chance to spawn)

Register onDeath on player, only means when player die, so it doesnt have much sense!
Anyway, good job with the idea.
For anyone who wants my "fix" just register it as kill

creaturescripts.xml register
<event type="kill" name="multiMonstros" script="multiMonstros.lua" />

login register
player:registerEvent("multiMonstros")

put inside creature scripts\scripts multiMonstros.lua

Lua:
local config = {
["necromancer"] = {chance = 95000, boss = "demon", msg = "Kreekkk!"}, --50k = 50%
["bug"] = {chance = 95000, boss = "bug", msg = "Ribbbiitttt!"}, --25k = 25%
["exp"] = {chance = 95000, boss = "dragon", msg = "Ribbbiitttt!"}, --25k = 25%
}
function onKill(creature, target, player)

    --print("Enter Function")
    local random_chance = math.random(10000)
    local targetPosition = target:getPosition()
        if target:isMonster() then
        --print("Checking Target")
          local Monster = config[getCreatureName(target):lower()]
        --print(Monster.boss)
            if Monster then
            --print("Checking Name")
                if Monster.chance >= random_chance then
                --print("Summon")
                target:getPosition():sendMagicEffect(CONST_ME_POFF)
                Game.createMonster(Monster.boss:lower(), targetPosition)
                target:say(Monster.msg, TALKTYPE_MONSTER_SAY)
            end
        end
    end
return true
end
 
Back
Top