viewing paste Unknown #8073 | C | Private

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 93 94 95 96
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../common/HPMi.h"
#include "../map/script.h"
#include "../map/pc.h"
#include "../map/map.h"
#include "../map/unit.h"
#include "../map/atcommand.h"
#include "../common/nullpo.h"
 
#define OPTION_AUTOATTACK 0x10000000
 
 
 
HPExport struct hplugin_info pinfo = {
    "autoattack",       // Plugin name
    SERVER_TYPE_MAP,    // Which server types this plugin works with?
    "1.0",              // Plugin version
    HPM_VERSION,        // HPM Version (don't change, macro is automatically updated)
};
 
static int buildin_autoattack_sub(struct block_list *bl,va_list ap)
{
    int *target_id=va_arg(ap,int *);
    *target_id = bl->id;
    return 1;
}
 
void autoattack_motion(struct map_session_data* sd)
{
    int i, target_id;
    for(i=0;i<=9;i++)
    {
        target_id=0;
        map->foreachinarea(buildin_autoattack_sub, sd->bl.m, sd->bl.x-i, sd->bl.y-i, sd->bl.x+i, sd->bl.y+i, BL_MOB, &target_id);
        if(target_id)
        {
            unit->attack(&sd->bl,target_id,1);
            break;          
        }
        target_id=0;
    }
    if(!target_id)
    {
        unit->walktoxy(&sd->bl,sd->bl.x+(rand()%2==0?-1:1)*(rand()%10),sd->bl.y+(rand()%2==0?-1:1)*(rand()%10),0);
    }
    return;
}
 
int autoattack_timer(int tid, unsigned int tick, int id, intptr_t data)
{
    struct map_session_data *sd=NULL;
 
    sd=map->id2sd(id);
    if(sd==NULL)
        return 0;
    if(sd->sc.option & OPTION_AUTOATTACK)
    {
        autoattack_motion(sd);
        timer->add(timer->gettick()+2000,autoattack_timer,sd->bl.id,0);
    }
    return 0;
}
 
ACMD(autoattack)
{
    if (!sd) return false;
    if (sd->sc.option & OPTION_AUTOATTACK)
    {
        sd->sc.option &= ~OPTION_AUTOATTACK;
        unit->stop_attack(&sd->bl);
    } else
    {
        sd->sc.option |= OPTION_AUTOATTACK;
        timer->add(timer->gettick()+200,autoattack_timer,sd->bl.id,0);
    }
    clif->changeoption(&sd->bl);
    return true;
}
 
/* Server Startup */
HPExport void plugin_init (void)
{
    clif = GET_SYMBOL("clif");
    script = GET_SYMBOL("script");
    pc = GET_SYMBOL("pc");
    atcommand = GET_SYMBOL("atcommand");
    map = GET_SYMBOL("map");
    unit = GET_SYMBOL("unit");
    timer = GET_SYMBOL("timer");
 
    if( HPMi->addCommand != NULL ) {//link our '@sample' command
        HPMi->addCommand("autoattack",ACMD_A(autoattack));
    }
}
Viewed 651 times, submitted by Guest.