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);
}
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
Requires more checks.
which would be, by example?
which would be, by example?
if getMonsterInfo(name) and getMonsterInfo(name).summonable then
[..]
if getPlayerMana(cid) >= getMonsterInfo(name).manaCost
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
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!![]()
oh reallyYour scripts is poor written because of the lack of human-understanding keywords
@topic:
Evil Hero is a great scripter!![]()