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

Lua After kill mob teleport appears -PROBLEM-

equero

New Member
Joined
Feb 22, 2013
Messages
51
Reaction score
1
Hello.
I have just read these post and nothing works.
I mean teleport's not showing after monster kill.
Can someone resolve this problem. I'm done...
I have found on my old server this code but he does not work tho.
sorry for my english

Lua:
function onDeath(cid, corpse, killer)
registerCreatureEvent(cid, "Grand War Golem")
local creaturename = getCreatureName(cid)
--- place where tp will be created
local pos1 = {x=788, y=1213, z=10, stackpos=2}
--- position to teleport?:
local pos2 = {x=796, y=1242, z=7, stackpos=1}
local time_to_pass = 180 -- time to disappear
local tpID = 5023
local doEffect = CONST_ME_ENERGYHIT
local message = "Done! You got 3 mins.."
if creaturename == 'Grand War Golem' then
teleport = doCreateTeleport(tpID, pos2, pos1)
doSendMagicEffect(pos1, doEffect)
doCreatureSay(cid, message, TALKTYPE_ORANGE_1)
addEvent(removeTeleportInBossWard, (1000*time_to_pass))
end
end
function removeTeleportInBossWard()
--- place where tp will be created
if getThingfromPos({x=788, y=1213, z=10, stackpos=1}).itemid == 5023 then
--- miejsce gdzie tp zostanie utworzone
doRemoveItem(getThingfromPos({x=788, y=1213, z=10, stackpos=1}).uid,1)
--- place where tp will be created
doSendMagicEffect({x=788, y=1213, z=10, stackpos=1}, CONST_ME_POFF)
return TRUE
end
end

XML:
<event type="death" name="Grand War Golem" script="grand war golem.lua"/>
 
Solution
E
have you registered the script on the monster .xml file?

XML:
<script>
        <event name="Grand War Golem" />
    </script>
For TFS1.2:
Lua:
-- in creaturescripts.xml add:
-- <event type="kill" name="BossKill" script="BossKill.lua" />

-- in login.lua add:
-- player:registerEvent("BossKill")

local teleportToPosition = Position(1000, 1000, 7)
local teleportCreatePosition = Position(2000, 2000, 7)
local bossName = "boss monster"
local killMessage = "You have killed Boss Monster! A teleport has been created but it will disappear in 5 minutes!"

-- Function that will remove the teleport after a given time
local function removeTeleport(position)
    local teleportItem = Tile(position):getItemById(1387)
    if teleportItem then
        teleportItem:remove()
        position:sendMagicEffect(CONST_ME_POFF)
    end
end

function onKill(creature, target)
    if target:isPlayer() or target:getMaster()  or target:getName():lower() ~= bossName then
        return true
    end

    local position = target:getPosition()
    position:sendMagicEffect(CONST_ME_TELEPORT)
    local item = Game.createItem(1387, 1, teleportCreatePosition)
    if item:isTeleport() then
        item:setDestination(teleportToPosition)
    end
    target:say(killMessage, TALKTYPE_MONSTER_SAY, 0, 0, position)

    -- Remove portal after 5 minutes
    addEvent(removeTeleport, 5 * 60 * 1000, position)

    return true
end

For TFS1.3+ Revscriptsys
Lua:
-- Boss teleport spawn script by mdwilliams.
-- https://otland.net/threads/tfs-1-2-portal-created-on-monster-death.265567/#post-2567024
-- Converted to TFS 1.3 Revscriptsys by Evil Hero.

local teleportToPosition = Position(1000, 1000, 7)
local teleportCreatePosition = Position(2000, 2000, 7)
local bossName = "boss monster"
local killMessage = "You have killed Boss Monster! A teleport has been created but it will disappear in 5 minutes!"

-- Function that will remove the teleport after a given time
local function removeTeleport(position)
    local teleportItem = Tile(position):getItemById(1387)
    if teleportItem then
        teleportItem:remove()
        position:sendMagicEffect(CONST_ME_POFF)
    end
end

local event = CreatureEvent("BossKill")

