• 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++]Wild monsters are not harmed by attacks from other wild monsters

Joe Rod

Discord: joerod1
Joined
Mar 16, 2011
Messages
499
Solutions
2
Reaction score
172
GitHub
joerod1
hi guys, i need a code for make that wild monsters don't get harmed by attacks of another wild monsters. Basically i need that summons can only cause harm. It would be nice if someone can help me :).

Thanks in Advance
Kind Regards ;)
 
the code to prevent damage is easy, the problem is registering the creatureevent to every monster on the server..

Code:
function onStatsChange(cid, attacker, type, combat, value)
    if type == STATSCHANGE_HEALTHLOSS then
        if isMonster(getCreatureMaster(attacker)) then
            return false
        end
    end
end
this code is enough to prevent any damage from monsters that arent summons from players(damage from summons from monsters are also ignored)

the problem is how to give this creaturescript to every monster on the server, unfortunatelly, I don't know a good way to do this...
 
Should work in 0.3.6pl1, here-

in monster.cpp replace:
Code:
void Monster::drainHealth(Creature* attacker, CombatType_t combatType, int32_t damage)
{
	Creature::drainHealth(attacker, combatType, damage);
	if(isInvisible())
		removeCondition(CONDITION_INVISIBLE);
}

with:
Code:
void Monster::drainHealth(Creature* attacker, CombatType_t combatType, int32_t damage)
{
	bool effect = true
	if(g_config.getBool(ConfigManager::MONSTER_DAMAGED_BY_PLAYER_ONLY))
	{
		if(!isPlayerSummon()) //Player summons can be damaged by players and monsters
		{
			if(attacker->getPlayer() || attacker->isPlayerSummon()) //Make sure it is a player making damage
				effect = true
			else
				effect = false
		}
		else
			effect = true
	}
	else
		effect = true
	
	if(effect)
	{
		Creature::drainHealth(attacker, combatType, damage);
		if(isInvisible())
			removeCondition(CONDITION_INVISIBLE);
	}
	else
		Creature::drainHealth(attacker, combatType, 0);
}

in configmanager.cpp below:
Code:
m_confBool[SHOW_HEALING_DAMAGE_MONSTER] = getGlobalBool("showHealingDamageForMonsters", false);

add:
Code:
m_confBool[MONSTER_DAMAGED_BY_PLAYER_ONLY] = getGlobalBool("monsterDamagedByPlayerOnly", false);

in configmanager.h below:
Code:
SHOW_HEALING_DAMAGE_MONSTER,

add:
Code:
MONSTER_DAMAGED_BY_PLAYER_ONLY,

then in config.lua below:
Code:
showHealingDamageForMonsters = false

add:
Code:
monsterDamagedByPlayerOnly = true

and you're done. I haven't actually tested it yet, so let me know if it has any issues.

Regards,
Mav
 
Last edited:
i'm use too tfs 0.3.6 :( please someone me and joe road are despret after script :)
 
Back
Top