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

TFS 1.X+ How to modify this event (Two thinks)

henkas

Well-Known Member
Joined
Jul 8, 2015
Messages
989
Solutions
5
Reaction score
54
Using TFS: 1.2

This is how i would like to modify it.
1. Make it 10% chance per 2 hour to respawn (boss)
2. If boss is not killed per 1hour it will be deleted with broadcast (i have this function already but its not convenient because it will delete everything around even if player will stand close so you will be kicked to.
Or it would be great instead of deleting it if monster is not killed do not spawn another boss if that first boss is not killed to avoid couple spawns.
3. Last think if its possible to give exp reward if they deal some dmg to that boss because its not really good to use share exp function on such event like this. So it would be nice to see if everyone would get the same amount exp.

I'll explain how my script works now.
Lua:
local bosses = {
    {bossName = "Test LvL 1", bossPosition = Position(315, 179, 7)},
    {bossName = "Test LvL 2", bossPosition = Position(315, 179, 7)}
}
Bosses = {}

function spawnBoss()
    if #Bosses >= #bosses then
        for i = #Bosses, 1, -1 do
            Bosses[i] = nil
        end
    end

    local creature = bosses[math.random(#bosses)]
    if isInArray(Bosses, creature.bossName) then
        -- print('>> attempt to spawn '..creature.bossName..' again.')
        creature = spawnBoss() -- recursive, call again if name exist
    else
        -- update the global Bosses table with the creature name if it does not exist
        table.insert(Bosses, creature.bossName)
    end
    -- return the local table's return value
    return creature
end
local function removeBoss()
    local center = Position(315, 179, 7)
    local radius = 10
    local monsters = Game.getSpectators(center, false, false, radius, radius, radius, radius)

    if monsters == nil then
        return false
    end

    if #monsters < 0 then
        return false
    end

    for i = 1, #monsters do
        monster = Creature(monsters[i])
        monster:remove()
    end
    broadcastMessage("1 Hour passed and you was not able to defeat the daily boss!", MESSAGE_EVENT_ADVANCE)
    return true
end

function onTime(interval)
    local rand = spawnBoss()
    local monster = Game.createMonster(rand.bossName, rand.bossPosition)
    if not monster then
        print('>> Failed to spawn '..rand.bossName..'.')
        return true
    end
    print('>> The boss: ' ..monster:getName() .. ' spawn.')
    broadcastMessage("Daily boss have been spawned infront of temple!.", MESSAGE_EVENT_ADVANCE)
    return true
    end
        addEvent(removeBoss, 3600000)

Code:
    <globalevent name="SpawnBoss" time="20:00:00" script="spawn.lua" />

So every 20:00 boss randomly between Test LvL 1, Test LvL 2 will be spawned, it will choose one of them to spawn if boss is not killed it will delete that boss with broadcast but as you can see it will delete players to if they stand next to that monster
 
Solution
I didn't like how all the system was done, so I just remade it for you (Taking into consideration that you want all of it in just 1 table):

Add to your data/global.lua:
Lua:
monsterSystem = {
    [1] = {name = "rat", pos = Position(1000, 1000, 7), expReward = 5000, goldReward = 1000},
    [2] = {name = "demon", pos = Position(1000, 1000, 7), expReward = 9000, goldReward = 1000}
}


This goes to creaturescripts/scripts/henkas.lua:
Lua:
function onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    local percent = creature:getMaxHealth() * 0.01
    for k, v in pairs(monsterSystem) do
            if v.name:lower() == creature:getName():lower() then
            for pid, info in pairs(creature:getDamageMap())...
About this local config so how to use it if want to apply different exp to every monster so instead of creating new config is it possible to apply in this local bosses
Lua:
local bosses = {
    {bossName = "Test LvL 1", bossPosition = Position(315, 179, 7)},
    {bossName = "Test LvL 2", bossPosition = Position(315, 179, 7)}
}
?
bump
 
Wow so many bumps. Good persistence.

Yeah, definitely possible.
Easiest way is to check the monster name versus the ones in the table.
(make sure you the ones in the table lowercase. xP)
Lua:
local monsters = {
    [{"please kill me"}] = {experience = 5000, gold = 5000}, -- gold is simply there as an example of stuff you can add.
    [{"rat", "cave rat", "munster"}] = {experience = 5000, gold = 5000}, --gold is not being used currently.
    [{"rotworm", "carrion worm"}] =  {experience = 5000, gold = 5000},
}

function onDeath(monster, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    for v, k in pairs(monsters) do
        if isInArray(v, monster:getName():lower()) then
            local onepercent = monster:getMaxHealth() * 0.01
            for cid, info in pairs(monster:getDamageMap()) do
                local creature = Creature(cid)
                if(creature and info.total >= onepercent) then
                    --this creature has dealt 1% dmg
                           
                    local player = creature:getPlayer()
                    if(player) then
                        player:addExperience(k.experience)
                    end
                end
            end
        end
    end
   
    return true
end
 
Wow so many bumps. Good persistence.

Yeah, definitely possible.
Easiest way is to check the monster name versus the ones in the table.
(make sure you the ones in the table lowercase. xP)
Lua:
local monsters = {
    [{"please kill me"}] = {experience = 5000, gold = 5000}, -- gold is simply there as an example of stuff you can add.
    [{"rat", "cave rat", "munster"}] = {experience = 5000, gold = 5000}, --gold is not being used currently.
    [{"rotworm", "carrion worm"}] =  {experience = 5000, gold = 5000},
}

function onDeath(monster, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    for v, k in pairs(monsters) do
        if isInArray(v, monster:getName():lower()) then
            local onepercent = monster:getMaxHealth() * 0.01
            for cid, info in pairs(monster:getDamageMap()) do
                local creature = Creature(cid)
                if(creature and info.total >= onepercent) then
                    --this creature has dealt 1% dmg
                         
                    local player = creature:getPlayer()
                    if(player) then
                        player:addExperience(k.experience)
                    end
                end
            end
        end
    end
 
    return true
end
Yea a lot :D So about curious about local monsters = { isnt possible to make local monsters in the same local where they are spawned? Inside this local?
Lua:
local bosses = {
    {bossName = "Rat LvL 1", bossPosition = Position(315, 179, 7)},
    {bossName = "Rat LvL 2", bossPosition = Position(315, 179, 7)}
}
 
Yea a lot :D So about curious about local monsters = { isnt possible to make local monsters in the same local where they are spawned? Inside this local?
Lua:
local bosses = {
    {bossName = "Rat LvL 1", bossPosition = Position(315, 179, 7)},
    {bossName = "Rat LvL 2", bossPosition = Position(315, 179, 7)}
}
As for the thread topic (now that I look back..) the above script will provide the experience for the boss killed.
Script #3.

#'s 1 & 2 would be best to have in a different scripts entirely.

Script 1,

Every X amount of time, try to spawn creature_Y in area_Z.

If creature_Y is alive in area_Z, don't attempt to spawn.
If no creature_Y in area_Z, attempt to spawn. (percent chance)
Script 2,

local yy = 0

Every XX amount of time, check area_Z for creature_Y.
If creature_Y in area_Z, yy increases in count.

If yy becomes 10 or above, and no players are in area_Z, then delete creature_Y, and reset yy count to zero.
 
As for the thread topic (now that I look back..) the above script will provide the experience for the boss killed.
Script #3.

#'s 1 & 2 would be best to have in a different scripts entirely.
You mean by different scripts entirely is to make different lua?
 
You mean by different scripts entirely is to make different lua?
What? lol

monster_experience.lua -- creaturescript onKill
spawn_bosses.lua -- probably global is best
remove_bosses.lua -- probably global is best

name your scripts whatever you want.
 
What? lol

monster_experience.lua -- creaturescript onKill
spawn_bosses.lua -- probably global is best
remove_bosses.lua -- probably global is best

name your scripts whatever you want.
"monster_experience.lua -- creaturescript onKill" what do you mean by creaturescript onKill? you mean registerEvent in login.lua?
 
"monster_experience.lua -- creaturescript onKill" what do you mean by creaturescript onKill? you mean registerEvent in login.lua?
Yes.
You register it in login.lua
You create it's own lua file.
You put a line in creaturescripts.xml
 
Yes.
You register it in login.lua
You create it's own lua file.
You put a line in creaturescripts.xml
Error event OnKill not found
Code:
local monsters = {
    [{"Namekjin"}] = {experience = 1500000, gold = 5000}, -- gold is simply there as an example of stuff you can add.
}

function onDeath(monster, corpse, killer, mostDamageKiller, unjustified, mostDamageUnjustified)
    for v, k in pairs(monsters) do
        if isInArray(v, monster:getName():lower()) then
            local onepercent = monster:getMaxHealth() * 0.02
            for cid, info in pairs(monster:getDamageMap()) do
                local creature = Creature(cid)
                if(creature and info.total >= onepercent) then
                    --this creature has dealt 1% dmg
                           
                    local player = creature:getPlayer()
                    if(player) then
                        player:addExperience(k.experience)
                    end
                end
            end
        end
    end
   
    return true
end
Code:
    <event type="kill" name="MvpScore" script="mvpscore.lua"/>
Code:
    player:registerEvent("MvpScore")
 
Lua:
local monsters = {
    [{"Namekjin"}] = {experience = 1500000, gold = 5000}, -- gold is simply there as an example of stuff you can add.
}

function onKill(creature, target)
    for k, v in pairs(monsters) do
        if isInArray(k, target:getName()) then
            creature:addExperience(v.experience)
            creature:addMoney(v.gold)
            return true
        end
    end
    return true
end
 
Back
Top