• 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 Teleport my summon to me

Cornwallis

Member
Joined
Jan 3, 2010
Messages
480
Reaction score
16
I'm trying to create a talkaction to teleport my summon to me but it seems I can't get the position of it.
HTML:
function onSay(player, words, param)
    local summons = #player:getSummons()
    local oldPosition = creature:getPosition()
    local newPosition = creature:getClosestFreePosition(player:getPosition(), false)
    if summons == 1 then
        if newPosition.x == 0 or summons == 0 then
            player:sendCancelMessage("You can not teleport your summoned monster.")
        return false
        elseif creature:teleportTo(newPosition) then
            oldPosition:sendMagicEffect(CONST_ME_POFF)
            newPosition:sendMagicEffect(CONST_ME_TELEPORT)
        end
    end
    return false
end
And here is the error in console
HTML:
Lua Script Error: [TalkAction Interface]
data/talkactions/scripts/teleport_summon.lua:onSay
data/talkactions/scripts/teleport_summon.lua:3: attempt to call method 'getPosition' (a nil value)
stack traceback:
        [C]: in function 'getPosition'
        data/talkactions/scripts/teleport_summon.lua:3: in function <data/talkactions/scripts/teleport_summon.lua:1>
Please point me in the right direction.
 
if creature is supposed to be a summon define creature
Code:
function onSay(player, words, param)
    local summons = player:getSummons()
    if #summons == 1 then
        local creature = summons[1]
        local oldPosition = creature:getPosition()
        local newPosition = creature:getClosestFreePosition(player:getPosition(), false)
        if newPosition.x == 0 then
            player:sendCancelMessage("You can not teleport your summoned monster.")
        elseif creature:teleportTo(newPosition) then
            oldPosition:sendMagicEffect(CONST_ME_POFF)
            newPosition:sendMagicEffect(CONST_ME_TELEPORT)
        end
    end
    return false
end
 
Last edited:
change all creature: to player:, since onSay uses player
or if creature is supposed to be a summon define creature
sigh... no need to change creature to player.. its not the name of the parameter that matters its what the value of the parameter is passed
onSay can just as well say
Code:
function onSay(boy, sdrow, marap)
      print(boy:getName(), sdrow, marap)
      return true
end

The thing you can't do is swap the order of the parameters, like you can't state
Code:
function onSay(sdrow, boy, marap)
      print(boy:getName(), sdrow, marap)
      return true
end

That will return an error because boy is no longer userdata it is now a string
 
sigh... no need to change creature to player.. its not the name of the parameter that matters its what the value of the parameter is passed
onSay can just as well say
Code:
function onSay(boy, sdrow, marap)
      print(boy:getName(), sdrow, marap)
      return true
end

The thing you can't do is swap the order or the parameters, like you can't state
Code:
function onSay(sdrow, boy, marap)
      print(boy:getName(), sdrow, marap)
      return true
end

That will return an error because boy is no longer userdata it is now a string
i know that, but in this case he wants to get closest free position from the PLAYER and then teleport the CREATURE which is his summon to his position, hence he needs to define what creature is..

edit: the first sentence of my previous post was due to that i didnt read it properly, but rather just the error
 
i know that, but in this case he wants to get closest free position from the PLAYER and then teleport the CREATURE which is his summon to his position, hence he needs to define what creature is..
Why use caps :rolleyes:.. i swear i'll read the whole statement.. next time ;)
 
Thank you both, is liking your post the same as repping?
Also what had happened with the creature and player thing was I was copying it from a spell and forgot to change creature to player ctfu.
Quick question, whenever you put summons[1] does that reference the first summon in the table? I only use 1 summon but it'd be nice to know if i can reference places in a table in such a way.
 
Last edited:
Back
Top