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

Why is summoning a function?

Slain

TrueHavoc.com
Joined
Nov 27, 2008
Messages
2,243
Reaction score
31
Would be nice if summoning was a spell, not a function..would be a lot easier to mess with it in other scripts then..for example idk how to turn off summoning in X area.. lol

sry for poor explanation :P im hungover..
 
Because scripting it in Lua would require additional Lua functions to be implemented, and in my opinion we already have enough bloat.

Anyways, here's the function from spells.cpp:
Code:
bool InstantSpell::SummonMonster(const InstantSpell* spell, Creature* creature, const std::string& param)
{
	Player* player = creature->getPlayer();
	if(!player)
		return false;

	MonsterType* mType = g_monsters.getMonsterType(param);
	if(!mType)
	{
		player->sendCancelMessage(RET_NOTPOSSIBLE);
		g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
		return false;
	}

	int32_t manaCost = (int32_t)(mType->manaCost * g_config.getDouble(ConfigManager::RATE_MONSTER_MANA));
	if(!player->hasFlag(PlayerFlag_CanSummonAll))
	{
		if(player->getSkull() == SKULL_BLACK)
		{
			player->sendCancelMessage(RET_NOTPOSSIBLE);
			g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
			return false;
		}

		if(!mType->isSummonable)
		{
			player->sendCancelMessage(RET_NOTPOSSIBLE);
			g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
			return false;
		}

		if(player->getMana() < manaCost)
		{
			player->sendCancelMessage(RET_NOTENOUGHMANA);
			g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
			return false;
		}

		if((int32_t)player->getSummonCount() >= g_config.getNumber(ConfigManager::MAX_PLAYER_SUMMONS))
		{
			player->sendCancel("You cannot summon more creatures.");
			g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
			return false;
		}
	}

	ReturnValue ret = g_game.placeSummon(creature, param);
	if(ret == RET_NOERROR)
	{
		spell->postCastSpell(player, (uint32_t)manaCost, (uint32_t)spell->getSoulCost());
		g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_WRAPS_BLUE);
	}
	else
	{
		player->sendCancelMessage(ret);
		g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
	}

	return (ret == RET_NOERROR);
}

Or, is that so?
Oh wait - how do I get the parameter?
 
Last edited:
i've made this azzap, not sure if it's correctly working but test it.

LUA:
function spellSummonMonster(cid, name, count, maxSummons) -- count can't be higher then maxSummons!
local counting = 0
local monster = doSummonMonster(cid, name)
	if getCreatureSummonCount(cid) < maxSummons then
		if count ~= 1 then
			while getCreatureSummonCount(cid) < maxSummons  or counting < count do
				counting = counting + 1
				doConvinceCreature(cid, monster)
			end
		else
			doConvinceCreature(cid, monster)
		end
	else
		doPlayerSendCancel(cid,"You already reached the maximum of summons.")
	end
	return TRUE
end


kind regards, Evil Hero
 
Well, was re writing the entire thing, while you had posted.

LUA:
function spellSummonMonster(cid, name, count, maxSummons, vocations) -- count can't be higher then maxSummons! / vocations is supposed to be a table.
local counting = 0
local monster = doSummonMonster(cid, name)
	if getMonsterInfo(name).name == nil then
		doPlayerSendCancel(cid,"This monster does not exist.")
		return true
	end
	if getCreatureSkullType(cid) == SKULL_BLACK then
		doPlayerSendCancel(cid,"Black skulled players can't summon.")
		return true
	end
	if(isInArray(vocations, getPlayerVocation(cid)) == false then
		doPlayerSendCancel(cid,"Your vocation is not allowed to cast this spell.")
		return true
	end
	if getCreatureSummonCount(cid) >= maxSummons then
		doPlayerSendCancel(cid,"You already reached the maximum of summons.")
		return true
	end
	if getMonsterInfo(monster).summonable == false or getPlayerGroupId(cid) < 4 then
		doPlayerSendCancel(cid," Monster is not summonable.")
		return true
	end
	if getCreatureMana(cid) < getMonsterInfo(name).manacost or getPlayerGroupId(cid) < 4 then
		doPlayerSendCancel(cid,"You don't have enough mana.")
		return true
	end
	if count ~= 1 then
		while getCreatureMana(cid) > getMonsterInfo(name).manacost and getCreatureSummonCount(cid) < maxSummons  or counting < count do
			counting = counting + 1
			doConvinceCreature(cid, monster)
			doCreatureAddMana(cid, -(getMonsterInfo(name).manacost))
		end
	else
		doConvinceCreature(cid, monster)
		doCreatureAddMana(cid, -(getMonsterInfo(name).manacost))
	end
	return true
end

The first one was meant to be basic, so he can add the extra stuff on his own, this one is with all the checks you'd need to.

Well, was looking through sources and checking up the getMonsterInfo function, hopefully it works the way I thought it would :p


kind regards, Evil Hero.
 
Code:
function spellSummonMonster(cid, name)
	if not isPlayer(cid) then
		return false
	end

	local i = getMonsterInfo(name)
	if not i then
		doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
		doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
	end

	local manaCost = i.manaCost * getConfigInfo('rateMonsterMana')

	if not getPlayerFlagValue(cid, PLAYERFLAG_CANSUMMONALL) then
		if getCreatureSkullType(cid) == SKULL_BLACK or not i.summonable then
			doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
			doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
			return false
		elseif getPlayerMana(cid) < manaCost then
			doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHMANA)
			doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
			return false
		elseif getCreatureSummonCount(cid) >= getConfigInfo('maxPlayerSummons') then
			doPlayerSendCancel(cid, "You cannot summon more creatures.")
			doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
			return false
		end
	end

	local ret = doSummonMonster(cid, name)
	if ret == RETURNVALUE_NOERROR then
		doConvinceCreature(cid, ret)
		doCreatureAddMana(cid, - i.manaCost, false)
		doPlayerAddSpentMana(cid, i.manaCost)
		doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
	else
		doPlayerSendDefaultCancel(cid, ret)
		doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
	end

	return (ret == RETURNVALUE_NOERROR)
end
 
Code:
function spellSummonMonster(cid, name)
	if not isPlayer(cid) then
		return false
	end

	local i = getMonsterInfo(name)
	if not i then
		doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
		doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
	end

	local manaCost = i.manaCost * getConfigInfo('rateMonsterMana')

	if not getPlayerFlagValue(cid, PLAYERFLAG_CANSUMMONALL) then
		if getCreatureSkullType(cid) == SKULL_BLACK or not i.summonable then
			doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
			doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
			return false
		elseif getPlayerMana(cid) < manaCost then
			doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHMANA)
			doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
			return false
		elseif getCreatureSummonCount(cid) >= getConfigInfo('maxPlayerSummons') then
			doPlayerSendCancel(cid, "You cannot summon more creatures.")
			doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
			return false
		end
	end

	local ret = doSummonMonster(cid, name)
	if ret == RETURNVALUE_NOERROR then
		doConvinceCreature(cid, ret)
		doCreatureAddMana(cid, - i.manaCost, false)
		doPlayerAddSpentMana(cid, i.manaCost)
		doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
	else
		doPlayerSendDefaultCancel(cid, ret)
		doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
	end

	return (ret == RETURNVALUE_NOERROR)
end

Your scripts is poor written because of the lack of human-understanding keywords

@topic:
Evil Hero is a great scripter! :D
 
Back
Top