• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved How should I make a teleportPlayerToMonster function?

Oneda

Aspiring Spriter
Joined
Dec 3, 2013
Messages
159
Solutions
2
Reaction score
104
Location
Brazil
Well, I would like to create a function that would be something like: teleportPlayerToMonster(monstername)

Is there anyone who could help me with it? Don't even know where to start from.

TFS 1.1 btw

Tried it making like this:
Code:
function teleportOutTarrasque(cid)
    local tarrasquePos = getCreaturePosition(getCreatureByName("Tarrasque"))
    doTeleportThing(cid, tarrasquePos, TRUE)
end

Using it in this script:
Code:
function onDeath(cid, corpse, killer)
    --addEvent(respawn, timeToRespawn * 1000, getCreaturePosition(cid))
    teleportOutTarrasque(cid)
    return true
end

gives me this error:
803c6c7930.png
 
Last edited:
Code:
local monster = {
    'Tarrasque'
}

local time_ = 1

function onDeath(cid, corpse, killer)
    local function teleportOutTarrasque()
        for _, name in pairs(monster)
            local toPos = getCreaturePosition( getCreatureByName(monster[name:lower()]) )
            if isPlayer(cid) then
                doTeleportThing(cid, toPos, true)
            end
        end
    end
    addEvent(teleportOutTarrasque, time_ * 1000)
    return true
end
 
Last edited:
Code:
local monster = {
    'Tarrasque'
}

local time_ = 1

function onDeath(cid, corpse, killer)
    local function teleportOutTarrasque()
        for _, name in pairs(monster)
            local toPos = getCreaturePosition( getCreatureByName(monster[name:lower()]) )
            if isPlayer(cid) then
                doTeleportThing(cid, toPos, true)
            end
        end
    end
    addEvent(teleportOutTarrasque, time_ * 1000)
    return true
end

Seems like there's an extra end in the script, I removed the first one, then it gave me this error:
c81bd6bef3.png


And when the monster dies, it shows me
d4ada23b2b.png


(Yup, it is defined in creaturescripts.xml)
 
To keep things simple;

Remove local from this line:
Code:
local function teleportOutTarrasque()

And try again.
 
When the player kills a monster, he should be teleported to another monster named Tarrasque?

Can the first monster be anything? Or are we killing Tarrasque and then teleporting to the next Tarrasque?

Edit:
Note*: This is an onKill and not an onDeath creature event.

Code:
-- Our table with information
local monster = {
    targetMonsterName = 'Rotworm', -- Monster you kill
    tpMonsterName = 'Orshabaal', -- Monster that you're TP'd to
    time = 1 -- Time in seconds before you are Tp'd
}

-- Our Local (just for this script) Function
local function teleportToMonster(dude, position)
    local player = Player(dude)
    if player then
        player:teleportTo(position, false)
    end
end


function onKill(creature, target)
    --- Make sure killer is player
    if not creature:isPlayer() then
        return true
    end
  
    --- Make sure target is monster
    local targetMonster = Monster(target)
    if not targetMonster then
        return true
    end
  
    --- Make sure target is involved in our script
    if targetMonster:getName():lower() ~= monster.targetMonsterName:lower() then
        return true
    end  
  
    --- Check to see if the TP monster is on the map and if so then add the TP function
    local tpMonster = Creature(monster.tpMonsterName)
    if tpMonster then
        addEvent(teleportToMonster, monster.time * 1000, creature:getId(), tpMonster:getPosition())
    else
        creature:sendCancelMessage('Sorry, the monster by the name of ' .. monster.tpMonsterName .. ' is not on the map.')
    end

    return true
end
 
Last edited:
When the player kills a monster, he should be teleported to another monster named Tarrasque?

Can the first monster be anything? Or are we killing Tarrasque and then teleporting to the next Tarrasque?

Well, I am making a stomach enviroment, where there's monsters named "Tarrasque Stomach Wall" inside, I want the player to get teleported to "Tarrasque" when he kills a Tarrasque Stomach Wall.
 
Well, I am making a stomach enviroment, where there's monsters named "Tarrasque Stomach Wall" inside, I want the player to get teleported to "Tarrasque" when he kills a Tarrasque Stomach Wall.

@Oneda
I edited my first post, let me know if you have difficulty adding it in.
 
No, how should it be registered in there?
In your creaturescripts.xml you have something like this:
<event type="kill" name="EVENT_NAME" script="script.lua"/>

So in your login.lua you will need to add this:
player:registerEvent(EVENT_NAME)

After you do that execeute the command: /reload creaturescripts, and the re-log your character and try again.
 
In your creaturescripts.xml you have something like this:
<event type="kill" name="EVENT_NAME" script="script.lua"/>

So in your login.lua you will need to add this:
player:registerEvent(EVENT_NAME)

After you do that execeute the command: /reload creaturescripts, and the re-log your character and try again.

I had just pushed the change to our git and was waiting on him to come back and restart the server. It worked.

Salute. o7
 
That solved it, thank you very much to everyone who helped.

@imkingran @Leo32 @Codex NG

Final script:

Creaturescripts.xml TAG:

Code:
    <event type="kill" name="TStomach" script="tarrasquestomach.lua"/>

tarrasquestomach.lua:
Code:
local monster = {
    targetMonsterName = 'Tarrasque Stomach Wall', -- Monster you kill
    tpMonsterName = 'Tarrasque', -- Monster that you're TP'd to
    time = 1 -- Time in seconds before you are Tp'd
}

local function teleportToMonster(dude, position)
    local player = Player(dude)
    if player then
        player:teleportTo(position, false)
    end
end


function onKill(creature, target)
    if not creature:isPlayer() then
        return true
    end

    local targetMonster = Monster(target)
    if not targetMonster then
        return true
    end

    if targetMonster:getName():lower() ~= monster.targetMonsterName:lower() then
        return true
    end

    local tpMonster = Creature(monster.tpMonsterName)
    if tpMonster then
        addEvent(teleportToMonster, monster.time * 1000, creature:getId(), tpMonster:getPosition())
    else
        creature:sendCancelMessage('Sorry, the monster by the name of ' .. monster.tpMonsterName .. ' is not on the map.')
    end

    return true
end

Add to login.lua:
Code:
    player:registerEvent("TStomach")
 
Last edited:
Add to your monster (after flags) [the monster you must kill to teleport to the other monster]:
Code:
    <script>
    <event name="TStomach"/>
    </script>

I'm glad you were able to get it working, this part however is not necessary since the event is registered to the player and is triggered by the players' killing action.

Before, with onDeath, it was registered to the monster since the monster would be the one carrying out the dieng action.
 
I'm glad you were able to get it working, this part however is not necessary since the event is registered to the player and is triggered by the players' killing action.

Before, with onDeath, it was registered to the monster since the monster would be the one carrying out the dieng action.

Thank you again for your help, and its been fixed. ;)
 
Back
Top