• 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 Cant figure how to teleport players when they kill creature

SixNine

Active Member
Joined
Dec 12, 2018
Messages
442
Reaction score
40
TFS 1.2
How can i add teleport to x,y,z when players kill creature in this config. Tried doing myself but it was just one big failure

So i would like to add something like this in local config

Lua:
teleport = {x = 999, y = 999, z = 7},

Lua:
local config = {
    ['monstername'] = {needValue = 1, setValue = 2,
        minimumDamagePercent = 0.06,
        reward = {
            addExperience = 50,
            addItem = {{id = 1560, count = 1}}
    },
}

function onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    local creatureName = creature:getName()
    local config = config[creatureName:lower()]
    if not config then
        return true
    end

    local convinceCreature = nil
    local creaturePosition = creature:getPosition()
    if config.convinceCreature then
        convinceCreature = Game.createMonster(config.convinceCreature, creaturePosition, true)
    end

    local summonMonsters = config.summonMonsters
    if summonMonsters and next(summonMonsters) then
        for k, monsterName in pairs(summonMonsters) do
            local summonCreature = Creature(monsterName)
            if convinceCreature ~= nil or not isMonster(summonCreature) then
                local monster = Creature(Game.createMonster(monsterName, creaturePosition, true))
                if monster ~= nil and convinceCreature ~= nil then
                    doConvinceCreature(convinceCreature, monster)
                end
            end
        end
    end   

    if config.minimumDamagePercent and config.minimumDamagePercent > 0 then
        local monsterMaxHealth = creature:getMaxHealth()
        local needDamage = monsterMaxHealth * config.minimumDamagePercent
        for pid, info in pairs(creature:getDamageMap()) do
            local player = Player(pid)
            if player then
                local currentSaga = player:getStorageValue(Storage.Saga)
                if currentSaga == config.needValue and info.total >= needDamage then
                    if config.setValue then player:setStorageValue(Storage.Saga, config.setValue) end
                    if config.reward then player:takeReward(config.reward) end
                end

                 local playerPercent = math.min(100, math.max(0, info.total / monsterMaxHealth * 100))
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, string.format("[PRINT] dealt %.2f percents to %s.", playerPercent, creatureName))
            end
        end
    end

    return true
end
 
maybe use some like this:

local creatureevent = CreatureEvent("monsterKilled")
function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
local teleport = {x = 999, y = 999, z = 7}
local player = Creature(killer)
player:teleportTo(teleport)
end
creatureevent:register()


and add this on monster you want to teleport after he die
<script>
<event name="monsterKilled" />
</script>
 
maybe use some like this:

local creatureevent = CreatureEvent("monsterKilled")
function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
local teleport = {x = 999, y = 999, z = 7}
local player = Creature(killer)
player:teleportTo(teleport)
end
creatureevent:register()


and add this on monster you want to teleport after he die
<script>
<event name="monsterKilled" />
</script>
If i wanted to use something like this i would have already used something like this :D the entire point of this thread is adding it in local config. This solution is really primitive if i would add more creatures in my table i would need to create multiple lua files so its hella stupid thats why its required to add it in table
 
