• 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!

Summoning monster on level

adamox223

New Member
Joined
Oct 21, 2017
Messages
99
Reaction score
4
Hi, i need help, can you fix it, because i have no idea how do this? please! :)

If we have level 1 we can summon Monster I, when we up 30 then we can summon monster II, here is code and errors:
2ivlk7o.png



Code:
local clones = {
    [{1, 29}] = "Monster I",
    [{30, 70}] = "Monster II"
}

local cloneName, MaxSummon = '', 2

function summonCreatureBasedOnLevel(playerLevel)
    for level, creatureName in pairs(clones) do
        if playerLevel >= level[1] and playerLevel <= level[2] then
            cloneName = creatureName
            return true
        end
    end
    return false
end

function onCastSpell(cid, var)
    if(#getCreatureSummons(cid) < MaxSummon) then
        if summonCreatureBasedOnLevel(getPlayerLevel(cid)) then
            local pos = getPlayerPosition(cid)
            local clone = doSummonCreature(cid, cloneName, pos)
            doConvinceCreature(cid, clone)
            doChangeSpeed(clone, getCreatureBaseSpeed(cid))
            local creatureHealth = (getCreatureMaxHealth(cid) / 2)
            setCreatureMaxHealth(clone, creatureHealth)
            doCreatureAddHealth(clone, creatureHealth)
            pos.x = pos.x + 1
            doSendMagicEffect(pos, CONST_ME_BIGPLANTS)
            return true
        end
    end
    doSendMagicEffect(pos, CONST_ME_POFF)
    return false
end
 
Solution
Hi, i need help, can you fix it, because i have no idea how do this? please! :)

If we have level 1 we can summon Monster I, when we up 30 then we can summon monster II, here is code and errors:
2ivlk7o.png



Code:
local clones = {
    [{1, 29}] = "Monster I",
    [{30, 70}] = "Monster II"
}

local cloneName, MaxSummon = '', 2

function summonCreatureBasedOnLevel(playerLevel)
    for level, creatureName in pairs(clones) do
        if playerLevel >= level[1] and playerLevel <= level[2] then
            cloneName = creatureName
            return true
        end
    end
    return false
end

function onCastSpell(cid, var)
    if(#getCreatureSummons(cid) < MaxSummon) then
        if...
Hi, i need help, can you fix it, because i have no idea how do this? please! :)

If we have level 1 we can summon Monster I, when we up 30 then we can summon monster II, here is code and errors:
2ivlk7o.png



Code:
local clones = {
    [{1, 29}] = "Monster I",
    [{30, 70}] = "Monster II"
}

local cloneName, MaxSummon = '', 2

function summonCreatureBasedOnLevel(playerLevel)
    for level, creatureName in pairs(clones) do
        if playerLevel >= level[1] and playerLevel <= level[2] then
            cloneName = creatureName
            return true
        end
    end
    return false
end