function event.onKill(creature, target)
    if target:isPlayer() or target:getMaster()  or target:getName():lower() ~= bossName then
        return true
    end

    local position = target:getPosition()
    position:sendMagicEffect(CONST_ME_TELEPORT)
    local item = Game.createItem(1387, 1, teleportCreatePosition)

    if item:isTeleport() then
        item:setDestination(teleportToPosition)
    end

    target:say(killMessage, TALKTYPE_MONSTER_SAY, 0, 0, position)

    -- Remove portal after 5 minutes
    addEvent(removeTeleport, 5 * 60 * 1000, position)

    return true
end

event:register()

local login = CreatureEvent("RegisterBossKill")

function login.onLogin(player)
    player:registerEvent("BossKill")
    return true
end

login:register()
 
As you can see
XML:
<?xml version="1.0" encoding="UTF-8"?>
<monster name="Grand War Golem" nameDescription="a war golem" race="energy" experience="2550" speed="680" manacost="0">
    <health now="9300" max="9300"/>
    <look type="326" corpse="10005"/>
    <targetchange interval="5000" chance="8"/>
    <strategy attack="100" defense="0"/>
    <flags>
        <flag summonable="0"/>
        <flag attackable="1"/>
        <flag hostile="1"/>
        <flag illusionable="0"/>
        <flag convinceable="0"/>
        <flag pushable="0"/>
        <flag canpushitems="1"/>
        <flag canpushcreatures="1"/>
        <flag targetdistance="1"/>
        <flag staticattack="90"/>
        <flag runonhealth="0"/>
    </flags>
    <script>
        <event name="Grand War Golem" />
    </script>
    <attacks>
        <attack name="melee" interval="2000" min="-0" max="-280"/>
        <attack name="energy" interval="1000" chance="7" range="7" min="-0" max="-220">
            <attribute key="shootEffect" value="energy"/>
        </attack>
        <attack name="energy" interval="2000" chance="25" length="8" spread="0" min="-0" max="-280">
            <attribute key="areaEffect" value="energy"/>
        </attack>
        <attack name="outfit" interval="1000" chance="9" range="7" monster="skeleton" duration="5000">
            <attribute key="areaeffect" value="blueshimmer"/>
        </attack>
    </attacks>
    <defenses armor="40" defense="45">
        <defense name="speed" interval="1000" chance="7" speedchange="290" duration="4000">
            <attribute key="areaEffect" value="redshimmer"/>
        </defense>
        <defense name="healing" interval="1000" chance="25" min="200" max="400">
            <attribute key="areaEffect" value="blueshimmer"/>
        </defense>
    </defenses>
    <elements>
        <element earthPercent="50"/>
        <element holyPercent="30"/>
        <element firePercent="45"/>
        <element energyPercent="35"/>
        <element physicalPercent="40"/>
        <element icePercent="25"/>
        <element deathPercent="30"/>
    </elements>
    <immunities>
        <immunity invisible="1"/>
        <immunity paralyze="1"/>
    </immunities>
    <voices interval="2500" chance="10">
        <voice sentence="Azerus barada nikto!"/>
        <voice sentence="Klonk klonk klonk"/>
        <voice sentence="Engaging Enemy!"/>
        <voice sentence="Threat level processed."/>
        <voice sentence="Charging weapon systems!"/>
        <voice sentence="Auto repair in progress."/>
        <voice sentence="The battle is joined!"/>
        <voice sentence="Termination initialized!"/>
        <voice sentence="Rrrtttarrrttarrrtta"/>       
    </voices>
    <script>
    <event name="Grand War Golem"/>
    </script>
    <loot>
        <item id="8309" countmax="5" chance="50000"/><!-- nails -->
        <item id="2148" countmax="170" chance="100000"/><!-- gold coin -->
        <item id="1987" chance="100000"><!-- bag -->
            <inside>
                <item id="7893" chance="400"/><!-- lightning boots -->
                <item id="9980" chance="300"/><!-- crystal of power -->
                <item id="2645" chance="400"/><!-- steel boots -->
                <item id="5880" chance="20000"/><!-- iron ore -->
                <item id="7403" chance="250"/><!-- berserker -->
                <item id="7422" chance="250"/><!-- jade hammer -->
            </inside>
        </item>
    </loot>
</monster>
XML:
<event type="death" name="Grand War Golem" script="grand war golem.lua"/>

