// I don't know the difference between npc->event and npc->script_event!!!
//This is what caused the confussion. mob.c, inside mob_dead
if( md->npc_event[0] && !md->state.npc_killmonster ) {
if( sd && battle_config.mob_npc_event_type ) {
pc->setparam(sd, SP_KILLERRID, sd->bl.id);
npc->event(sd,md->npc_event,0);
} else if( mvp_sd ) {
pc->setparam(mvp_sd, SP_KILLERRID, sd?sd->bl.id:0);
npc->event(mvp_sd,md->npc_event,0);
} else
npc->event_do(md->npc_event);
} else if( mvp_sd && !md->state.npc_killmonster ) {
pc->setparam(mvp_sd, SP_KILLEDRID, md->class_);
npc->script_event(mvp_sd, NPCE_KILLNPC); // PCKillNPC [Lance]
}
// npc related functions
/*==========================================
* NPC processing event type
*------------------------------------------*/
int npc_event(struct map_session_data* sd, const char* eventname, int ontouch)
{
struct event_data* ev = (struct event_data*)strdb_get(npc->ev_db, eventname);
struct npc_data *nd;
nullpo_ret(sd);
if( ev == NULL || (nd = ev->nd) == NULL ) {
if( !ontouch )
ShowError("npc_event: event not found [%s]\n", eventname);
return ontouch;
}
switch(ontouch) {
case 1:
nd->touching_id = sd->bl.id;
sd->touching_id = nd->bl.id;
break;
case 2:
sd->areanpc_id = nd->bl.id;
break;
}
return npc->event_sub(sd,ev,eventname);
}
// No prev documentation
int npc_script_event(struct map_session_data* sd, enum npce_event type)
{
int i;
if (type == NPCE_MAX)
return 0;
if (!sd) {
ShowError("npc_script_event: NULL sd. Event Type %d\n", type);
return 0;
}
for (i = 0; i<script_event[type].event_count; i++)
npc->event_sub(sd,script_event[type].event[i],script_event[type].event_name[i]);
return i;
}
// No prev documentation
int npc_event_sub(struct map_session_data* sd, struct event_data* ev, const char* eventname)
{
if ( sd->npc_id != 0 )
{
//Enqueue the event trigger.
int i;
ARR_FIND( 0, MAX_EVENTQUEUE, i, sd->eventqueue[i][0] == '\0' );
if( i < MAX_EVENTQUEUE )
{
safestrncpy(sd->eventqueue[i],eventname,EVENT_NAME_LENGTH); //Event enqueued.
return 0;
}
ShowWarning("npc_event: player's event queue is full, can't add event '%s' !\n", eventname);
return 1;
}
if( ev->nd->option&OPTION_INVISIBLE )
{
//Disabled npc, shouldn't trigger event.
npc->event_dequeue(sd);
return 2;
}
script->run(ev->nd->u.scr.script,ev->pos,sd->bl.id,ev->nd->bl.id);
return 0;
}
// Bonus question: How to set values to a scripting array via source?