Jump to content
  • 0

Make Function (random auto move)


LearningRO

Question


  • Group:  Members
  • Topic Count:  107
  • Topics Per Day:  0.02
  • Content Count:  770
  • Reputation:   69
  • Joined:  02/10/12
  • Last Seen:  

hi, all how to make new function when call the function character auto random walk ?
and this function will be used on usable item?
 

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  303
  • Reputation:   117
  • Joined:  12/10/16
  • Last Seen:  

function	script	random_walk	{

	if(@walking) {
		@walking = false;
	} else {
		@walking = true;
		while(@walking) {
			getmapxy .@m$,.@x,.@y,UNITTYPE_PC;
			getfreecell .@m$,.@to_x,.@to_y,.@x,.@y,10,10,3;
			unitwalk getcharid(3),.@to_x,.@to_y;
			while(.@x != .@to_x || .@y != .@to_y)
				sleep2 500;
		}
	}
	return;

}

Not tested.

Usage: callfunc "random_walk";

If you want to end the function just call it again.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  107
  • Topics Per Day:  0.02
  • Content Count:  770
  • Reputation:   69
  • Joined:  02/10/12
  • Last Seen:  

On 12/12/2018 at 8:44 AM, n0tttt said:

function	script	random_walk	{

	if(@walking) {
		@walking = false;
	} else {
		@walking = true;
		while(@walking) {
			getmapxy .@m$,.@x,.@y,UNITTYPE_PC;
			getfreecell .@m$,.@to_x,.@to_y,.@x,.@y,10,10,3;
			unitwalk getcharid(3),.@to_x,.@to_y;
			while(.@x != .@to_x || .@y != .@to_y)
				sleep2 500;
		}
	}
	return;

}

Not tested.

Usage: callfunc "random_walk";

If you want to end the function just call it again.

Quote

[Debug]: map_search_freecell: Incorrect usage! When src is NULL, flag has to be &1 and can't have &2
[Debug]: map_search_freecell: Incorrect usage! When src is NULL, flag has to be &1 and can't have &2
[Debug]: map_search_freecell: Incorrect usage! When src is NULL, flag has to be &1 and can't have &2
[Debug]: map_search_freecell: Incorrect usage! When src is NULL, flag has to be &1 and can't have &2
[Debug]: map_search_freecell: Incorrect usage! When src is NULL, flag has to be &1 and can't have &2
[Debug]: map_search_freecell: Incorrect usage! When src is NULL, flag has to be &1 and can't have &2
[Debug]: map_search_freecell: Incorrect usage! When src is NULL, flag has to be &1 and can't have &2
[Debug]: map_search_freecell: Incorrect usage! When src is NULL, flag has to be &1 and can't have &2
[Debug]: map_search_freecell: Incorrect usage! When src is NULL, flag has to be &1 and can't have &2
[Debug]: map_search_freecell: Incorrect usage! When src is NULL, flag has to be &1 and can't have &2
[Debug]: map_search_freecell: Incorrect usage! When src is NULL, flag has to be &1 and can't have &2
[Debug]: map_search_freecell: Incorrect usage! When src is NULL, flag has to be &1 and can't have &2
[Debug]: map_search_freecell: Incorrect usage! When src is NULL, flag has to be &1 and can't have &2
[Error]: script:run_script_main: infinity loop !
[Debug]: Source (NPC): FAKE_NPC (invisible/not on a map)

i got error like that

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  107
  • Topics Per Day:  0.02
  • Content Count:  770
  • Reputation:   69
  • Joined:  02/10/12
  • Last Seen:  

btw i found this is similiar what i want
 

function	script	F_botex	{
	set .@i,0;
	while (.@i < 1) {
		set .@b,0;
		dispbottom .@i+"";
		.@rid = getcharid(3);
		getmapxy(.@m$,.@x0,.@y0,0);
		sleep2 100;
		.@x = rand(-13,13)+.@x0;
		.@y = rand(-13,13)+.@y0;
		sleep2 100;
		if(!checkcell( .@m$,.@x,.@y,cell_chkpass )){
			dispbottom "Coordinate not exists!";
			continue;
		} else if(checkcell( .@m$,.@x,.@y,cell_chkpass )){
			dispbottom "Coordinate exists!";
		}
		sleep2 100;
		while(.@x0 != .@x && .@y0 != .@y) {
			set .@b,.@b+1;
			viewpoint 1,.@x,.@y,1,0xFF0000;
			dispbottom "auto walking to x = "+.@x+" y = "+.@y;
			unitwalk getcharid(3),.@x,.@y,strnpcinfo(3)+"::OnReach";
			sleep2 2000;
			if(.@b > 5) break;
			getmapxy(.@m$,.@x0,.@y0,0);
			sleep2 100;
		}
		unitskilluseid .@rid,"WL_JACKFROST",5,.@rid,-4;
		percentheal 100,100;
		sleep2 100;
		dispbottom "JackJack";
	}
	end;
}

