• 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 Spell issue

gabriel28

Member
Joined
Mar 16, 2012
Messages
199
Solutions
6
Reaction score
24
The spells works in necessity of have a previous summon, if the player have it, will remove this previous summon and summon another five. If not, will return false.
I'm sucesfull in make spell remove a summon and make another five, but I fail in get this previous summons to make spell work well (because the player can make another summons, so I need to get this one expecifically). I tried so many things but I haven't sucess. So I came here to call for help.

Thanks in advance.

My try:
Lua:
function onCastSpell(cid, var)
local playerpos = getPlayerPosition(cid)
local position1 = {x=getPlayerPosition(cid).x+1, y=getPlayerPosition(cid).y+1, z=getPlayerPosition(cid).z}
local position2 = {x=getPlayerPosition(cid).x, y=getPlayerPosition(cid).y, z=getPlayerPosition(cid).z}
local maxSummons = 5
local su = {
sa = {"Big Wolf"}
}
if not su.sa[getCreatureName(getCreatureSummons(cid))] then
doPlayerSendCancel(cid, "You need to summon a Big Wolf first.") return false
else
for _, pid in ipairs(getCreatureSummons(cid)) do
doRemoveCreature(pid)
end
for n = 1, maxSummons do
                if #getCreatureSummons(cid) >= maxSummons then
                        break
                end
local mon = doCreateMonster("Wolf", playerpos)
doConvinceCreature(cid, mon)
doSendMagicEffect(position1, 152)
doSendMagicEffect(position2, 111)
end
end
return true
end
 
Solution
I made this a little big so you can see what is being done in the code to check for everything.

Code:
local maxSummons = 4 --Wolfs + 1 for Big Wolf
local summonNeeded = "Big Wolf"

--I made this outside the code so you can see it easier.
local function getSummonCount(cid)
    local count = 0
    for i = 1 #getCreatureSummons(cid) do
        count = count + 1
    end
return count
end

local function playerHasRequiredSummon(cid)
    local summons = getPlayerSummons(cid)
    for i = 1, #summons do
        if getCreatureName(summons[i]) == summonNeeded then
            return true
        end
    end

    return false
end

function onCastSpell(cid, var)
    if getSummonCount(cid) >= maxSummons then
        doPlayerSendCancel(cid, "You have...
I made this a little big so you can see what is being done in the code to check for everything.

Code:
local maxSummons = 4 --Wolfs + 1 for Big Wolf
local summonNeeded = "Big Wolf"

--I made this outside the code so you can see it easier.
local function getSummonCount(cid)
    local count = 0
    for i = 1 #getCreatureSummons(cid) do
        count = count + 1
    end
return count
end

local function playerHasRequiredSummon(cid)
    local summons = getPlayerSummons(cid)
    for i = 1, #summons do
        if getCreatureName(summons[i]) == summonNeeded then
            return true
        end
    end

    return false
end

function onCastSpell(cid, var)
    if getSummonCount(cid) >= maxSummons then
        doPlayerSendCancel(cid, "You have too many summons.")
    return false
    end

    if not playerHasRequiredSummon(cid) then
        doPlayerSendCancel(cid, "You must summon a "..summonNeeded.." first.")
    return false
    end

    local count = getSummonCount(cid)
    while (count < maxSummons) do
        local mon = doCreateMonster("Wolf", getPlayerPosition(cid))
        doConvinceCreature(cid, mon)
        doSendMagicEffect(getCreaturePosition(mon), 152)
        doSendMagicEffect(getPlayerPosition(cid), 111)
        count = count + 1
    end
return true
end

This is set up so the player can cast the spell if he has only 3 wolf + 1 big wolf and it will summon 1 more wolf.
or if he has 2 wolfs + 1 big wolf he can summon 2 more wolfs
The total amount he can have out is always: 4 wolfs + 1 big wolf.
 
Last edited:
Solution
@Itutorial

Thanks a lot.
Just missed the part that remove the previous summon, but your code is so good and easy to read, even to a newbie like me, that I made this change by my own.
Thank you again.
 
Back
Top