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

Specified creature summon count

Chaos Origin

New Member
Joined
Oct 31, 2017
Messages
6
Reaction score
2
Hello everyone, I wanted to create a spell that summons a specified creature so that different vocasions have their own creatures. I'm totally new to this, but after some struggle I came up with this:
Lua:
function onCastSpell(cid, var)
local config =
{
    playerpos = getPlayerPosition(cid),
    creature = "creature name",
    effects = {CONST_ME_MAGIC_RED, CONST_ME_POFF}
}    
local summon = doSummonCreature(cid, config.creature, config.playerpos)
if (summon == RETURNVALUE_NOERROR) then 
    doConvinceCreature(cid, summon)
    doSendMagicEffect(config.playerpos, config.effects[1])
    return true
else
    doSendMagicEffect(config.playerpos, config.effects[2])
    doPlayerSendDefaultCancel(cid, config.playerpos)
    return false
end
end
And it works, my only problem is that it allows player to have unlimited summons and to be honest I have no clue how to put some limit here. Can anyone give some tips on how to do it?
 
Hello everyone, I wanted to create a spell that summons a specified creature so that different vocasions have their own creatures. I'm totally new to this, but after some struggle I came up with this:
Lua:
function onCastSpell(cid, var)
local config =
{
    playerpos = getPlayerPosition(cid),
    creature = "creature name",
    effects = {CONST_ME_MAGIC_RED, CONST_ME_POFF}
}   
local summon = doSummonCreature(cid, config.creature, config.playerpos)
if (summon == RETURNVALUE_NOERROR) then
    doConvinceCreature(cid, summon)
    doSendMagicEffect(config.playerpos, config.effects[1])
    return true
else
    doSendMagicEffect(config.playerpos, config.effects[2])
    doPlayerSendDefaultCancel(cid, config.playerpos)
    return false
end
end
And it works, my only problem is that it allows player to have unlimited summons and to be honest I have no clue how to put some limit here. Can anyone give some tips on how to do it?
Lua:
if getCreatureSummons(cid) >= 2 then
    return false
end
 
Lua:
if getCreatureSummons(cid) >= 2 then
    return false
end

getCreatureSummons(cid) returns a table of summons, so I guess he'd need to do a table.maxn(getCreatureSummons(cid)) for that check :p

Put this by the start of the script:
Code:
if table.maxn(getCreatureSummons(cid)) > 2 then
doPlayerSendCancel(cid, "You have reached the max amount of summons.")
return false
end
 
getCreatureSummons(cid) returns a table of summons, so I guess he'd need to do a table.maxn(getCreatureSummons(cid)) for that check :p

