viewing paste Questions | C

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
// 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?
Viewed 1187 times, submitted by jaBote.