[Warning - Monster::Monster] Unknown event name - Grand War Golem
As you can see they are the same and still i have the same error or i made something wrong maybe?
Post automatically merged:

i added jet this lane
registerCreatureEvent(cid, "Grand War Golem")
but still the same.
 
Ive got the same problem, did you solve it?
Post automatically merged:

[Warning - Event::checkScript] Event onDeath not found. scripts/BossKill.lua
 
Ive got the same problem, did you solve it?
Post automatically merged:

[Warning - Event::checkScript] Event onDeath not found. scripts/BossKill.lua


Are you registering the event? Either in revscriptsys or login.lua? (depending on how are you doing this)
 
I have TFS 1.3, i tried doing it in Login.lua using
XML:
player:registerEvent("BossKill")

And also the BossKill Script...
and registred it in creaturescripts.xml as
XML:
    <event type="kill" name="BossKill" script="BossKill.lua" />

and here is the bosskill.lua
Lua:
-- in creaturescripts.xml add:
-- <event type="kill" name="BossKill" script="BossKill.lua" />

-- in login.lua add:
-- player:registerEvent("BossKill")

local teleportToPosition = Position(1027, 1179, 7)
local teleportCreatePosition = Position(1031, 1173, 6)
local bossName = "Bazir"
local killMessage = "You have killed The Bazir! A teleport has been created but it will disappear in 5 minutes!"

-- Function that will remove the teleport after a given time
local function removeTeleport(position)
    local teleportItem = Tile(position):getItemById(1387)
    if teleportItem then
        teleportItem:remove()
        position:sendMagicEffect(CONST_ME_POFF)
    end
end

function onKill(creature, target)
    if target:isPlayer() or target:getMaster()  or target:getName():lower() ~= bossName then
        return true
    end

    local position = target:getPosition()
    position:sendMagicEffect(CONST_ME_TELEPORT)
    local item = Game.createItem(1387, 1, teleportCreatePosition)
    if item:isTeleport() then
        item:setDestination(teleportToPosition)
    end
    target:say(killMessage, TALKTYPE_MONSTER_SAY, 0, 0, position)

    -- Remove portal after 5 minutes
    addEvent(removeTeleport, 5 * 60 * 1000, position)

    return true
end

Post automatically merged:

Killing the bazir doesnt gives any error in console and it doesnt spawn a teleport ingame... did i do something wrong or doesnt the script work for TFS 1.3?
Post automatically merged:

Also this is in my Bazir.xml monsterscript
XML:
    <script>
    <event name="BossKill" />
    </script>
Post automatically merged:

Are you registering the event? Either in revscriptsys or login.lua? (depending on how are you doing this)
Am i missing something?
 
Last edited:
Try this. Bazir.xml shouldn't need the event part

Lua:
local teleportToPosition = Position(X, Y, Z) -- coords where teleport takes you

local function removeTeleport(position)
    local teleportItem = Tile(position):getItemById(17868)
    if teleportItem then
        teleportItem:remove()
        position:sendMagicEffect(CONST_ME_POFF)
    end
end

function onKill(creature, target)
    local targetMonster = target:getMonster()
    if not targetMonster or targetMonster:getName():lower() ~= 'MONSTERNAME' then -- add monster name
        return true
    end

    local position = Position(X, Y, Z) -- coords where teleport spawn
    position:sendMagicEffect(    CONST_ME_TELEPORT)
    local item = Game.createItem(17868, 1, position) -- change teleport ID if needed
    if item:isTeleport() then
        item:setDestination(teleportToPosition)
    end
    targetMonster:say('Take the teleport before it/s too late!', TALKTYPE_MONSTER_SAY, 0, 0, position) -- edit message if needed

    --remove portal after 2 min, change as needed
    addEvent(removeTeleport, 2 * 60 * 1000, position)
    return true
end
 
I have TFS 1.3, i tried doing it in Login.lua using
XML:
player:registerEvent("BossKill")

And also the BossKill Script...
and registred it in creaturescripts.xml as
XML:
    <event type="kill" name="BossKill" script="BossKill.lua" />

and here is the bosskill.lua
Lua:
-- in creaturescripts.xml add:
-- <event type="kill" name="BossKill" script="BossKill.lua" />

-- in login.lua add:
-- player:registerEvent("BossKill")