btw is possible change function "unitskilluseid" to "unitattack" ? the purpose like auto attack but via script ?

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  303
  • Reputation:   117
  • Joined:  12/10/16
  • Last Seen:  

function	script	random_walk	{

	@walking = !@walking;
	if(@walking) {
		while(@walking) {
			getmapxy .@m$,.@x,.@y,UNITTYPE_PC;
			getfreecell .@m$,.@to_x,.@to_y,.@x,.@y,10,10;
			unitwalk getcharid(3),.@to_x,.@to_y;
			while(.@x != .@to_x || .@y != .@to_y) {
				sleep2 500;
				getmapxy .@m$,.@x,.@y,UNITTYPE_PC;
			}
		}
	}
	return;

}
function	script	F_botex	{
	set .@i,0;
	while (.@i < 1) {
		set .@b,0;
		dispbottom .@i+"";
		.@rid = getcharid(3);
		getmapxy(.@m$,.@x0,.@y0,0);
		sleep2 100;
		.@x = rand(-13,13)+.@x0;
		.@y = rand(-13,13)+.@y0;
		sleep2 100;
		if(!checkcell( .@m$,.@x,.@y,cell_chkpass )){
			dispbottom "Coordinate not exists!";
			continue;
		} else if(checkcell( .@m$,.@x,.@y,cell_chkpass )){
			dispbottom "Coordinate exists!";
		}
		sleep2 100;
		while(.@x0 != .@x && .@y0 != .@y) {
			set .@b,.@b+1;
			viewpoint 1,.@x,.@y,1,0xFF0000;
			dispbottom "auto walking to x = "+.@x+" y = "+.@y;
			unitwalk getcharid(3),.@x,.@y,strnpcinfo(3)+"::OnReach";
			sleep2 2000;
			if(.@b > 5) break;
			getmapxy(.@m$,.@x0,.@y0,0);
			sleep2 100;
		}
		.@n = getareaunits(BL_MOB,.@m$,.@x0 + 5,.@y0 + 5,.@x0 - 5,.@y0 - 5,.@mob);
		unitattack 0,.@mob[rand(.@n)],true;
		percentheal 100,100;
		sleep2 100;
		dispbottom "JackJack";
	}
	end;
}

 

  • Love 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  107
  • Topics Per Day:  0.02
  • Content Count:  770
  • Reputation:   69
  • Joined:  02/10/12
  • Last Seen:  

On 12/21/2018 at 12:11 AM, n0tttt said:

function	script	random_walk	{

	@walking = !@walking;
	if(@walking) {
		while(@walking) {
			getmapxy .@m$,.@x,.@y,UNITTYPE_PC;
			getfreecell .@m$,.@to_x,.@to_y,.@x,.@y,10,10;
			unitwalk getcharid(3),.@to_x,.@to_y;
			while(.@x != .@to_x || .@y != .@to_y) {
				sleep2 500;
				getmapxy .@m$,.@x,.@y,UNITTYPE_PC;
			}
		}
	}
	return;

}

function	script	F_botex	{
	set .@i,0;
	while (.@i < 1) {
		set .@b,0;
		dispbottom .@i+"";
		.@rid = getcharid(3);
		getmapxy(.@m$,.@x0,.@y0,0);
		sleep2 100;
		.@x = rand(-13,13)+.@x0;
		.@y = rand(-13,13)+.@y0;
		sleep2 100;
		if(!checkcell( .@m$,.@x,.@y,cell_chkpass )){
			dispbottom "Coordinate not exists!";
			continue;
		} else if(checkcell( .@m$,.@x,.@y,cell_chkpass )){
			dispbottom "Coordinate exists!";
		}
		sleep2 100;
		while(.@x0 != .@x && .@y0 != .@y) {
			set .@b,.@b+1;
			viewpoint 1,.@x,.@y,1,0xFF0000;
			dispbottom "auto walking to x = "+.@x+" y = "+.@y;
			unitwalk getcharid(3),.@x,.@y,strnpcinfo(3)+"::OnReach";
			sleep2 2000;
			if(.@b > 5) break;
			getmapxy(.@m$,.@x0,.@y0,0);
			sleep2 100;
		}
		.@n = getareaunits(BL_MOB,.@m$,.@x0 + 5,.@y0 + 5,.@x0 - 5,.@y0 - 5,.@mob);
		unitattack 0,.@mob[rand(.@n)],true;
		percentheal 100,100;
		sleep2 100;
		dispbottom "JackJack";
	}
	end;
}

 

