• 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 setMaster() TFS 1.2 (SOLVED)

A

Alw

Guest
Hi. I'm making a summon spell, but the player dosn't get set as master. When a GM summons the monster the GM get set as master but on regular players it dosn't work.


Code:
local summonName = "Monk"

function onCastSpell(cid, var)
    local player = Player(cid)
    if player == nil then
        return false
    end
   
    local summons = player:getSummons()

    if #summons > 0 then
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false   
    end
   
    local monster = Game.createMonster(summonName, player:getPosition(), false, false)

    if not monster then
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local didSummon = monster:setMaster(player)
    if not didSummon then
        monster:remove()
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    return true                    
end

I appreciate any help.
Regards Alw
 
Try this
Code:
local summonName = "Monk"

function onCastSpell(player, var)
    if player == nil then
        return false
    end
    local function getPlayerSummonCount()
        local summonTable = {}
        if type(player:getSummons()) == "table" then
            for _, playerSummons in ipairs(player:getSummons()) do
                if playerSummons:getId() ~= 0 or playerSummons:getId() ~= nil then
                    summonTable[#summonTable + 1] =  playerSummons:getId()
                end
            end
            return #summonTable
        end
        return 0
    end

    if getPlayerSummonCount() > 0 then
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local monster = Game.createMonster(summonName, player:getPosition())

    if not monster then
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end
 
    monster:setMaster(player)
 
    if monster:getMaster():getId() ~= player:getId() then
        monster:remove()
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return false
    end

    return true                 
end
 
Last edited:
I see your point, I've already tried removing that and used player instead of cid.
Cid is still being used in most of the spells.
Anyway it didn't change the fact that the player dosn't get set as master.
But thanks anyway :)
Regard Alw
 
I see your point, I've already tried removing that and used player instead of cid.
Cid is still being used in most of the spells.
Anyway it didn't change the fact that the player dosn't get set as master.
But thanks anyway :)
Regard Alw
I edited the script above, I know I should do that before I post it.. but I just can't help myself :p
 
Well you just edited the "Check summons" part of the scripts and thats already working:p Anyway tested your script, It didn't set the player as the Master.
Thanks Anyway :)
Regards Alw
 
u shouldnt tag in people who haven't posted in your thread or have nothing to do with the thread, in this case ninja shouldn't be tagged :p
Ninja helps us alot with scripts, he's currently working on a paid one for us. So i figured he would be okay with the tag.
 
Code:
local config = {
    maxSummons = 2,
    summonName = "Monk"
}

function onCastSpell(creature, var)
    local player = creature:getPlayer()
    if player == nil then
        return false
    end

    local playerPosition = player:getPosition()
    if #player:getSummons() > config.maxSummons then -- Player has already to many summons
        playerPosition:sendMagicEffect(CONST_ME_POFF)
        return false
    end

    local monster = Game.createMonster(config.summonName, playerPosition, false, false)
    if not monster then -- If there is no room the summon the monster, lets force it!
        Game.createMonster(config.summonName, playerPosition, false, true)
    end

    monster:setMaster(player)
    return true
end
 
The script is working it's no problem until the "setMaster" comes into play. Printer your script had the same error as mine, and I really don't understand why the player dosn't get set as master.
GMS gets set as master when i execute the spell, but regular player doesn't. Any ideas?
Regards Alw
 
Back
Top