function onCastSpell(cid, var)
    if(#getCreatureSummons(cid) < MaxSummon) then
        if summonCreatureBasedOnLevel(getPlayerLevel(cid)) then
            local pos = getPlayerPosition(cid)
            local clone = doSummonCreature(cid, cloneName, pos)
            doConvinceCreature(cid, clone)
            doChangeSpeed(clone, getCreatureBaseSpeed(cid))
            local creatureHealth = (getCreatureMaxHealth(cid) / 2)
            setCreatureMaxHealth(clone, creatureHealth)
            doCreatureAddHealth(clone, creatureHealth)
            pos.x = pos.x + 1
            doSendMagicEffect(pos, CONST_ME_BIGPLANTS)
            return true
        end
    end
    doSendMagicEffect(pos, CONST_ME_POFF)
    return false
end
you've added extra parameters to doSummonCreature

doSummonCreature(name, pos)
--------
Change this
Lua:
local clone = doSummonCreature(cid, cloneName, pos)
to this
Lua:
local clone = doSummonCreature(cloneName, pos)
 
Solution
@Xikini when i add 2nd same script, because its two different spells and i have this error but 1 spell is work, second copied dont work :/ idk why..
2rgno8l.png

Code:
local clones = {
    [{1, 29}] = "Monster",
    [{30, 69}] = "Monster [I]",
    [{70, 149}] = "Monster [II]",
    [{150, 219}] = "Monster [III]",
    [{220, 349}] = "Monster [IV]",
    [{350, 9999}] = "Monster [V]"

}

local cloneName, MaxSummon = '', 1

function summonCreatureBasedOnLevel(playerLevel)
    for level, creatureName in pairs(clones) do
        if playerLevel >= level[1] and playerLevel <= level[2] then
            cloneName = creatureName
            return true
        end
    end
    return false
end

function onCastSpell(cid, var)
    if(#getCreatureSummons(cid) < MaxSummon) then
        if summonCreatureBasedOnLevel(getPlayerLevel(cid)) then
            local pos = getPlayerPosition(cid)
            local clone = doSummonCreature(cloneName, pos)
            doConvinceCreature(cid, clone)
            doChangeSpeed(clone, getCreatureBaseSpeed(cid))
            local creatureHealth = (getCreatureMaxHealth(cid) / 2)
            setCreatureMaxHealth(clone, creatureHealth)
            doCreatureAddHealth(clone, creatureHealth)
            pos.x = pos.x + 1
            return true
        end
    end
    doSendMagicEffect(pos, CONST_ME_POFF)
    return false
end
 
@Xikini when i add 2nd same script, because its two different spells and i have this error but 1 spell is work, second copied dont work :/ idk why..
2rgno8l.png

Code:
local clones = {
    [{1, 29}] = "Monster",
    [{30, 69}] = "Monster [I]",
    [{70, 149}] = "Monster [II]",
    [{150, 219}] = "Monster [III]",
    [{220, 349}] = "Monster [IV]",
    [{350, 9999}] = "Monster [V]"

}

local cloneName, MaxSummon = '', 1

function summonCreatureBasedOnLevel(playerLevel)
    for level, creatureName in pairs(clones) do
        if playerLevel >= level[1] and playerLevel <= level[2] then
            cloneName = creatureName
            return true
        end
    end
    return false
end

function onCastSpell(cid, var)
    if(#getCreatureSummons(cid) < MaxSummon) then
        if summonCreatureBasedOnLevel(getPlayerLevel(cid)) then
            local pos = getPlayerPosition(cid)
            local clone = doSummonCreature(cloneName, pos)
            doConvinceCreature(cid, clone)
            doChangeSpeed(clone, getCreatureBaseSpeed(cid))
            local creatureHealth = (getCreatureMaxHealth(cid) / 2)
            setCreatureMaxHealth(clone, creatureHealth)
            doCreatureAddHealth(clone, creatureHealth)
            pos.x = pos.x + 1
            return true
        end
    end
    doSendMagicEffect(pos, CONST_ME_POFF)
    return false
end
My friend had something of a same issue.
Using 'locals' with the same name, in two separate scripts would somehow fuse together, but only in spells or weapons.
I think it has something to do with how the Lua environment is created in these area's.

Basically the way you fix it, is to make sure your local variables are never named the same.

So usually he just put the spell_name in front of any local.

Example:

local cloneName, MaxSummon = '', 1
local summonCreature_cloneName, summonCreature_MaxSummon = '', 1
local greatSummonCreature_cloneName, greatSummonCreature_MaxSummon = '', 1

You can play around and find your own naming system but that's the only 'fix' I know of.
 
Lua:
Lua Script Error: [Spell Interface]
data/spells/scripts/support/sum cre.lua:onCastSpell
data/spells/scripts/support/sum cre.lua:25: attempt to call global 'setCreatureMaxHealth' (a nil value)
stack traceback:
    [C]: in function 'setCreatureMaxHealth'
    data/spells/scripts/support/sum cre.lua:25: in function <data/spells/scripts/support/sum cre.lua:17>



Lua:
local clones = {
    [{1, 999}] = "Hero"
}

local cloneName, MaxSummon = '', 1

function summonCreatureBasedOnLevel(playerLevel)
    for level, creatureName in pairs(clones) do
        if playerLevel >= level[1] and playerLevel <= level[2] then
            cloneName = creatureName
            return true
        end
    end
    return false
end

function onCastSpell(cid, var)
    if(#getCreatureSummons(cid) < MaxSummon) then
        if summonCreatureBasedOnLevel(getPlayerLevel(cid)) then
            local pos = getPlayerPosition(cid)
            local clone = doSummonCreature(cid, cloneName, pos)
            doConvinceCreature(cid, clone)
            doChangeSpeed(clone, getCreatureBaseSpeed(cid))
            local creatureHealth = (getCreatureMaxHealth(cid) / 2)
            setCreatureMaxHealth(clone, creatureHealth)
            doCreatureAddHealth(clone, creatureHealth)
            pos.x = pos.x + 1
            doSendMagicEffect(pos, CONST_ME_BIGPLANTS)
            return true
        end
    end
    doSendMagicEffect(pos, CONST_ME_POFF)
    return false
end
 
Lua:
Lua Script Error: [Spell Interface]
data/spells/scripts/support/sum cre.lua:onCastSpell
data/spells/scripts/support/sum cre.lua:25: attempt to call global 'setCreatureMaxHealth' (a nil value)
stack traceback:
    [C]: in function 'setCreatureMaxHealth'
    data/spells/scripts/support/sum cre.lua:25: in function <data/spells/scripts/support/sum cre.lua:17>

if(#getCreatureSummons(cid) < MaxSummon) then
if summonCreatureBasedOnLevel(getPlayerLevel(cid)) then
local pos = getPlayerPosition(cid)
local clone = doSummonCreature(cid, cloneName, pos)
doConvinceCreature(cid, clone)
doChangeSpeed(clone, getCreatureBaseSpeed(cid))
local creatureHealth = (getCreatureMaxHealth(cid) / 2)
setCreatureMaxHealth(clone, creatureHealth)

setCreatureMaxHealth(clone, creatureHealth)

to:

clone:setMaxHealth(creatureHealth)

you didn't said which tfs you are using, so I'm just giving random answer :)
 
Back
Top