I've been doing this for a while now. I can't finish it since i'm not actually good at src mod. Actually I posted something here before.
Now I came up with these codes but it isn't working well. I got the idea from here.
In this topic, OnNPCAttackedEvent = when a monster received a damage.
Questions:
1) will this code use too much memory since it will trigger each time a mob is hit?
2) if I use a script like this, will it still consume the same amount of memory?
OnNPCAttackedEvent:
if( @attackedrid != 1002 ) end;
3) As i've stated in this post, is it possible to only trigger OnNPCAttackedEvent to the mobs who are spawned with specific or "OnThisMob" event label?
mob.c
//Call when a mob has received damage.
void mob_damage(struct mob_data *md, struct block_list *src, int damage)
{
+ // OnNPCAttackedEvent
+ struct map_session_data *sd = NULL, *tmpsd[DAMAGELOG_SIZE];
+ memset(tmpsd,0,sizeof(tmpsd));
+ if ( src && src->type == BL_PC )
+ {
+ sd = (struct map_session_data *)src;
+ }
if (src && damage > 0) { //Store total damage...
if (UINT_MAX - (unsigned int)damage > md->tdmg)
md->tdmg += damage;
else if (md->tdmg == UINT_MAX)
damage = 0; //Stop recording damage once the cap has been reached.
else { //Cap damage log...
damage = (int)(UINT_MAX - md->tdmg);
md->tdmg = UINT_MAX;
}
if ((src != &md->bl) && md->state.aggressive) //No longer aggressive, change to retaliate AI.
md->state.aggressive = 0;
//Log damage
mob_log_damage(md, src, damage);
md->dmgtick = gettick();
+ // OnNPCAttackedEvent
+ if(sd) { // if I didn't use if(sd) the map-server crash when a pet attacks a monster
+ pc_setreg(sd, add_str("@attackerrid"), sd->bl.id);
+ pc_setreg(sd, add_str("@attackedrid"), md->mob_id);
+ npc_event_doall_id("OnNPCAttackedEvent", sd->bl.id);
+ }
}
if (battle_config.show_mob_info&3)
clif_charnameack(0, &md->bl);
#if PACKETVER >= 20120404
if( battle_config.monster_hp_bars_info){
int i;
for(i = 0; i < DAMAGELOG_SIZE; i++){ // must show hp bar to all char who already hit the mob.
struct map_session_data *sd = map_charid2sd(md->dmglog[i].id);
if( sd && check_distance_bl(&md->bl, &sd->bl, AREA_SIZE) ) // check if in range
clif_monster_hp_bar(md, sd->fd);
}
}
#endif
if (!src)
return;
if( md->special_state.ai == AI_SPHERE ) {//LOne WOlf explained that ANYONE can trigger the marine countdown skill. [Skotlex]
md->state.alchemist = 1;
mobskill_use(md, gettick(), MSC_ALCHEMIST);
}
}
Thanks in advance for those who can help!