Here's an example on how you can use it :
Code:
sub EVENT_SPAWN
{
quest::setnexthpevent(80);
}
sub EVENT_HP
{
if ( $hpevent == 80 ) {
quest::say("I have $hpratio % HP!");
quest::setnexthpevent(45);
}
if ( $hpevent == 45 ) {
quest::say("I have $hpratio % HP!");
quest::setnexthpevent(0);
}
}
you have at first to initialize the hp event in an EVENT_SPAWN fonction
setnexthpevent(hp) is a command to fix at which hp ratio of the npc the next HP_EVENT will be triggered, in the example it is 80%
and there is 2 variables : $hpevent and $hpratio
$hpevent identifies the event
you have to use setnexthpevent(0) when there is no other hp event
to implement this you have to change all this :
in mob.h : in the class Mob, just before the protected word : ~line 623 :
Code:
// HP Event
inline int& GetNextHPEvent() { return nexthpevent; }
void SetNextHPEvent( int hpevent );
and in mob.h again : in the class Mob, after the protected word where you want :
Code:
// HP Event
int nexthpevent;
in mob.cpp now :
in the function : --void Mob::CreateHPPacket(APPLAYER* app, bool sendself) --
where you see :
Quote:
else
{
ds->cur_hp=IsNPC()?(sint32)GetHPRatio():cur_hp;
ds->max_hp=100;
}
|
add this in the else : after line "ds->max_hp=100;" for example
Quote:
// HP Event
if ( IsNPC() && ( GetNextHPEvent() > 0 ) ) {
if ( ds->cur_hp < GetNextHPEvent() ) {
parse->Event(EVENT_HP, GetNPCTypeID(), 0, this, 0);
}
}
|
in mob.cpp again :
at the end of the file add this :
Quote:
// HP Event
void Mob::SetNextHPEvent( int hpevent ) {
nexthpevent = hpevent;
if ( nexthpevent < 0 ) {
nexthpevent = 0;
}
}
|
now in parser.cpp :
at the end of the function :
"void Parser::ExCommands(string command, string parms, int argnums, int32 npcid, Mob* other, Mob* mob )"
~ line 1223 : after :
Code:
else if (!strcmp(strlwr(command),"rebind")) {
if(mob->IsClient()){
if (mob) mob->CastToClient()->SetBindPoint( atoi(arglist[0]), atof(arglist[1]), atof(arglist[2]), atof(arglist[3]));
}
}
add this :
Code:
// HP Event
else if (!strcmp(strlwr(command),"setnexthpevent")) {
if (other) other->SetNextHPEvent( atoi(arglist[0]) );
}
that's not finished =)
now in embparser.cpp :
in the function : "void PerlembParser::Event(int event, int32 npcid, const char * data, Mob* npcmob, Mob* mob)"
~ line 215 after the case EVENT_SPAWN for example :
add this :
Code:
// HP_Event
case EVENT_HP: {
if (npcmob) {
ExportVar(packagename.c_str(), "hpevent", itoa(npcmob->GetNextHPEvent()));
ExportVar(packagename.c_str(), "hpratio", itoa(npcmob->GetHPRatio()));
SendCommands(packagename.c_str(), "EVENT_HP", npcid, npcmob, mob);
}
break;
}
in embarser.cpp again :
in function : "void PerlembParser::map_funs(void) const"
between myra and scorpious2k comments for example =)
add this :
Code:
// HP Event
"sub setnexthpevent{push(@cmd_queue,{func=>'setnexthpevent',args=>join(',',@_)});}"
and finally in event_codes.h :
add this at the end :
Say me if it works =)