Jump to content
  • 0

Why error when compile


GubA

Question


  • Group:  Members
  • Topic Count:  14
  • Topics Per Day:  0.00
  • Content Count:  24
  • Reputation:   0
  • Joined:  06/16/14
  • Last Seen:  

Original Code Is OK

Spoiler

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

Spoiler

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

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...