• 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++ monster attack other

ConAn Edujawa

Member
Joined
Feb 23, 2015
Messages
457
Reaction score
17
hello guys i use 0.4
i need help in monster attack other monster
i don't need monster hit other by area spells but need normal monster hit summon monster and summon monster hut normal player
and i need know how to protect master of summon (player) from summon spells
thx guys
 
You need to make condition in game.cpp function:
LUA:
bool Game::combatChangeHealth(const CombatParams& params, Creature* attacker, Creature* target, int32_t healthChange, bool force)
Under this:
Code:
if(damage > 0)
Something like:
Code:
if (target && target->getMonster() && attacker->getMonster() && target->getMaster() != target) 
                    return false;
 
LUA:
function onStatsChange(cid, attacker, type, combat, value)

    if type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS then

        -- disallow summon from hurting master
        if isPlayer(cid) and getCreatureMaster(attacker) == cid then
            return false
        end
    
        -- disallow summons from same master from hurting each other.
        if isSummon(cid) and isSummon(attacker) and getCreatureMaster(attacker) == getCreatureMaster(cid) then
            return false
        end

    end

    return true
end
 
LUA:
function onStatsChange(cid, attacker, type, combat, value)

    if type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS then

        -- disallow summon from hurting master
        if isPlayer(cid) and getCreatureMaster(attacker) == cid then
            return false
        end
  
        -- disallow summons from same master from hurting each other.
        if isSummon(cid) and isSummon(attacker) and getCreatureMaster(attacker) == getCreatureMaster(cid) then
            return false
        end

    end

    return true
end
no error but not work summon always hurting his master when use spells
 
sorry but when player die get this erro
View attachment 47627
Strange.
But an easy fix.

LUA:
function onStatsChange(cid, attacker, type, combat, value)
   
    if type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS then
   
        -- disallow summon from hurting master
        if isPlayer(cid) and isCreature(attacker) and getCreatureMaster(attacker) == cid then
            return false
        end
   
        -- disallow summons from same master from hurting each other.
        if isSummon(cid) and isSummon(attacker) and getCreatureMaster(attacker) == getCreatureMaster(cid) then
            return false
        end
   
    end
   
    return true
end
 
Back
Top