• 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.2+] Kill Monster & Create Portal

J.Dre

Unity Games
Joined
May 18, 2011
Messages
2,647
Solutions
3
Reaction score
648
Location
United States
Hi everyone, just thought I’d release this script as it is often times requested and most of the ones released are somewhat outdated. You may add multiple bosses to this script as well. :) Please post issues below.

You have killed a Demon. You have 5 minutes to escape.
You have defeated Orshabaal! You have 1 minute to escape.

Here is the code!

Creaturescripts.xml
XML:
<event type="kill" name="bossKillEvent" script="bossKill.lua" />

Login.lua
Lua:
player:registerEvent("bossKillEvent")

bossKill.lua

 
Last edited:
There is small bug, p:sendTextMessage(MESSAGE_INFO_DESCR, k.message .. " You have " .. (k.config.portalTime > 1 and "minutes" or "minute") .. " to escape!") won't create message like You have 5 minutes to escape..
 
wow, thanks a lot..
i will sure use it for my Tower of Heaven's (Monster Arena for end game lvls 120+)
 
I'm pretty sure this will spam the text message for however many players actually damaged the monster since you're using the onKill event which executes on each player. You're sending message to the entire damageMap list, so each time someone else's event is executed for their kill all other players including themselves will also get the message again.
 
There is small bug, p:sendTextMessage(MESSAGE_INFO_DESCR, k.message .. " You have " .. (k.config.portalTime > 1 and "minutes" or "minute") .. " to escape!") won't create message like You have 5 minutes to escape..

Good catch. I will fix it tonight unless someone else would like to beforehand.

I'm pretty sure this will spam the text message for however many players actually damaged the monster since you're using the onKill event which executes on each player. You're sending message to the entire damageMap list, so each time someone else's event is executed for their kill all other players including themselves will also get the message again.

When I was using it on my server it sent a message to every player who attacked the monster, as I intended. I don’t believe this was an issue.
 
Good catch. I will fix it tonight unless someone else would like to beforehand.



When I was using it on my server it sent a message to every player who attacked the monster, as I intended. I don’t believe this was an issue.
You'd see it once on screen obviously because you're not using a default-chat specific text type, but in server log it's going to send the same amount of times as the number of people who are in that damage map. The same applies for the portal creation and the scheduled event, it will be creating multiple because onKill isn't a unique 1-person only event.
This doesn't matter technically just out-of-the-box, but I'm just trying to help avoid potential issues if people decide to change the text type.
 
You'd see it once on screen obviously because you're not using a default-chat specific text type, but in server log it's going to send the same amount of times as the number of people who are in that damage map. The same applies for the portal creation and the scheduled event, it will be creating multiple because onKill isn't a unique 1-person only event.
This doesn't matter technically just out-of-the-box, but I'm just trying to help avoid potential issues if people decide to change the text type.

Ah okay, yeah if they change the type of message it may be an issue. Guess I’ll break the loop? Not sure. Tonight I’ll update it.
 
Ah okay, yeah if they change the type of message it may be an issue. Guess I’ll break the loop? Not sure. Tonight I’ll update it.
All you need to do is just remove the message sending to each person in the damage map and send it to killer. The event will execute for all players who damaged it either way so there's no need to do anything with the damage map.
 
Thank you, I like it, but this code does not close the portal.
 
Thank you, I like it, but this code does not close the portal.

It should now, there was a typo. :)


Use the script on Pastebin, not in the main post.
 
It should now, there was a typo. :)


Use the script on Pastebin, not in the main post.

It really didn't work for me.
I registered in login.lua, I declared the respective positions, but when the monster dies, nothing happens.
 
Last edited:
[Warning - Event::checkScript] Can not load script: scripts/bossKill.lua
data/creaturescripts/scripts/bossKill.lua:8: unexpected symbol near '='
 
Lua:
   ["demon"] = {
        message = "You killed a Demon!",
        config = {
            createPos = {x = 100, y = 100, z = 7},
            toPos = {x = 100, y = 100, z = 7},
            portalTime = 5, --minutes  < line 8, comma is wrong
            storage = 123
        }
    },
 
i changed the script a little bit,
I don't want to create another post, so if you allow me, I'll post it right here ...
works on tfs 1.3

scriptbosskill.gif
Lua:
local portalId, t = 1387,
{
    ["Rat"] = {
        message = "You killed a Rat!",
        config = {
            createPos = {x = 0, y = 0, z = 0},
            toPos = {x = 0, y =  0, z = 0},
            portalTime = 2, --minutes
            storage = 123
        }
    }
}

local function removePortal(position)
    local portal = Tile(position):getItemById(portalId)
    if portal then
        portal:remove()
    end
end

function onKill(creature, target)
    if not target:isMonster() or target:getMaster() then
        return true
    end
   
    local player = Player(creature)
    local k = t[target:getName():lower()]
    if not k then
        return true
    end
   
    local pos, cPos = target:getPosition()
    if type(k.config.createPos) == 'table' then
        if next(k.config.createPos) == nil then
            cPos = pos
        else
            cPos = k.config.createPos
        end
    end
    local item = Game.createItem(portalId, 1, cPos)
    if item:isTeleport() then
        item:setDestination(k.config.toPos)
    end

    local pt = k.config.portalTime
    for i, damage in pairs(target:getDamageMap()) do
        local p = Player(i)
        if p then
            if p:getStorageValue(k.config.storage) < 1 then
                p:setStorageValue(k.config.storage, 1)
            end
        end
    end

    local killMessage = k.message .. " You have " .. pt .. " " .. (pt > 1 and "minutes" or "minute") .. " to escape!"
    target:say(killMessage, TALKTYPE_MONSTER_SAY, 0, 0, target:getPosition())
    addEvent(removePortal, pt * 60 * 1000, cPos)
   return true
end
 
local item = Game.createItem(portalId, 1, cPos) if item:isTeleport() then item:setDestination(k.config.toPos) end
I'm using more simple function, which works as intended:
doCreateTeleport(itemid, topos, createpos)
 

Similar threads

Back
Top