add in config:
Lua:
local config = {
    ['monstername'] = {needValue = 1, setValue = 2,
        minimumDamagePercent = 0.06,
        reward = {
            addExperience = 50,
            addItem = {{id = 1560, count = 1}}
        },
        tpPosition = Position(1000, 1000, 7),
        secondsToRemove = 10,
}

To make teleport:
Lua:
    local tp = Game.createItem(1387, 1, creature:getPosition())
    if tp then
        tp:setDestination(config.tpPosition)
        addEvent(removeTp, 1000 * config.secondsToRemove , creature:getPosition())
    end


Remove function:
Lua:
    local function removeTp(tpPosition)
        local item = Tile(tpPosition):getItemById(1387)  
        if item then
            item:remove()
        end
    end
 
To make it clear

If you kill a monster it should create a teleport which teleports you to position 10,10,7 as explain?
add in config:
Lua:
local config = {
    ['monstername'] = {needValue = 1, setValue = 2,
        minimumDamagePercent = 0.06,
        reward = {
            addExperience = 50,
            addItem = {{id = 1560, count = 1}}
        },
        tpPosition = Position(1000, 1000, 7),
        secondsToRemove = 10,
}

To make teleport:
Lua:
    local tp = Game.createItem(1387, 1, creature:getPosition())
    if tp then
        tp:setDestination(config.tpPosition)
        addEvent(removeTp, 1000 * config.secondsToRemove , creature:getPosition())
    end


Remove function:
Lua:
    local function removeTp(tpPosition)
        local item = Tile(tpPosition):getItemById(1387) 
        if item then
            item:remove()
        end
    end
Okay it creates the teleport but it gives attempt to index a nil value. Btw it would be better if it teleports you to a postition then creating a teleport, because lets say you killed a creature and missed the teleport because you were afk it would be pain in the ass so thats it would be better if it just teleported everyone who killed the creature.
 
Okay it creates the teleport but it gives attempt to index a nil value. Btw it would be better if it teleports you to a postition then creating a teleport, because lets say you killed a creature and missed the teleport because you were afk it would be pain in the ass so thats it would be better if it just teleported everyone who killed the creature.
function onKill reads only the last hit in my tfs version idk if it changed, it might be like force players to be inparty i have no clue how, and in creaturescripts, function onKill, if player in party get party members and teleport them, currently iam on phone i might write this code when iam baack

instead of adding teleport use
player:teleportTo(X, Y, Z)
 
function onKill reads only the last hit in my tfs version idk if it changed, it might be like force players to be inparty i have no clue how, and in creaturescripts, function onKill, if player in party get party members and teleport them, currently iam on phone i might write this code when iam baack

instead of adding teleport use
player:teleportTo(X, Y, Z)
No thats why you see function
minimumDamagePercent = 0.06,
so if you deal 6% it counts as a finished mission for you already, so that way last hit function is not used.
 
function onKill reads only the last hit in my tfs version idk if it changed, it might be like force players to be inparty i have no clue how, and in creaturescripts, function onKill, if player in party get party members and teleport them, currently iam on phone i might write this code when iam baack

instead of adding teleport use
player:teleportTo(X, Y, Z)
Function 'onKill' can execute one time or more. On old engines, it was executed for 'max damage player' and 'last hit player' (if it was one player, it executed once).
On some versions of TFS there was configurable amount of 'assists' for each frag and 'onKill' was executed for every 'assisting player' (ordered by amount of dmg).

Checked TFS 1.3 code: it executes for 'max damage player' and 'last hit player'.

@SixNine
Does that 'onDeath' work for you? onDeath was registered only for players. Is it registered for monsters too on TFS 1.x?
 
Function 'onKill' can execute one time or more. On old engines, it was executed for 'max damage player' and 'last hit player' (if it was one player, it executed once).
On some versions of TFS there was configurable amount of 'assists' for each frag and 'onKill' was executed for every 'assisting player' (ordered by amount of dmg).

Checked TFS 1.3 code: it executes for 'max damage player' and 'last hit player'.

@SixNine
Does that 'onDeath' work for you? onDeath was registered only for players. Is it registered for monsters too on TFS 1.x?
This entire system works perfectly and yes its registered in monsters too, storage part which is this needValue = 1 and it has
<script>
<event name="SagaSystem"/>
</script>
Overall this entire system works perfectly i just didnt posted the different parts of this entire saga system. So because of this minimumDamagePercent = 0.06, people who dealt 6% all of them gets rewards, storages and etc what ever i add.
 
been using onkill function for my missions & tasks system for 2 years now, ye it works for monsters and players, and only the last hit takes the kill. here is example,
Lua:
local config = {
     ['roc'] = {amount = 1000, storage = 29691, startstorage = 93046, startvalue = 1},
     ['eradicator'] = {amount = 150, storage = 289692, startstorage = 93046, startvalue = 3},
     ['hellflayer'] = {amount = 2, storage = 29693, startstorage = 93046, startvalue = 5},
     ['mad mage'] = {amount = 2, storage = 29695, startstorage = 93046, startvalue = 5},
     ['glooth slasher'] = {amount = 2, storage = 29696, startstorage = 93046, startvalue = 5},
     ['deathstrike'] = {amount = 2, storage = 29694, startstorage = 93046, startvalue = 5},
}
function onKill(player, target)
     local monster = config[target:getName():lower()]
     if target:isPlayer() or not monster or target:getMaster() then
         return true
     end
    local stor = player:getStorageValue(monster.storage)+1
     if player:getIsSVip() == true then
        stor = player:getStorageValue(monster.storage)+2
    else
        stor = player:getStorageValue(monster.storage)+2
    end
     if stor <= monster.amount and player:getStorageValue(monster.startstorage) >= monster.startvalue then
         player:setStorageValue(monster.storage, stor)
         player:sendChannelMessage(nil, '[Zilor]: '..(stor +1)..' of '..monster.amount..' '..target:getName()..'s killed.', TALKTYPE_CHANNEL_R1, 11)
     end
     if (stor+1) == monster.amount or (stor) == monster.amount then
         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'Congratulations, you have killed '..(stor)..' '..target:getName()..'s and completed the '..target:getName()..'s mission.')
         player:setStorageValue(monster.storage, stor)
     end
     return true
end
 
been using onkill function for my missions & tasks system for 2 years now, ye it works for monsters and players, and only the last hit takes the kill. here is example,
Lua:
local config = {
     ['roc'] = {amount = 1000, storage = 29691, startstorage = 93046, startvalue = 1},
     ['eradicator'] = {amount = 150, storage = 289692, startstorage = 93046, startvalue = 3},
     ['hellflayer'] = {amount = 2, storage = 29693, startstorage = 93046, startvalue = 5},
     ['mad mage'] = {amount = 2, storage = 29695, startstorage = 93046, startvalue = 5},
     ['glooth slasher'] = {amount = 2, storage = 29696, startstorage = 93046, startvalue = 5},
     ['deathstrike'] = {amount = 2, storage = 29694, startstorage = 93046, startvalue = 5},
}
function onKill(player, target)
     local monster = config[target:getName():lower()]
     if target:isPlayer() or not monster or target:getMaster() then
         return true
     end
    local stor = player:getStorageValue(monster.storage)+1
     if player:getIsSVip() == true then
        stor = player:getStorageValue(monster.storage)+2
    else
        stor = player:getStorageValue(monster.storage)+2
    end
     if stor <= monster.amount and player:getStorageValue(monster.startstorage) >= monster.startvalue then
         player:setStorageValue(monster.storage, stor)
         player:sendChannelMessage(nil, '[Zilor]: '..(stor +1)..' of '..monster.amount..' '..target:getName()..'s killed.', TALKTYPE_CHANNEL_R1, 11)
     end
     if (stor+1) == monster.amount or (stor) == monster.amount then
         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'Congratulations, you have killed '..(stor)..' '..target:getName()..'s and completed the '..target:getName()..'s mission.')
         player:setStorageValue(monster.storage, stor)
     end
     return true