local teleportToPosition = Position(1027, 1179, 7)
local teleportCreatePosition = Position(1031, 1173, 6)
local bossName = "Bazir"
local killMessage = "You have killed The Bazir! A teleport has been created but it will disappear in 5 minutes!"

-- Function that will remove the teleport after a given time
local function removeTeleport(position)
    local teleportItem = Tile(position):getItemById(1387)
    if teleportItem then
        teleportItem:remove()
        position:sendMagicEffect(CONST_ME_POFF)
    end
end

function onKill(creature, target)
    if target:isPlayer() or target:getMaster()  or target:getName():lower() ~= bossName then
        return true
    end

    local position = target:getPosition()
    position:sendMagicEffect(CONST_ME_TELEPORT)
    local item = Game.createItem(1387, 1, teleportCreatePosition)
    if item:isTeleport() then
        item:setDestination(teleportToPosition)
    end
    target:say(killMessage, TALKTYPE_MONSTER_SAY, 0, 0, position)

    -- Remove portal after 5 minutes
    addEvent(removeTeleport, 5 * 60 * 1000, position)

    return true
end

Post automatically merged:

Killing the bazir doesnt gives any error in console and it doesnt spawn a teleport ingame... did i do something wrong or doesnt the script work for TFS 1.3?
Post automatically merged:

Also this is in my Bazir.xml monsterscript
XML:
    <script>
    <event name="BossKill" />
    </script>
Post automatically merged:


Am i missing something?

Just incase. Use lower case to set the boss name.
 
Try this. Bazir.xml shouldn't need the event part

Lua:
local teleportToPosition = Position(X, Y, Z) -- coords where teleport takes you

local function removeTeleport(position)
    local teleportItem = Tile(position):getItemById(17868)
    if teleportItem then
        teleportItem:remove()
        position:sendMagicEffect(CONST_ME_POFF)
    end
end

function onKill(creature, target)
    local targetMonster = target:getMonster()
    if not targetMonster or targetMonster:getName():lower() ~= 'MONSTERNAME' then -- add monster name
        return true
    end

    local position = Position(X, Y, Z) -- coords where teleport spawn
    position:sendMagicEffect(    CONST_ME_TELEPORT)
    local item = Game.createItem(17868, 1, position) -- change teleport ID if needed
    if item:isTeleport() then
        item:setDestination(teleportToPosition)
    end
    targetMonster:say('Take the teleport before it/s too late!', TALKTYPE_MONSTER_SAY, 0, 0, position) -- edit message if needed

    --remove portal after 2 min, change as needed
    addEvent(removeTeleport, 2 * 60 * 1000, position)
    return true
end
This didnt work either..? hmmm something seems very wrong, why doesnt anything works
Post automatically merged:

Now i get this error with your script @BahamutxD
Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/BossKill.lua:onKill
data/creaturescripts/scripts/BossKill.lua:11: attempt to call method 'getMonster                     ' (a nil value)
stack traceback:
        [C]: in function 'getMonster'
        data/creaturescripts/scripts/BossKill.lua:11: in function <data/creature                     scripts/scripts/BossKill.lua:10>
Post automatically merged:

The scripts I posted are working for others >.<
I don't know why you have this in your Bazir.xml though (It's not part of TFS 1.3 Bazir.xml) - remove it.
XML:
    <script>
    <event name="BossKill" />
    </script>

Lmao it was the upper case letter B that was the problem :D
Bazir to bazir... XD
Anyways thx guys, i use your script and it works now @mdwilliams

Seems like the teleport wont dissapear though..
 
Last edited:
I've noticed that for SOME bosses the teleport wont disappear, and I am not sure why. This was first reported to me by Nugo the creator & hoster of Nutopia.
I haven't had a chance to investigate this further, but it could be a stackpos issue? If anyone else wants to weigh in on this?
 
I've noticed that for SOME bosses the teleport wont disappear, and I am not sure why. This was first reported to me by Nugo the creator & hoster of Nutopia.
I haven't had a chance to investigate this further, but it could be a stackpos issue? If anyone else wants to weigh in on this?

Some bosses ??

Here's working example for 1.3

data/creaturescripts/scripts/nin.lua
Lua:
local enemyNames = {
    [1] = "Bazir",
    [2] = "Bazir's dad"
}

