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

[Monster] Passive until attacked

Herpicus

Web Developer
Joined
Jun 21, 2008
Messages
1,644
Reaction score
94
Location
British Columbia
Hello fellow OtLanders, I am in need of some assistance!

I would like someone to create a function for monsters so that they are passive until they are attacked.

What does that mean you might ask. Well allow me to explain!

Basically if a monster attribute is passive then it will not attack you until you attack the monster. So you can walk right beside it and it will not do anything, but once you attack. Shit will be stormed and the monster will attack back.

Requesting function for 0.2.10 or 0.4
Either or Both :d

Thank you for your time. I have 10 Euros on PayPal it could be yours if assist with this request.

Again, Thank you for your time.
 
Since you are not a donator, this goes for 0.2:
monster.cpp:
Code:
void Monster::doAttacking(uint32_t interval)
{
	if(!attackedCreature || (isSummon() && attackedCreature == this))
		return;

[b][color="red"]   if (!attackedCreature)
        return;[/color][/b]

	bool updateLook = true;
	bool outOfRange = true;

	resetTicks = interval != 0;
	attackTicks += interval;

	const Position& myPos = getPosition();
	const Position& targetPos = attackedCreature->getPosition();

	for(SpellList::iterator it = mType->spellAttackList.begin(); it != mType->spellAttackList.end(); ++it)
	{
		bool inRange = false;
		if(canUseSpell(myPos, targetPos, *it, interval, inRange))
		{
			if(it->chance >= (uint32_t)random_range(1, 100))
			{
				if(updateLook)
				{
					updateLookDirection();
					updateLook = false;
				}

				minCombatValue = it->minCombatValue;
				maxCombatValue = it->maxCombatValue;
				it->spell->castSpell(this, attackedCreature);
				if(it->isMelee)
					extraMeleeAttack = false;

#ifdef __DEBUG__
				static uint64_t prevTicks = OTSYS_TIME();
				std::cout << "doAttacking ticks: " << OTSYS_TIME() - prevTicks << std::endl;
				prevTicks = OTSYS_TIME();
#endif
			}
		}

		if(inRange)
			outOfRange = false;
		else if(it->isMelee)
		{
			//melee swing out of reach
			extraMeleeAttack = true;
		}
	}

	if(updateLook)
		updateLookDirection();

	if(resetTicks)
		attackTicks = 0;
}
 
Since you are not a donator, this goes for 0.2:
monster.cpp:
Code:
void Monster::doAttacking(uint32_t interval)
{
	if(!attackedCreature || (isSummon() && attackedCreature == this))
		return;

[b][color="red"]   if (!attackedCreature)
        return;[/color][/b]

	bool updateLook = true;
	bool outOfRange = true;

	resetTicks = interval != 0;
	attackTicks += interval;

	const Position& myPos = getPosition();
	const Position& targetPos = attackedCreature->getPosition();

	for(SpellList::iterator it = mType->spellAttackList.begin(); it != mType->spellAttackList.end(); ++it)
	{
		bool inRange = false;
		if(canUseSpell(myPos, targetPos, *it, interval, inRange))
		{
			if(it->chance >= (uint32_t)random_range(1, 100))
			{
				if(updateLook)
				{
					updateLookDirection();
					updateLook = false;
				}

				minCombatValue = it->minCombatValue;
				maxCombatValue = it->maxCombatValue;
				it->spell->castSpell(this, attackedCreature);
				if(it->isMelee)
					extraMeleeAttack = false;

#ifdef __DEBUG__
				static uint64_t prevTicks = OTSYS_TIME();
				std::cout << "doAttacking ticks: " << OTSYS_TIME() - prevTicks << std::endl;
				prevTicks = OTSYS_TIME();
#endif
			}
		}

		if(inRange)
			outOfRange = false;
		else if(it->isMelee)
		{
			//melee swing out of reach
			extraMeleeAttack = true;
		}
	}

	if(updateLook)
		updateLookDirection();

	if(resetTicks)
		attackTicks = 0;
}

Like away, you never let me down. <3
 
strong or weak :d? ;//
Nice but weak only two lines of change! hue hue hua hua hua hue hue heu~!

I made this, add the creaturescripts to creaturescripts.xml and only register the onKill to login.lua the other two(onStatChange and onTarget) register it to the creatures that you want to be passive until provoked. it should work!
EDIT: Spotted one bug.
Lua:
function onTarget(cid, target)
return getCreatureStorage(target, 101010) <= 0 and false or getCreatureTarget(target) ~= cid and doRemoveCondition(target, CONDITION_INFIGHT) and false or true
end
 
function onStatChange(cid, attacker, combat, type, value)
	if getCreatureStorage(attacker, 101010) == 1 then
		return true
	end	
	if getCreatureTarget(attacker) == cid then
		if type == STATCHANGE_HEALTHLOSS then
			doCreatureSetStorage(attacker, 101010, 1)
		end
	end
return true
end	
 
function onKill(cid, target)
return getCreatureStorage(cid, 101010) == 1 and doCreatureSetStorage(cid, 101010, 0) and true or true
end
 
Last edited:
Back
Top