end

been using onkill function for my missions & tasks system for 2 years now, ye it works for monsters and players, and only the last hit takes the kill. here is example,
Lua:
local config = {
     ['roc'] = {amount = 1000, storage = 29691, startstorage = 93046, startvalue = 1},
     ['eradicator'] = {amount = 150, storage = 289692, startstorage = 93046, startvalue = 3},
     ['hellflayer'] = {amount = 2, storage = 29693, startstorage = 93046, startvalue = 5},
     ['mad mage'] = {amount = 2, storage = 29695, startstorage = 93046, startvalue = 5},
     ['glooth slasher'] = {amount = 2, storage = 29696, startstorage = 93046, startvalue = 5},
     ['deathstrike'] = {amount = 2, storage = 29694, startstorage = 93046, startvalue = 5},
}
function onKill(player, target)
     local monster = config[target:getName():lower()]
     if target:isPlayer() or not monster or target:getMaster() then
         return true
     end
    local stor = player:getStorageValue(monster.storage)+1
     if player:getIsSVip() == true then
        stor = player:getStorageValue(monster.storage)+2
    else
        stor = player:getStorageValue(monster.storage)+2
    end
     if stor <= monster.amount and player:getStorageValue(monster.startstorage) >= monster.startvalue then
         player:setStorageValue(monster.storage, stor)
         player:sendChannelMessage(nil, '[Zilor]: '..(stor +1)..' of '..monster.amount..' '..target:getName()..'s killed.', TALKTYPE_CHANNEL_R1, 11)
     end
     if (stor+1) == monster.amount or (stor) == monster.amount then
         player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, 'Congratulations, you have killed '..(stor)..' '..target:getName()..'s and completed the '..target:getName()..'s mission.')
         player:setStorageValue(monster.storage, stor)
     end
     return true
end
Not sure how it has to do something with my thread :D
 
Found this:
-- 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
 
Found this:
It creates teleport we dont need teleport portal. I want people to be teleported
 
Maybe just use spectator function if tfs 1.2 has it:
Lua:
    local spec = Game.getSpectators(creature:getPosition(), false, false, 20, 20, 20, 20)
    if spec ~= nil then
        for _, s in pairs(spec) do
            if isPlayer(s) then
                // other checks
                s:teleportTo(config.tpPosition)
            end
        end   
    end
You could register onHealthChange and save people's dmg in table. Then check if player has dealt more than that 0.6% dmg.
 
Last edited:
Maybe just use spectator function if tfs 1.2 has it:
Lua:
    local spec = Game.getSpectators(creature:getPosition(), false, false, 20, 20, 20, 20)
    if spec ~= nil then
        for _, s in pairs(spec) do
            if isPlayer(s) then
                // other checks
                s:teleportTo(config.tpPosition)
            end
        end  
    end
You could register onHealthChange and save people's dmg in table. Then check if player has dealt more than that 0.6% dmg.
It already checks if played did 6% all i need is to teleport. Why people are not listening :D All you see in this creaturescript already works and was tested million of times.
 
Hmm.. @SixNine
If you want to send multiple people away without the use of a portal then I found something else for you in the forums, should work for 1.X as the thread says.

Found at: TFS 1.X+ - Teleport all player in are to area (https://otland.net/threads/teleport-all-player-in-are-to-area.261883/#post-2533072)
Lua:
local square = {
    frompos = {x = 1252, y = 1007, z = 5},
    topos = {x = 1261, y = 1013, z = 5},
    exitpos = {x = 1253, y = 1010, z = 6}
}

for a = square.frompos.x, square.topos.x do
    for b = square.frompos.y, square.topos.y do
        pos = {x = a, y = b, z = 5, stackpos = 255}
            if(isPlayer(getTopCreature(pos).uid)) then
                doTeleportThing(getTopCreature(pos).uid,square.exitpos)
            end
    end
end
 
if currentSaga == config.needValue and info.total >= needDamage then if config.setValue then player:setStorageValue(Storage.Saga, config.setValue) end if config.reward then player:takeReward(config.reward) end end

I don't see what's the issue here, the first post is literally just missing the player:teleportTo(Position(999, 999, 7))
 
Back
Top