• 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())...
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
I dont know are you able to fix it or not, but this script is not working properly i tried to kill this monster three times and i got reward just once. First run - Didnt get anything, another dude got reward, Second Run - I got reward, and he got reward or he didnt not sure tho, he said he did but im not trusting him, Third Run - Didnt get anything, but other player got reward. Its not working because you deleted that function if you deal 1% to monster you got reward so if 100players will hit 1% everyone will get reward not just one dude.
 
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()) do
                local player = Player(pid)
                if player and info.total >= percent then
                    player:addExperience(v.expReward, true)
                    player:addMoney(v.goldReward)
                end
            end
        end
    end
    stopEvent(henkasEventOne)
    return true
end

Add to your creaturescripts.xml
XML:
<event type="death"    name="Henkas Death"    script="henkas.lua" />

This goes to globalEvents/scripts/henkas.lua:
Lua:
local function removeBoss(id)
henkasEventOne = addEvent(function(cid)
        if not Monster(cid) then
            return
        end
        Monster(cid):remove()
        broadcastMessage("1 Hour has passed, and no one defeated the Daily Boss!", MESSAGE_EVENT_ADVANCE)
        end, 3600000, id.uid)
    return true
end

function onThink(interval)
local rand = math.random(1, 100)
    if rand <= 10 then
        local creature = monsterSystem[math.random(#monsterSystem)]
        local monster = Game.createMonster(creature.name, creature.pos)
        broadcastMessage("Daily boss has spawned in front of temple!", MESSAGE_EVENT_ADVANCE)
        if monster then
            Creature(monster):registerEvent("Henkas Death")
            removeBoss(monster)
        end
        return true
    end
    return true
end

Add to your globalEvents.xml:
XML:
<globalevent name="Henkas Script" interval="7200000" script="henkas.lua" />
 
Last edited:
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()) do
                local player = Player(pid)
                if player and info.total >= percent then
                    player:addExperience(v.expReward, true)
                    player:addMoney(v.goldReward)
                end
            end
        end
    end
    stopEvent(henkasEventOne)
    return true
end

Add to your creaturescripts.xml
XML:
<event type="death"    name="Henkas Death"    script="henkas.lua" />

This goes to globalEvents/scripts/henkas.lua:
Lua:
local function removeBoss(id)
henkasEventOne = addEvent(function(cid)
    local monster = Monster(cid)
        if monster then
            monster:remove()
            broadcastMessage("1 Hour has passed, and no one defeated the Daily Boss!", MESSAGE_EVENT_ADVANCE)
            return true
        else
            return true
        end
        end, 3600000, id)
end

function onThink(interval)
local rand = math.random(1, 100)
    if rand <= 10 then
        local creature = monsterSystem[math.random(#monsterSystem)]
        local monster = Game.createMonster(creature.name, creature.pos)
        broadcastMessage("Daily boss has spawned in front of temple!", MESSAGE_EVENT_ADVANCE)
        if monster then
            Creature(monster):registerEvent("Henkas Death")
            removeBoss(monster)
        end
        return true
    end
    return true
end

Add to your globalEvents.xml:
XML:
<globalevent name="Henkas Script" interval="7200000" script="henkas.lua" />
Wow looks so clean :eek: haven't tested yet but i think it might work perfectly if not i'll hit you on PM
 
Back
Top