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

[SOLVED][C++] Return false if has storage value X

richux

Tibera.org
Joined
Aug 18, 2008
Messages
3,666
Reaction score
26
Location
---------
Issue solved differently, just by checking storage value of player in spells.cpp summonCreature spell.

Code:
[code]	std::string stor;
	player->getStorage(9000, stor);
	if(stor == "1") 
	{
		player->sendCancel("You are not allowed to use summon spells at the moment.");
		g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
		return false;
	}

thx to Migxxx

------
Hello!

So, I am total newbie in C++ and I would like to add a player storage check for summon creature spell. I tried it myself but I am getting compilation error. It's probably because, to do storage check in spell.cpp file, you need to include something or add some extra parameters for the spell function. As I understand, storage in C++ is being checked like this:

Code:
player->getStorage(storage, id)

Here is the summonCreature code 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))
	{
	// I tired it this way, but I am getting compilation error S:	if(player->getStorage(323323, 1)) return false;

		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->postSpell(player, (uint32_t)manaCost, (uint32_t)spell->getSoulCost());
		g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_WRAPS_BLUE);
		return true;
	}

	player->sendCancelMessage(ret);
	g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
	return false;
}
 
Last edited:
make it as a talkaction in lua :p
LUA:
local rate, max = getConfigInfo('rateMonsterMana'), getConfigInfo('maxPlayerSummons')

function onSay(cid, words, param, channel)
	if getPlayerFlagValue(cid, PLAYERFLAG_CANNOTUSESPELLS) then
		return false
	end

	if not getPlayerFlagValue(cid, PLAYERFLAG_IGNORESPELLCHECK) then
		if not getPlayerFlagValue(cid, PLAYERFLAG_IGNOREPROTECTIONZONE) and getTileInfo(getThingPos(cid).protection) then
			return doPlayerSendDefaultCancel(cid, RETURNVALUE_ACTIONNOTPERMITTEDINANOPVPZONE)
		end

		if not getPlayerFlagValue(cid, PLAYERFLAG_HASNOEXHAUSTION) and hasCondition(cid, CONDITION_EXHAUST, EXHAUST_COMBAT) then
			doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
			return doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
		end
		
		if getPlayerLevel(cid) < 25 then
			doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHLEVEL)
			doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
			return true
		end

		if not isSorcerer(cid) and not isDruid(cid) then
			doPlayerSendDefaultCancel(cid, RETURNVALUE_YOURVOCATIONCANNOTUSETHISSPELL)
			doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
			return true
		end
	end
	
	if not param or param == '' then
		doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
		doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
		return true
	end

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

	local manaCost = i.manaCost * rate

	if not getPlayerFlagValue(cid, PLAYERFLAG_CANSUMMONALL) then
		if not i.summonable or getCreatureSkullType(cid) == SKULL_BLACK then
			doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
			doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
			return tr
		elseif getPlayerMana(cid) < manaCost then
			doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHMANA)
			doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
			return true
		elseif #getCreatureSummons(cid) >= max then
			doPlayerSendCancel(cid, 'You cannot summon more creatures.')
			doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
			return true
		end
	end

	local ret = doSummonMonster(cid, param)
	if ret == RETURNVALUE_NOERROR then
		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
 
Last edited:
make it as a talkaction in lua :p
LUA:
local rate, max = getConfigInfo('rateMonsterMana'), getConfigInfo('maxPlayerSummons')

function onSay(cid, words, param, channel)
	if getPlayerFlagValue(cid, PLAYERFLAG_CANNOTUSESPELLS) then
		return false
	end

	if not getPlayerFlagValue(cid, PLAYERFLAG_IGNORESPELLCHECK) then
		if not getPlayerFlagValue(cid, PLAYERFLAG_IGNOREPROTECTIONZONE) and getTileInfo(getThingPos(cid).protection) then
			return doPlayerSendDefaultCancel(cid, RETURNVALUE_ACTIONNOTPERMITTEDINANOPVPZONE)
		end

		if not getPlayerFlagValue(cid, PLAYERFLAG_HASNOEXHAUSTION) and hasCondition(cid, CONDITION_EXHAUST, EXHAUST_COMBAT) then
			doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
			return doPlayerSendDefaultCancel(cid, RETURNVALUE_YOUAREEXHAUSTED)
		end
		
		if getPlayerLevel(cid) < 25 then
			doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHLEVEL)
			doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
			return true
		end

		if not isSorcerer(cid) and not isDruid(cid) then
			doPlayerSendDefaultCancel(cid, RETURNVALUE_YOURVOCATIONCANNOTUSETHISSPELL)
			doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
			return true
		end
	end
	
	if not param or param == '' then
		doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
		doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
		return true
	end

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

	local manaCost = i.manaCost * rate

	if not getPlayerFlagValue(cid, PLAYERFLAG_CANSUMMONALL) then
		if not i.summonable or getCreatureSkullType(cid) == SKULL_BLACK then
			doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTPOSSIBLE)
			doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
			return tr
		elseif getPlayerMana(cid) < manaCost then
			doPlayerSendDefaultCancel(cid, RETURNVALUE_NOTENOUGHMANA)
			doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
			return true
		elseif #getCreatureSummons(cid) >= max then
			doPlayerSendCancel(cid, 'You cannot summon more creatures.')
			doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
			return true
		end
	end

	local ret = doSummonMonster(cid, name)
	if ret == RETURNVALUE_NOERROR then
		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

thank you. Thu I would like it to be doen in C++
 
Last edited:
Issue was solved differently, just by checking storage value of player in spells.cpp summonCreature spell.

Code:
[code]	std::string stor;
	player->getStorage(9000, stor);
	if(stor == "1") 
	{
		player->sendCancel("You are not allowed to use summon spells at the moment.");
		g_game.addMagicEffect(player->getPosition(), MAGIC_EFFECT_POFF);
		return false;
	}
 
Back
Top