• Vote in November Mapping Competition to select a winner!
  • 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

Member
Joined
Dec 12, 2018
Messages
247
Reaction score
21
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
 

pacan123

New Member
Joined
Oct 5, 2012
Messages
31
Reaction score
2
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>
 
OP
SixNine

SixNine

Member
Joined
Dec 12, 2018
Messages
247
Reaction score
21
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
 

kamilcioo

Premium User
Premium User
Joined
Jul 25, 2008
Messages
872
Reaction score
220
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
 
OP
SixNine

SixNine

Member
Joined
Dec 12, 2018
Messages
247
Reaction score
21
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.
 

Shadow_

Advanced OT User
Joined
Jun 2, 2018
Messages
735
Solutions
25
Reaction score
231
Location
Cairo, Egypt
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)
 
OP
SixNine

SixNine

Member
Joined
Dec 12, 2018
Messages
247
Reaction score
21
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.
 

Gesior.pl

Mega Noob&LOL 2012
Senator
Premium User
Joined
Sep 18, 2007
Messages
2,133
Solutions
25
Reaction score
1,380
Location
PLand
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?
 
OP
SixNine

SixNine

Member
Joined
Dec 12, 2018
Messages
247
Reaction score
21
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.
 

Shadow_

Advanced OT User
Joined
Jun 2, 2018
Messages
735
Solutions
25
Reaction score
231
Location
Cairo, Egypt
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
 
OP
SixNine

SixNine

Member
Joined
Dec 12, 2018
Messages
247
Reaction score
21
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
 

Ralumbi

apt install nubmod
Content Editor
Premium User
Joined
Jun 8, 2011
Messages
180
Solutions
6
Reaction score
65
Location
Netherlands
GitHub
Ralumbi
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
 
OP
SixNine

SixNine

Member
Joined
Dec 12, 2018
Messages
247
Reaction score
21
Found this:
It creates teleport we dont need teleport portal. I want people to be teleported
 

kamilcioo

Premium User
Premium User
Joined
Jul 25, 2008
Messages
872
Reaction score
220
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:
OP
SixNine

SixNine

Member
Joined
Dec 12, 2018
Messages
247
Reaction score
21
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.
 

Ralumbi

apt install nubmod
Content Editor
Premium User
Joined
Jun 8, 2011
Messages
180
Solutions
6
Reaction score
65
Location
Netherlands
GitHub
Ralumbi
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
 

Colors

Joined
Mar 22, 2013
Messages
938
Solutions
4
Reaction score
257
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))
 
Top