viewing paste npcskill | 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
/* Cast a skill on the attached player.
 * npcskill <skill id>, <skill lvl>, <stat point>, <NPC level>;
 * npcskill "<skill name>", <skill lvl>, <stat point>, <NPC level>; */
BUILDIN_FUNC(npcskill)
{
    uint16 skill_id;
    unsigned short skill_level;
    unsigned int stat_point;
    unsigned int npc_level;
    struct npc_data *nd;
    struct map_session_data *sd;
 
    skill_id    = script_isstring(st, 2) ? skill_name2id(script_getstr(st, 2)) : script_getnum(st, 2);
    skill_level = script_getnum(st, 3);
    stat_point  = script_getnum(st, 4);
    npc_level   = script_getnum(st, 5);
    sd          = script_rid2sd(st);
    nd          = (struct npc_data *)map_id2bl(sd->npc_id);
 
    if (stat_point > battle_config.max_third_parameter) {
        ShowError("npcskill: stat point exceeded maximum of %d.\n",battle_config.max_third_parameter );
        return 1;
    }
    if (npc_level > MAX_LEVEL) {
        ShowError("npcskill: level exceeded maximum of %d.\n", MAX_LEVEL);
        return 1;
    }
    if (sd == NULL || nd == NULL) { //ain't possible, but I don't trust people.
        return 1;
    }
 
    nd->level = npc_level;
    nd->stat_point = stat_point;
 
    if (!nd->status.hp) {
        status_calc_npc(nd, true);
    } else {
        status_calc_npc(nd, false);
    }
 
    if (skill_get_inf(skill_id)&INF_GROUND_SKILL) {
        unit_skilluse_pos(&nd->bl, sd->bl.x, sd->bl.y, skill_id, skill_level);
    } else {
        unit_skilluse_id(&nd->bl, sd->bl.id, skill_id, skill_level);
    }
 
    return 0;
}
 
BUILDIN_DEF(npcskill,"viii"),
Viewed 1300 times, submitted by Streusel.