• 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 Get Summon Pos

mackerel

Well-Known Member
Joined
Apr 26, 2017
Messages
398
Solutions
18
Reaction score
72
The code below works for player just fine

Lua:
function onCastSpell(cid, var)
    print(getCreaturePosition(cid))
    return true
end

= Returns table

I want to get position for the summons as well, but the code below does not work

Lua:
function onCastSpell(cid, var)
   summons = Player(cid):getSummons()
   print(getCreaturePosition(summons))
   return true
end

= Returns false

tfs 1.0

Any help appreciated
 
Solution
bogart is correct, player:getSummons() returns a table which you have to iterate to get the monster
even in your link, printer had to iterate the table to get the monster
here's an example
Lua:
for index, summon in ipairs(player:getSummons()) do
    print(index, summon:getName(), summon:getPosition())
end
AFAIK getSummons() will return a table with the info of the summon(s), in this case you're trying to get the position of a table (which containts the summons info) instead of a creature.
 
AFAIK getSummons() will return a table with the info of the summon(s), in this case you're trying to get the position of a table (which containts the summons info) instead of a creature.

It has been used here:

GlobalEvent - Teleport summon to Master [TFS 1.0]

I've been trying different methods but this time I get nil value:

attempt to call method 'getPosition' (a nil value)

Lua:
function onCastSpell(cid, var)
    local player = Player(cid)
    local summons = player:getSummons()
    local pos = summons:getPosition()
  
    print(pos)
    return true
end

Summoned the monster by using:

utevo res "...
/summon ...

the same thing happens
 
bogart is correct, player:getSummons() returns a table which you have to iterate to get the monster
even in your link, printer had to iterate the table to get the monster
here's an example
Lua:
for index, summon in ipairs(player:getSummons()) do
    print(index, summon:getName(), summon:getPosition())
end
 
Solution
It has been used here:

GlobalEvent - Teleport summon to Master [TFS 1.0]

I've been trying different methods but this time I get nil value:



Lua:
function onCastSpell(cid, var)
    local player = Player(cid)
    local summons = player:getSummons()
    local pos = summons:getPosition()
 
    print(pos)
    return true
end

It worked because of this part:
Lua:
local summons = player:getSummons()
            if #summons ~= 0 then
                for i = 1, #summons do
                    local summon = summons[i]
It's iterating by index through a whole table.
 
It worked because of this part:
Lua:
local summons = player:getSummons()
            if #summons ~= 0 then
                for i = 1, #summons do
                    local summon = summons[i]
It's iterating by index through a whole table.

I did something like this earlier but that didn't work either :confused:

Lua:
function onCastSpell(cid, var)
    local player = Player(cid)
    local summons = player:getSummons()
 
    for i = 1, #summons do
        local pos = summons:getPosition()
        print(pos)
    end
 
    return true
end

Edit//

added
Lua:
local summon = summons[i]

and it works :eek:
 
Back
Top