Jump to content
  • 0

Can't use @afk if it's from @autoattack


Question

Posted

Hello, I would like that when the player had the @auttoattack command active he could not use the @afk command is that possible?

@autoattack.diff

Index: src/map/atcommand.c
===================================================================
--- src/map/atcommand.c	(revision 504)
+++ src/map/atcommand.c	(working copy)
@@ -5217,7 +5217,78 @@
 	return 0;
 }
 
+// Auto Attack
+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;
+}
+
+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 || pc_isdead(sd) || !sd->state.autoattack )
+		return 0;
+
+	if(sd->state.autoattack)
+	{
+		unit_stop_attack(&sd->bl);
+		autoattack_motion(sd);
+		if(DIFF_TICK(sd->autoattack_delay,gettick())> 0){
+			clif_authfail_fd(sd->fd, 15);
+			return 0;
+		}
+		else{
+			add_timer(gettick()+1000,autoattack_timer,sd->bl.id,0);
+			sd->autoattack_delay = gettick() + 1000;
+		}
+	}
+	return 0;
+}
+
+ACMD_FUNC(autoattack)
+{
+	nullpo_retr(-1, sd);
+	if (sd->state.autoattack)
+	{
+		sd->state.autoattack = 0;
+		unit_stop_attack(&sd->bl);
+		clif_displaymessage(fd, "Auto Attack has been deactivated.");
+	}
+	else
+	{
+		sd->state.autoattack = 1;
+		add_timer(gettick()+1000,autoattack_timer,sd->bl.id,0);
+		clif_displaymessage(fd, "Auto Attack activated.");
+	}
+	return 0;
+}
+
+
 /*==========================================
  * @broadcast by [Valaris]
  *------------------------------------------*/
@@ -10184,6 +10255,7 @@
 		ACMD_DEF(autoloottype),
 		ACMD_DEF(mobinfo),
 		ACMD_DEF(exp),
+		ACMD_DEF(autoattack),
 		ACMD_DEF(version),
 		ACMD_DEF(mutearea),
 		ACMD_DEF(rates),
Index: src/map/pc.c
===================================================================
--- src/map/pc.c	(revision 505)
+++ src/map/pc.c	(working copy)
@@ -701,6 +701,7 @@
 		sd->canlog_tick = gettick();
 	//Required to prevent homunculus copuing a base speed of 0.
 	sd->battle_status.speed = sd->base_status.speed = DEFAULT_WALK_SPEED;
+	sd->state.autoattack = 0; // Keitenai
 }
 
 /**
Index: src/map/pc.h
===================================================================
--- src/map/pc.h	(revision 504)
+++ src/map/pc.h	(working copy)
@@ -245,6 +245,7 @@
 		unsigned int lesseffect : 1;
 		unsigned int vending : 1;
 		unsigned int noks : 3; // [Zeph Kill Steal Protection]
+		unsigned autoattack : 1; // Keitenai
 		unsigned int changemap : 1;
 		unsigned int callshop : 1; // flag to indicate that a script used callshop; on a shop
 		short pmap; // Previous map on Map Change
@@ -347,6 +348,7 @@
 	unsigned int canskill_tick; // used to prevent abuse from no-delay ACT files
 	unsigned int cansendmail_tick; // [Mail System Flood Protection]
 	unsigned int ks_floodprotect_tick; // [Kill Steal Protection]
+	unsigned int autoattack_delay;	// Keitenai
 
 	struct s_item_delay {
 		unsigned short nameid;

 

2 answers to this question

Recommended Posts

  • 0
Posted

Hello,

I don't kow your implant of @afk, but inside the definition ACMD_FUNC(afk) add:

if(sd->state.autoattack){
clif_displaymessage(fd, "You can't use @afk while autoattacking.");
return 0;
}

It should prevent the @afk to work.

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...