• 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 [TFS 1.2] Getting a summon userdata

Shitobu

displays under your name in your posts.
Joined
Apr 24, 2016
Messages
25
Reaction score
1
I'm trying to get a summon userdata that I created by:

Code:
        local monster = Game.createMonster("Test", player:getPosition())
            monster:setMaster(player)
            player:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
This code summons a monster named "Test".
Now, on another code, I'm trying to check if there is any summon summoned.
I tried:
Code:
    if player:getSummons() ~= nil then
         -- Summoned
    end
But somehow getSummons() return an userdata even when there is no summon summoned.
I think I could do an onThink checking the creature name, if it's Test, I find it's master and Set a storage on master.
But I need the summon userdata anyway to manipulate the summon on others codes. D:
Any ideas?

@if there was any way to get the summons table and by that I could play with each one would be great.. but I guess that I can't do that by that way?
 
Last edited:
But somehow getSummons() return an userdata even when there is no summon summoned.
From what I know getSummons return table with summons not userdata so if you don't have summons you still have table but without any element.
You can check if you have summons like this:
Code:
if #player:getSummons() > 0 then
 
From what I know getSummons return table with summons not userdata so if you don't have summons you still have table but without any element.
You can check if you have summons like this:
Code:
if #player:getSummons() > 0 then
Yeah you are right. I didn't know it returned a table and not a userdata.
I'm gonna try doing something with your info. Thanks a lot.
 
For anyone interested on how I did this:

Code:
            if #player:getSummons() > 0 then
                for k, v in pairs(player:getSummons()) do
                    v:setMaxHealth(player:getMaxHealth())
                    print(v:getMaxHealth())
                end
            end

Just showing how you can do it, on this code I basically set your summon max health equal to the player's max health and then print it's max health.
You can obviously do others things, but that's just the idea.
 
For anyone interested on how I did this:

Code:
            if #player:getSummons() > 0 then
                for k, v in pairs(player:getSummons()) do
                    v:setMaxHealth(player:getMaxHealth())
                    print(v:getMaxHealth())
                end
            end

Just showing how you can do it, on this code I basically set your summon max health equal to the player's max health and then print it's max health.
You can obviously do others things, but that's just the idea.
you can just iterate through summon list by index instead of using pairs
Code:
local summs = player:getSummons()
if #summs > 0 then
    for i = 1, #summs do
        summs[i]:setMaxHealth(player:getMaxHealth())
    end
end
 
Back
Top