local function removeTeleport(position)
    local spawnedTeleport = Tile(position):getItemById(17868)
    if spawnedTeleport then
        spawnedTeleport:remove()
        position:sendMagicEffect(CONST_ME_POFF)
    end
   
    return true
end

local function formatString(s)
    s = string.gsub(s, "[%d%p%c%s]", "")
    s = s:lower()
   
    return s
end

function onKill(creature, target)
    if not target or not target:isMonster() then
        return true
    end
   
    local f = false
    local t = formatString(target:getName())
    for _, v in ipairs(enemyNames) do
        if t == formatString(v) then
            f = true
        end
    end
   
    if not f then
        return true
    end

    local teleportSpawn = Position(2181, 1220, 7) -- Position for teleport to spawn
    removeTeleport(teleportSpawn)
    teleportSpawn:sendMagicEffect(CONST_ME_TELEPORT)
   
    local item = Game.createItem(17868, 1, teleportSpawn)
    if item:isTeleport() then
        local teleportTo = Position(2177, 1222, 7) -- Teleport destination
        item:setDestination(teleportTo)
    end

    target:say('Take the teleport before it/s too late!', TALKTYPE_MONSTER_SAY, 0, 0, teleportSpawn)
    addEvent(removeTeleport, 60000, teleportSpawn)
   
    return true
end

data/creaturescripts/scripts/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(PlayerStorageKeys.promotion)
        if not promotion and value ~= 1 then
            player:setStorageValue(PlayerStorageKeys.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("nin")
    return true
end


data/creaturescripts/creaturescripts.xml (Add at the top after '<creaturescripts>' line)
XML:
<event type="kill" name="nin" script="nin.lua" />
 
Last edited:
Some bosses ??

Here's working example for 1.3

data/creaturescripts/scripts/nin.lua
Lua:
local enemyNames = {
    [1] = "Bazir",
    [2] = "Bazir's dad"
}

local function removeTeleport(position)
    local spawnedTeleport = Tile(position):getItemById(17868)
    if spawnedTeleport then
        spawnedTeleport:remove()
        position:sendMagicEffect(CONST_ME_POFF)
    end
  
    return true
end

local function formatString(s)
    s = string.gsub(s, "[%d%p%c%s]", "")
    s = s:lower()
  
    return s
end

function onKill(creature, target)
    if not target or not target:isMonster() then
        return true
    end
  
    local f = false
    local t = formatString(target:getName())
    for _, v in ipairs(enemyNames) do
        if t == formatString(v) then
            f = true
        end
    end
  
    if not f then
        return true
    end

    local teleportSpawn = Position(2181, 1220, 7) -- Position for teleport to spawn
    removeTeleport(teleportSpawn)
    teleportSpawn:sendMagicEffect(CONST_ME_TELEPORT)
  
    local item = Game.createItem(17868, 1, teleportSpawn)
    if item:isTeleport() then
        local teleportTo = Position(2177, 1222, 7) -- Teleport destination
        item:setDestination(teleportTo)
    end

    target:say('Take the teleport before it/s too late!', TALKTYPE_MONSTER_SAY, 0, 0, teleportSpawn)
    addEvent(removeTeleport, 60000, teleportSpawn)
  
    return true
end

data/creaturescripts/scripts/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(PlayerStorageKeys.promotion)
        if not promotion and value ~= 1 then
            player:setStorageValue(PlayerStorageKeys.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("nin")
    return true
end


data/creaturescripts/creaturescripts.xml (Add at the top after '<creaturescripts>' line)
XML:
<event type="kill" name="nin" script="nin.lua" />
Tried your script now, and the teleport or the message doesnt even appear at all now..
 
Tried your script now, and the teleport or the message doesnt even appear at all now..

@jo31 The script has been tested against clean TFS 1.3 version with 10.98 client and it was working completely fine. I have no idea what sort of configuration you have there
 
@jo31 The script has been tested against clean TFS 1.3 version with 10.98 client and it was working completely fine. I have no idea what sort of configuration you have there
Do you think i need to recompile Or Maybe change The tfs?
Post automatically merged:

@mackerel could you link The TFS1.3 so i can try to change?
 
Back
Top