Put this by the start of the script:
Code:
if table.maxn(getCreatureSummons(cid)) > 2 then
doPlayerSendCancel(cid, "You have reached the max amount of summons.")
return false
end
Lets say they have 2 summons 2 isn't greater than 2, probably just a typo right?
Code:
if table.maxn(getCreatureSummons(cid)) >= 2 then
doPlayerSendCancel(cid, "You have reached the max amount of summons.")
return false
end
This could also be done like this using the hash character (#) which returns the length/size of the table
Code:
if #getCreatureSummons(cid) >= 2 then
doPlayerSendCancel(cid, "You have reached the max amount of summons.")
return false
end
But can also be used for other things as well such as strings. :)
Code:
print(table.maxn({}), #{}, #"this is a string")
-- prints  0    0    16
 
Lets say they have 2 summons 2 isn't greater than 2, probably just a typo right?
Code:
if table.maxn(getCreatureSummons(cid)) >= 2 then
doPlayerSendCancel(cid, "You have reached the max amount of summons.")
return false
end
This could also be done like this using the hash character (#) which returns the length/size of the table
Code:
if #getCreatureSummons(cid) >= 2 then
doPlayerSendCancel(cid, "You have reached the max amount of summons.")
return false
end
But can also be used for other things as well such as strings. :)
Code:
print(table.maxn({}), #{}, #"this is a string")
-- prints  0    0    16

Yeah that was a typo, my bad. Though he can change the condition/limit number to whatever he wants.
I like to use table.maxn because # can be inconsistent in cases.
 
Lets say they have 2 summons 2 isn't greater than 2, probably just a typo right?
Code:
if table.maxn(getCreatureSummons(cid)) >= 2 then
doPlayerSendCancel(cid, "You have reached the max amount of summons.")
return false
end
This could also be done like this using the hash character (#) which returns the length/size of the table
Code:
if #getCreatureSummons(cid) >= 2 then
doPlayerSendCancel(cid, "You have reached the max amount of summons.")
return false
end
But can also be used for other things as well such as strings. :)
Code:
print(table.maxn({}), #{}, #"this is a string")
-- prints  0    0    16
Not a typo, in normal tibia you can use Undead Legion to get more than two summons at a time
so, we want to check how many summons they currently have and the maximum they are allowed to creates with this particular spell
 
Not a typo, in normal tibia you can use Undead Legion to get more than two summons at a time
so, we want to check how many summons they currently have and the maximum they are allowed to creates with this particular spell

This is true,
May want to do something like

Lua:
local summs, legioncount= getCreatureSummons(cid), 0

    for i = 1, table.maxn(summs) do
        if getCreatureName(summs[i]) == "Skeleton" then
            legioncount += 1
        end
    end
  
    if (table.maxn(summs) - legioncount) >= 2 then
        doPlayerSendCancel(cid, "You have reached the max amount of summons.")
        return false
    end

Which will take legion summons out of the equation, but the problem is that "Skeleton" can also be summoned with utevo res regularly, to which I'd say it would be the best to make undead legion spawn custom skeletons with a different name.
 
Thanks for all the replies!
But I still cant't get it to work. If I use any of solutions you guys gave me it just stops reading script as a spell. No errors, no crashes, just like this script was not even there. Probably I'm screwing something up, but I can't figure it out.
 
Thanks for all the replies!
But I still cant't get it to work. If I use any of solutions you guys gave me it just stops reading script as a spell. No errors, no crashes, just like this script was not even there. Probably I'm screwing something up, but I can't figure it out.

Can you post full script?
 
Sure. At first I tried to put it in front of the whole thing like this:
Lua:
if table.maxn(getCreatureSummons(cid)) >= 2 then
    doPlayerSendCancel(cid, "You have reached the max amount of summons.")
    return false
end
function onCastSpell(cid, var)
local config =
{
    playerpos = getPlayerPosition(cid),
    creature = "nazwa potwora",
    effects = {CONST_ME_MAGIC_RED, CONST_ME_POFF}
}    
local summon = doSummonCreature(cid, config.creature, config.playerpos)
if (summon == RETURNVALUE_NOERROR) then
    doConvinceCreature(cid, summon) 
    doSendMagicEffect(config.playerpos, config.effects[1])
    return true
else
    doSendMagicEffect(config.playerpos, config.effects[2])
    doPlayerSendDefaultCancel(cid, config.playerpos)
    return false
end
end
Then it acted like its not there, same if I've put it anywhere else except this:
Lua:
function onCastSpell(cid, var)
local config =
{
    playerpos = getPlayerPosition(cid),
    creature = "nazwa potwora",
    effects = {CONST_ME_MAGIC_RED, CONST_ME_POFF}
}    
if table.maxn(getCreatureSummons(cid)) >= 2 then
    doPlayerSendCancel(cid, "You have reached the max amount of summons.")
    return false
end
local summon = doSummonCreature(cid, config.creature, config.playerpos)
    doConvinceCreature(cid, summon)
if (summon == RETURNVALUE_NOERROR) then
    doConvinceCreature(cid, summon) 
    doSendMagicEffect(config.playerpos, config.effects[1])
    return true
else
    doSendMagicEffect(config.playerpos, config.effects[2])
    doPlayerSendDefaultCancel(cid, config.playerpos)
    return false
end
end
Now it shows error: "Lua Script Error: [Spell Interface]
data/spells/scripts/przyzwanie.lua:eek:nCastSpell

data/spells/scripts/przyzwanie.lua:8: attempt to call global 'getCreatureSummons' <a nil value>

So I guess now it reads the script, but something is wrong with it.
 
Sure. At first I tried to put it in front of the whole thing like this:
Lua:
if table.maxn(getCreatureSummons(cid)) >= 2 then
    doPlayerSendCancel(cid, "You have reached the max amount of summons.")
    return false
end
function onCastSpell(cid, var)
local config =
{
    playerpos = getPlayerPosition(cid),
    creature = "nazwa potwora",
    effects = {CONST_ME_MAGIC_RED, CONST_ME_POFF}
}   
local summon = doSummonCreature(cid, config.creature, config.playerpos)
if (summon == RETURNVALUE_NOERROR) then
    doConvinceCreature(cid, summon)
    doSendMagicEffect(config.playerpos, config.effects[1])
    return true
else
    doSendMagicEffect(config.playerpos, config.effects[2])
    doPlayerSendDefaultCancel(cid, config.playerpos)
    return false
end
end
Then it acted like its not there, same if I've put it anywhere else except this:
Lua:
function onCastSpell(cid, var)
local config =
{
    playerpos = getPlayerPosition(cid),
    creature = "nazwa potwora",
    effects = {CONST_ME_MAGIC_RED, CONST_ME_POFF}
}   
if table.maxn(getCreatureSummons(cid)) >= 2 then
    doPlayerSendCancel(cid, "You have reached the max amount of summons.")
    return false
end
local summon = doSummonCreature(cid, config.creature, config.playerpos)
    doConvinceCreature(cid, summon)
if (summon == RETURNVALUE_NOERROR) then
    doConvinceCreature(cid, summon)
    doSendMagicEffect(config.playerpos, config.effects[1])
    return true
else
    doSendMagicEffect(config.playerpos, config.effects[2])
    doPlayerSendDefaultCancel(cid, config.playerpos)
    return false
end
end
Now it shows error: "Lua Script Error: [Spell Interface]
data/spells/scripts/przyzwanie.lua:eek:nCastSpell

data/spells/scripts/przyzwanie.lua:8: attempt to call global 'getCreatureSummons' <a nil value>

So I guess now it reads the script, but something is wrong with it.

Yeah, the 2nd script is the correct place to insert this snippet, but strange, it appears you don't have a function called getCreatureSummons, which is rather odd. Which TFS are you using? Maybe it's called getPlayerSummons there? (Once again, odd naming, since monsters can have their own summons too). Check your LUA_DOCUMENTATION or source file luascript.cpp and search for functions regarding summons, something like this should exist

C++:
    //getCreatureSummons(cid)
    lua_register(L, "getCreatureSummons", LuaScriptInterface::luaGetCreatureSummons);
 
To be honoest I don't even know if I am using TFS, as I said, I'm completely new to all of this. I got Stigma2 engine for Tibia 8.1 from a friend of mine and we decided to use this one for our server 'cause its fully translated to polish (my native launguage), but its years old and and I can't find any file with .cpp extension. And I also don't know where to look for LUA_DOCUMENTATION.
Edit: I also tried getPlayerSummons, but same error occurs, just with Player instead of Creature.
 
Last edited:
To be honoest I don't even know if I am using TFS, as I said, I'm completely new to all of this. I got Stigma2 engine for Tibia 8.1 from a friend of mine and we decided to use this one for our server 'cause its fully translated to polish (my native launguage), but its years old and and I can't find any file with .cpp extension. And I also don't know where to look for LUA_DOCUMENTATION.
Edit: I also tried getPlayerSummons, but same error occurs, just with Player instead of Creature.

Yeah, that's a bit of a problem. Usually, you wanna specify that in your first post so people can know how to help you, since various engines have various ways of doing things. If you don't have any .cpp files, it's likely you don't have the sources for your serv, which is another big problem. At this point, I really don't know what else to tell you, except maybe do a global keyword search (via notepad++ or some other tool) to find any instances of functions related to summons in your entire server's folder. If that doesn't yield any results either, you wanna either try to find the sources of this engine or switch to another one so you can receive proper support when needed, since this one seems really outdated.
 
Yeah, that's a bit of a problem. Usually, you wanna specify that in your first post so people can know how to help you, since various engines have various ways of doing things. If you don't have any .cpp files, it's likely you don't have the sources for your serv, which is another big problem. At this point, I really don't know what else to tell you, except maybe do a global keyword search (via notepad++ or some other tool) to find any instances of functions related to summons in your entire server's folder. If that doesn't yield any results either, you wanna either try to find the sources of this engine or switch to another one so you can receive proper support when needed, since this one seems really outdated.
You're right, I should've specified that at the beggining, know I will know. I did glogal search but it did found nothing. Well, I'll take your advice and I'll search for another engine. Either way thank you for your time and patience, I'm sure that now I'll be able to figure it out when I'll get proper engine with all necessary files.
 
Back
Top