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

Kill boss, get teleported, only one player allowed 1.2

bybbzan

mapper
Joined
Aug 4, 2012
Messages
809
Solutions
2
Reaction score
135
Location
Sweden
Hello!

As the title sais. I would be so happy if anyone could make this script for me.
Using TFS 1.2

You enter a teleport, when entering, a boss will spawn, when you kill boss, you get teleported
to the reward room. Only one player is allowed at the time.

Thanks in advance.
 
Solution
can be made much simpler.
onKill will keep firing each time you kill something in sarah's script because the event never gets unregistered, onDeath is better to use here and register it directly to the boss
Lua:
-- <event type="death" name="boss death" script="filename.lua"/>

local rewardRoom = Position(x, y, z)

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified)
    killer:teleportTo(rewardRoom)
    rewardRoom:sendMagicEffect(CONST_ME_TELEPORT)
    killer:unregisterEvent("bossroom death")
    bossRoom.player = nil
    bossRoom.boss = nil
    return true
end

Lua:
-- <movevent event="StepIn" actionid="77745" script="filename.lua"/>

local cfg = {
    destination = Position(x, y, z),
    boss = {...
for example:
> movements script teleport enter
Lua:
local config = {
    position = { x = 82, y = 369, z = 6 },
    destination = { x = 84, y = 374, z = 7 },
    item_enable_id = 1481,
    item_disable_id = 1485,
    boss_name = 'Demon',
   boss_position = Position(0, 0, 0)
}

function onStepIn(player, item, position, fromPos)
if isPlayer(player) then
local coal_basin = getTileItemById(config.position, config.item_enable_id)
if coal_basin then
if coal_basin.itemid == config.item_enable_id then
doPlayerSendTextMessage(player, MESSAGE_EVENT_DEFAULT, 'Sorry, not posible.')
doTeleportThing(player, fromPos)
doSendMagicEffect(fromPos, CONST_ME_TELEPORT)
return true
end end
doTransformItem(coal_basin.uid, config.item_enable_id)
doTeleportThing(player, config.destination)
doSendMagicEffect(config.destination, CONST_ME_TELEPORT)
doSummonCreature(config.boss_name, config.boss_position)
player:registerEvent("boss_onkill")
end
return true
end

boss_onKillBoss = function(player, name)
local boss_name = config.boss_name
local name = name
if name == boss_name then
doPlayerSendTextMessage(player, MESSAGE_INFO_DESCR, 'Has eliminado al boss.')
local nextPosReward= Position(0, 0, 0)
doTeleportThing(player, nextPosReward)
doSendMagicEffect(nextPosReward, CONST_ME_TELEPORT)
local coal_basin = getTileItemById(config.position, config.item_enable_id)
if coal_basin then
if coal_basin.itemid == config.item_enable_id then
doTransformItem(coal_basin.uid, config.item_disable_id)
return true
end end
end
return true
end

and creaturescripts:
Lua:
function onKill(player, target)
local name_boss = getCreatureName(target)
boss_onKillBoss(player, name_boss)
return true
end

for TFS 0.4 to 1.2
 
for example:
> movements script teleport enter
Lua:
local config = {
    position = { x = 82, y = 369, z = 6 },
    destination = { x = 84, y = 374, z = 7 },
    item_enable_id = 1481,
    item_disable_id = 1485,
    boss_name = 'Demon',
   boss_position = Position(0, 0, 0)
}

function onStepIn(player, item, position, fromPos)
if isPlayer(player) then
local coal_basin = getTileItemById(config.position, config.item_enable_id)
if coal_basin then
if coal_basin.itemid == config.item_enable_id then
doPlayerSendTextMessage(player, MESSAGE_EVENT_DEFAULT, 'Sorry, not posible.')
doTeleportThing(player, fromPos)
doSendMagicEffect(fromPos, CONST_ME_TELEPORT)
return true
end end
doTransformItem(coal_basin.uid, config.item_enable_id)
doTeleportThing(player, config.destination)
doSendMagicEffect(config.destination, CONST_ME_TELEPORT)
doSummonCreature(config.boss_name, config.boss_position)
player:registerEvent("boss_onkill")
end
return true
end

boss_onKillBoss = function(player, name)
local boss_name = config.boss_name
local name = name
if name == boss_name then
doPlayerSendTextMessage(player, MESSAGE_INFO_DESCR, 'Has eliminado al boss.')
local nextPosReward= Position(0, 0, 0)
doTeleportThing(player, nextPosReward)
doSendMagicEffect(nextPosReward, CONST_ME_TELEPORT)
local coal_basin = getTileItemById(config.position, config.item_enable_id)
if coal_basin then
if coal_basin.itemid == config.item_enable_id then
doTransformItem(coal_basin.uid, config.item_disable_id)
return true
end end
end
return true
end

and creaturescripts:
Lua:
function onKill(player, target)
local name_boss = getCreatureName(target)
boss_onKillBoss(player, name_boss)
return true
end

for TFS 0.4 to 1.2

So, i guess i need coal basin's.. lol :p
 
If it is clear so that it is easier and faster, you can put it very far and hidden, in this case it will be like a physical variable ejjeje
You can also use global variables but it's the same
:p
 
If it is clear so that it is easier and faster, you can put it very far and hidden, in this case it will be like a physical variable ejjeje
You can also use global variables but it's the same
:p

But i suppose this prevents other players to enter the teleport at the same time? :p
 
can be made much simpler.
onKill will keep firing each time you kill something in sarah's script because the event never gets unregistered, onDeath is better to use here and register it directly to the boss
Lua:
-- <event type="death" name="boss death" script="filename.lua"/>

local rewardRoom = Position(x, y, z)

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified)
    killer:teleportTo(rewardRoom)
    rewardRoom:sendMagicEffect(CONST_ME_TELEPORT)
    killer:unregisterEvent("bossroom death")
    bossRoom.player = nil
    bossRoom.boss = nil
    return true
end

Lua:
-- <movevent event="StepIn" actionid="77745" script="filename.lua"/>

local cfg = {
    destination = Position(x, y, z),
    boss = {
        name = "Demon",
        spawnPos = Position(x, y, z)
    }
}

bossRoom = {player = nil, boss = nil} -- global, accessible from other files

function onStepIn(creature, item, toPosition, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return false
    end
    -- there is a player still in the room
    if bossRoom.player then
        return false
    end
    local boss = Game.createMonster(cfg.boss.name, cfg.boss.spawnPos, true)
    if not boss then
        return false
    end
    player:teleportTo(cfg.destination)
    cfg.destination:sendMagicEffect(CONST_ME_TELEPORT)
    boss:registerEvent("boss death")
    player:registerEvent("bossroom death")
    bossRoom.player = player
    bossRoom.boss = boss
    return true
end

this will remove the boss and player cache from the room
Lua:
-- <event type="preparedeath" name="bossroom death" script="filename.lua"/>

function onPrepareDeath(creature, killer)
    bossRoom.player = nil
    bossRoom.boss:remove()
    bossRoom.boss = nil
    return true
end
 
Last edited:
Solution
can be made much simpler.
onKill will keep firing each time you kill something in sarah's script because the event never gets unregistered, onDeath is better to use here and register it directly to the boss
Lua:
-- <event type="death" name="boss death" script="filename.lua"/>

local rewardRoom = Position(x, y, z)

function onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified)
    killer:teleportTo(rewardRoom)
    rewardRoom:sendMagicEffect(CONST_ME_TELEPORT)
    killer:unregisterEvent("bossroom death")
    bossRoom.player = nil
    bossRoom.boss = nil
    return true
end

Lua:
-- <movevent event="StepIn" actionid="77745" script="filename.lua"/>

local cfg = {
    destination = Position(x, y, z),
    boss = {
        name = "Demon",
        spawnPos = Position(x, y, z)
    }
}

bossRoom = {player = nil, boss = nil} -- global, accessible from other files

function onStepIn(creature, item, toPosition, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return false
    end
    -- there is a player still in the room
    if bossRoom.player then
        return false
    end
    local boss = Game.createMonster(cfg.boss.name, cfg.boss.spawnPos, true)
    if not boss then
        return false
    end
    player:teleportTo(cfg.destination)
    cfg.destination:sendMagicEffect(CONST_ME_TELEPORT)
    boss:registerEvent("boss death")
    player:registerEvent("bossroom death")
    bossRoom.player = player
    bossRoom.boss = boss
    return true
end

this will remove the boss and player cache from the room
Lua:
-- <event type="preparedeath" name="bossroom death" script="filename.lua"/>

function onPrepareDeath(creature, killer)
    bossRoom.player = nil
    bossRoom.boss:remove()
    bossRoom.boss = nil
    return true
end

It looks really good! Can you make so it cleans the room? Now, if i die with a player, and the next player enters, it will be 2 bosses in there :p
 
It looks really good! Can you make so it cleans the room? Now, if i die with a player, and the next player enters, it will be 2 bosses in there :p
did you check my edited code?
i added something to fix that, the onPrepareDeath will remove the boss from the bossRoom table when player dies
re-copy everything
 
did you check my edited code?
i added something to fix that, the onPrepareDeath will remove the boss from the bossRoom table when player dies
re-copy everything

Oh i didnt notice you edited the code. Now it works great, the only thing i miss is when the room is busy, and someone tries to enter.
Now you dont get anything, like "The room is busy". But maybe i can add that myself xD
Edit:
Added
Code:
    if bossRoom.player then
        player:say('Someone is already inside.', TALKTYPE_MONSTER_SAY)      
        fromPosition:sendMagicEffect(CONST_ME_TELEPORT)
        player:teleportTo(fromPosition, true)
        return false
    end
Now it works perfectly, thanks alot @Static_ . Made my day :)
 
Last edited:
Could you do, if player kill boss he has 30 seconds to take drop before he get teleport? Great script by the way!
 
Last edited:
Back
Top