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

[C++/Creaturescripts] When player no stroage id, monster dont attack

Erexo

Kage
Premium User
Joined
Mar 27, 2010
Messages
741
Solutions
5
Reaction score
193
Location
Pr0land
GitHub
Erexo
Hello,
i looking for a script:
-When player DONT have stroage id 8000,15 monster with name "demon lord" cant attack him (like a gm :p).
-When dont have this stroage, cant attack this monster too...


Someone can? please :(
 
I am suupposing you using 0.4 server if not then you would need some changes.
You can try that thou i am not sure

Goto monster.cpp find selectTarget method and replace with this [added stuff are shown]
PHP:
bool Monster::selectTarget(Creature* creature)
{
#ifdef __DEBUG__
	std::clog << "Selecting target... " << std::endl;
#endif
	if(!isTarget(creature))
		return false;

	CreatureList::iterator it = std::find(targetList.begin(), targetList.end(), creature);
	if(it == targetList.end())
	{
		//Target not found in our target list.
#ifdef __DEBUG__
		std::clog << "Target not found in targetList." << std::endl;
#endif
		return false;
	}

	if((isHostile() || isSummon()) && setAttackedCreature(creature) && !isSummon())
		Dispatcher::getInstance().addTask(createTask(
			boost::bind(&Game::checkCreatureAttack, &g_game, getID())));
	{//added

		Player* player = creature->getPlayer();//added
		std::string value = "15" ; //added
		if(getName() == "Demon Lord" && player && !(player->getStorage("8000",value)) )//added
			return false;//added
			
		return setFollowCreature(creature, true);
	}//added
}


This should be for monsters, as for players it can be done in lua
 
Last edited:
Try to change for that on 0.3.6
PHP:
bool Monster::selectTarget(Creature* creature)
{
#ifdef __DEBUG__
	std::cout << "Selecting target... " << std::endl;
#endif
	if(!isTarget(creature))
		return false;

	CreatureList::iterator it = std::find(targetList.begin(), targetList.end(), creature);
	if(it == targetList.end())
	{
		//Target not found in our target list.
#ifdef __DEBUG__
		std::cout << "Target not found in targetList." << std::endl;
#endif
		return false;
	}

	Player* player = creature->getPlayer();
	std::string value = "15";
	if (getName() == "Demon Lord" && player && !player->getStorage(8000,value) )
		return false;

	if((isHostile() || isSummon()) && setAttackedCreature(creature) && !isSummon())
		Dispatcher::getInstance().addTask(createTask(
			boost::bind(&Game::checkCreatureAttack, &g_game, getID())));

	return setFollowCreature(creature, true);
}
 
Last edited:
Fixed version, update every hit check if storage changed

goto monster.xml
search for
PHP:
void Monster::doAttacking(uint32_t interval)
{
	if(!attackedCreature || (isSummon() && attackedCreature == this))
		return;

under it paste
PHP:
Player* player = attackedCreature->getPlayer();
	std::string value;
	std::string check = "15";
	if (getName() == "Rat" && player && ( !(player->getStorage("8000",value)) || check != value ) )
	{
		setFollowCreature(NULL);
		setAttackedCreature(NULL);
		searchTarget(TARGETSEARCH_NEAREST);
		
	}

now replace this function
PHP:
bool Monster::selectTarget(Creature* creature)
{
#ifdef __DEBUG__
	std::cout << "Selecting target... " << std::endl;
#endif
	if(!isTarget(creature))
		return false;

	CreatureList::iterator it = std::find(targetList.begin(), targetList.end(), creature);
	if(it == targetList.end())
	{
		//Target not found in our target list.
#ifdef __DEBUG__
		std::cout << "Target not found in targetList." << std::endl;
#endif
		return false;
	}
	if((isHostile() || isSummon()) && setAttackedCreature(creature) && !isSummon())
		Dispatcher::getInstance().addTask(createTask(
			boost::bind(&Game::checkCreatureAttack, &g_game, getID())));

	return setFollowCreature(creature, true);
}

With this
PHP:
bool Monster::selectTarget(Creature* creature)
{
#ifdef __DEBUG__
	std::cout << "Selecting target... " << std::endl;
#endif
	if(!isTarget(creature))
		return false;

	CreatureList::iterator it = std::find(targetList.begin(), targetList.end(), creature);
	if(it == targetList.end())
	{
		//Target not found in our target list.
#ifdef __DEBUG__
		std::cout << "Target not found in targetList." << std::endl;
#endif
		return false;
	}

	Player* player = creature->getPlayer();
	std::string value;
	std::string check = "15";  
	if (getName() == "Rat" && player && ( !(player->getStorage("8000",value)) || check != value ) )
		return false;

	if((isHostile() || isSummon()) && setAttackedCreature(creature) && !isSummon())
		Dispatcher::getInstance().addTask(createTask(
			boost::bind(&Game::checkCreatureAttack, &g_game, getID())));

	return setFollowCreature(creature, true);
}
 
Last edited:
Aff,
i set everything ok.
NOT WORKING

Remove "" from stroage
NOT WORKING

Wtf? :(

I dont have a monster.xml, i set this in monster.cpp
or
Cant make any luafunction for this?
 
Last edited:
Maybe, for players, something like this???
Lua:
local storage = 8000
function onAttack(cid, target)
if isMonster(target) then
if getPlayerStorageValue(cid, storage) == -1 then
return false
end
end
return true
end
 
I hope youvn't just blindly copied it without changing anything, you need to change the monster name from rat to your monster, and to check 8000 change it to the key and check "15" change it for value.
 
So many players wanna get this? :D
(Rep if you want :D)

DemonLord.lua
Lua:
function onAttack(cid, target)
   if(isPlayer(cid) and getCreatureName(target):lower() == "demon lord") then
      if(getPlayerStorageValue(cid, 8000) ~= 25) then return false end
   elseif(isMonster(cid) and isPlayer(target)) then
      if(getPlayerStorageValue(target, 8000) ~= 25) then return false end
   end
   return true
end

creaturescripts.xml
XML:
<event type="attack" name="DemonLord" event="script" value="DemonLord.lua"/>

in monster file after "flags":
XML:
<scripts>
<script name="DemonLord"/>
</scripts>

HERE U ARE! (I dont wanna see this in other side...)
 
Back
Top