thx @n0tttt for random walk its work

but for auto attack not workin character didn;t hit any monster just random walk 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.00
  • Content Count:  303
  • Reputation:   117
  • Joined:  12/10/16
  • Last Seen:  

Maybe now? I read something about rids in unitattack.

function	script	F_botex	{
	set .@i,0;
	set .@rid,getcharid(3);
	while (.@i < 1) {
		set .@b,0;
		dispbottom .@i+"";
		.@rid = getcharid(3);
		getmapxy(.@m$,.@x0,.@y0,0);
		sleep2 100;
		.@x = rand(-13,13)+.@x0;
		.@y = rand(-13,13)+.@y0;
		sleep2 100;
		if(!checkcell( .@m$,.@x,.@y,cell_chkpass )){
			dispbottom "Coordinate not exists!";
			continue;
		} else if(checkcell( .@m$,.@x,.@y,cell_chkpass )){
			dispbottom "Coordinate exists!";
		}
		sleep2 100;
		while(.@x0 != .@x && .@y0 != .@y) {
			set .@b,.@b+1;
			viewpoint 1,.@x,.@y,1,0xFF0000;
			dispbottom "auto walking to x = "+.@x+" y = "+.@y;
			unitwalk getcharid(3),.@x,.@y,strnpcinfo(3)+"::OnReach";
			sleep2 2000;
			if(.@b > 5) break;
			getmapxy(.@m$,.@x0,.@y0,0);
			sleep2 100;
		}
		.@n = getareaunits(BL_MOB,.@m$,.@x0 + 5,.@y0 + 5,.@x0 - 5,.@y0 - 5,.@mob);
		detachrid;
		unitattack .@rid,.@mob[rand(.@n)],true;
		attachrid .@rid;
		percentheal 100,100;
		sleep2 100;
		dispbottom "JackJack";
	}
	end;
}

 

  • Love 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  107
  • Topics Per Day:  0.02
  • Content Count:  770
  • Reputation:   69
  • Joined:  02/10/12
  • Last Seen:  

On 12/23/2018 at 5:16 AM, n0tttt said:

Maybe now? I read something about rids in unitattack.


function	script	F_botex	{
	set .@i,0;
	set .@rid,getcharid(3);
	while (.@i < 1) {
		set .@b,0;
		dispbottom .@i+"";
		.@rid = getcharid(3);
		getmapxy(.@m$,.@x0,.@y0,0);
		sleep2 100;
		.@x = rand(-13,13)+.@x0;
		.@y = rand(-13,13)+.@y0;
		sleep2 100;
		if(!checkcell( .@m$,.@x,.@y,cell_chkpass )){
			dispbottom "Coordinate not exists!";
			continue;
		} else if(checkcell( .@m$,.@x,.@y,cell_chkpass )){
			dispbottom "Coordinate exists!";
		}
		sleep2 100;
		while(.@x0 != .@x && .@y0 != .@y) {
			set .@b,.@b+1;
			viewpoint 1,.@x,.@y,1,0xFF0000;
			dispbottom "auto walking to x = "+.@x+" y = "+.@y;
			unitwalk getcharid(3),.@x,.@y,strnpcinfo(3)+"::OnReach";
			sleep2 2000;
			if(.@b > 5) break;
			getmapxy(.@m$,.@x0,.@y0,0);
			sleep2 100;
		}
		.@n = getareaunits(BL_MOB,.@m$,.@x0 + 5,.@y0 + 5,.@x0 - 5,.@y0 - 5,.@mob);
		detachrid;
		unitattack .@rid,.@mob[rand(.@n)],true;
		attachrid .@rid;
		percentheal 100,100;
		sleep2 100;
		dispbottom "JackJack";
	}
	end;
}

 

still didn't attack any monster near the character 

Link to comment
Share on other sites

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...