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)
{
static int last_attack_tick = -10000; // Initialize to a value below the current tick
int i, target_id, tick = gettick();
if (pc_isdead(sd) || !sd->state.autoattack) return;
if (tick - last_attack_tick >= 10000) { // 10 seconds since last attack
// Use Fly Wing
if (sd->status.inventory[0].nameid == 601) {
clif_useitem(sd, 0);
return;
}
} else {
// Search for target to attack
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);
last_attack_tick = tick;
break;
}
target_id = 0;
}
}
Question
GubA
Original Code Is OK
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;
if( pc_isdead(sd) || !sd->state.autoattack ) return;
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 && !pc_isdead(sd) && sd->state.autoattack){
unit_walktoxy(&sd->bl,sd->bl.x+(rand()%2==0?-1:1)*(rand()%25),sd->bl.y+(rand()%2==0?-1:1)*(rand()%25),0);
}
return;
}
But when edit like this
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)
{
static int last_attack_tick = -10000; // Initialize to a value below the current tick
int i, target_id, tick = gettick();
if (pc_isdead(sd) || !sd->state.autoattack) return;
if (tick - last_attack_tick >= 10000) { // 10 seconds since last attack
// Use Fly Wing
if (sd->status.inventory[0].nameid == 601) {
clif_useitem(sd, 0);
return;
}
} else {
// Search for target to attack
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);
last_attack_tick = tick;
break;
}
target_id = 0;
}
}
if (!target_id && !pc_isdead(sd) && sd->state.autoattack) {
unit_walktoxy(&sd->bl, sd->bl.x + (rand() % 2 == 0 ? -1 : 1) * (rand() % 25),
sd->bl.y + (rand() % 2 == 0 ? -1 : 1) * (rand() % 25), 0);
}
}
Is error.
How to fix this.
Thank you.
Link to comment
Share on other sites
0 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.