Jump to content
  • 0

Requesting to simplify my custom script (repeating mes)


Dolphin86

Question


  • Group:  Members
  • Topic Count:  266
  • Topics Per Day:  0.06
  • Content Count:  729
  • Reputation:   16
  • Joined:  01/07/12
  • Last Seen:  

Posted (edited)

as mention above, my current script have part which it's keeps repeating the same message, could someone make it more easy and simple template, which later i can use to edit to add more and much more easy to manage?

like edit a configuration settings for rewards, require item for option 1, option 2 or anything came up on your idea..

thanks..

Spoiler
-	script	Green Tree	FAKE_NPC,{

	soundeffect "menu.wav",0;
	mes "What do you want to do ?";
	next;
	switch(select("- Gather Branch:- Gather Log:- Gather Tree Sap:- Cancel")){
	
		case 1:
			next;
			switch(select("- Use Stone Knife:- Cancel")){
				case 1:
					if(rentalcountitem(40005) < 1){
						goto no_stone_knife;
					}
					next;
					soundeffect "menu.wav",0;
					switch(select("- Start Gathering:- Cancel")){
						case 1:
							if(countitem(40008) == 1){
							mes "Gathering in progress";
							mes "Do not move or gathering";
							mes "progress will be cancel.";
							soundeffect "gathering.wav",0;
							addtimer 2,strnpcinfo(0)+"::OnTest";
							progressbar "0x00ff00",2;
							next;
							mes "Gathering Completed";
							soundeffect "menu.wav",0;
							gathering_points += 1;
							dispbottom "Gain +1 Gathering Points";
							getitem 40023,1;
							close3;
							}
								mes "Gathering in progress";
								mes "Do not move or gathering";
								mes "progress will be cancel.";
								soundeffect "gathering.wav",0;
								addtimer 2,strnpcinfo(0)+"::OnTest";
								progressbar "0x00ff00",2;
								next;
								mes "Gathering Completed";
								soundeffect "menu.wav",0;
								getitem 40023,1;
								close3;
						case 2:
							goto cancel;
							}
				case 2:
					goto cancel;
			}
		case 2:
			next;
			switch(select("- Use Makeshift Axe:- Cancel")){
				case 1:
					if(rentalcountitem(40029) < 1){
						goto no_axe;
					}
					next;
					soundeffect "menu.wav",0;
					switch(select("- Start Gathering:- Cancel")){
						case 1:
							if(countitem(40008) == 1){
							mes "Gathering in progress";
							mes "Do not move or gathering";
							mes "progress will be cancel.";
							soundeffect "gathering.wav",0;
							addtimer 2,strnpcinfo(0)+"::OnTest";
							progressbar "0x00ff00",2;
							next;
							mes "Gathering Completed";
							soundeffect "menu.wav",0;
							gathering_points += 1;
							dispbottom "Gain +1 Gathering Points";
							getitem 40027,1;
							close;
							}
								mes "Gathering in progress";
								mes "Do not move or gathering";
								mes "progress will be cancel.";
								soundeffect "gathering.wav",0;
								addtimer 2,strnpcinfo(0)+"::OnTest";
								progressbar "0x00ff00",2;
								next;
								mes "Gathering Completed";
								soundeffect "menu.wav",0;
								getitem 40027,1;
								close;
						case 2:
							goto cancel;
					}
					
				case 2:
					goto cancel;
			}
		case 3:
			next;
			switch(select("- Use Stone Knife:- Cancel")){
				case 1:
					if(rentalcountitem(40005) < 1){
						goto no_stone_knife;
					}
					next;
					soundeffect "menu.wav",0;
					switch(select("- Start Gathering:- Cancel")){
						case 1:
							if(countitem(40008) == 1){
							mes "Gathering in progress";
							mes "Do not move or gathering";
							mes "progress will be cancel.";
							soundeffect "gathering.wav",0;
							addtimer 2,strnpcinfo(0)+"::OnTest";
							progressbar "0x00ff00",2;
							next;
							mes "Gathering Completed";
							soundeffect "menu.wav",0;
							gathering_points += 1;
							dispbottom "Gain +1 Gathering Points";
							getitem 40190,1;
							close3;
							}
								mes "Gathering in progress";
								mes "Do not move or gathering";
								mes "progress will be cancel.";
								soundeffect "gathering.wav",0;
								addtimer 2,strnpcinfo(0)+"::OnTest";
								progressbar "0x00ff00",2;
								next;
								mes "Gathering Completed";
								soundeffect "menu.wav",0;
								getitem 40190,1;
								close3;
						case 2:
							goto cancel;
							}
				case 2:
					goto cancel;
			}
		case 4:
			goto cancel;
	}

no_stone_knife:
	next;
	soundeffect "menu.wav",0;
	mes "^ff0000 Require";
	mes "- 1 Stone Knife ^000000";
	close3;

no_axe:
	next;
	soundeffect "menu.wav",0;
	mes "^ff0000 Require";
	mes "- 1 Axe ^000000";
	close;

cancel:
	soundeffect "menu.wav",0;
	mes "Cancel..";
	close3;

OnTest:
	end;

}
// DUPLICATE
//=================================================================
new_1-3,92,63,6	duplicate(Green Tree)	Green Tree#1000	11000
new_1-3,96,65,6	duplicate(Green Tree)	Green Tree#1001	11000

 

 

Edited by Dolphin86
Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  266
  • Topics Per Day:  0.06
  • Content Count:  729
  • Reputation:   16
  • Joined:  01/07/12
  • Last Seen:  

fixed !

Spoiler
function	script	F_Gather	{
	.@rental_item = getarg(0);
	.@give_item = getarg(1);
	clear;
	if(rentalcountitem(.@rental_item) < 1){
		mes "You don't have a "+ getitemname(.@rental_item) +"."; // You don't have a Stone Knife.
		close;
	}

		if(countitem(40008) == 1){
			mes "Gathering in progress.", "Do not move or gathering", "progress will be cancelled.";
			soundeffect "gathering.wav",0;
			addtimer 2,strnpcinfo(0)+"::OnTest";
			progressbar "0x00ff00",2;
			next;
			mes "Gathering Completed.";
			soundeffect "menu.wav",0;
			gathering_points += 1;
			dispbottom "Gained +1 Gathering Points";
			getitem .@give_item,1;
			close3;
		}
			mes "Gathering in progress.", "Do not move or gathering", "progress will be cancelled.";
			soundeffect "gathering.wav",0;
			addtimer 2,strnpcinfo(0)+"::OnTest";
			progressbar "0x00ff00",2;
			next;
			mes "Gathering Completed.";
			soundeffect "menu.wav",0;
			getitem .@give_item,1;
			close3;
	
}

-	script	Green Tree	FAKE_NPC,{
	soundeffect "menu.wav",0;
	mes "What do you want to do ?";
	switch(select("- Gather Branch:- Gather Log:- Gather Tree Sap:- Cancel")){
		case 1:
			switch(select("- Use Stone Knife:- Cancel")){
				case 1:
				//							Rental item needed,		Second item needed,			Item to give
					callfunc "F_Gather",40005,40023;
				case 2:
					break;
			}
			break;
		case 2:
			switch(select("- Use Makeshift Axe:- Cancel")){
				case 1:
					callfunc "F_Gather",40029,40027;
				case 2:
					break;
			}
			break;
		case 3:
			switch(select("- Use Stone Knife:- Cancel")){
				case 1:
					callfunc "F_Gather",40005,40190;
				case 2:
					break;
			}
		case 4:
			break;
	}

OnTest:
	end;

}

 

 

Link to comment
Share on other sites

  • 0

  • Group:  Forum Manager
  • Topic Count:  282
  • Topics Per Day:  0.06
  • Content Count:  3127
  • Reputation:   1617
  • Joined:  03/26/12
  • Last Seen:  

For scripts that keep repeating the same thing over and over but only have minor changes based on scenario, functions are the way to go.

/* Function to check that the player has the requisite item, then accept multiple args to control the rest of the function.
 * @param {int} rental_item	- The item id to check for.
 * @param {int} second_item	- The item id to check for.
 * @param {int} give_item	- The item id to give the player when the function is finished.
 * @syntax callfunc "F_Gather",40005,40008,40023;
 */
function	script	F_Gather	{
	.@rental_item = getarg(0);
	.@second_item = getarg(1);
	.@give_item = getarg(2);
	clear;
	if(rentalcountitem(.@rental_item) < 1){
		mes "You don't have a "+ getitemname(.@rental_item) +"."; // You don't have a Stone Knife.
		close;
	}

	if(countitem(.@second_item) == 1){
		mes "Gathering in progress.", "Do not move or gathering", "progress will be cancelled.";
		soundeffect "gathering.wav",0;
		addtimer 2,strnpcinfo(0)+"::OnTest";
		progressbar "0x00ff00",2;
		next;
		mes "Gathering Completed.";
		soundeffect "menu.wav",0;
		gathering_points += 1;
		dispbottom "Gained +1 Gathering Points";
		getitem .@give_item,1;
		close3;
	}
}

-	script	Green Tree	FAKE_NPC,{
	soundeffect "menu.wav",0;
	mes "What do you want to do ?";
	switch(select("- Gather Branch:- Gather Log:- Gather Tree Sap:- Cancel")){
		case 1:
			switch(select("- Use Stone Knife:- Cancel")){
				case 1:
				//							Rental item needed,		Second item needed,			Item to give
					callfunc "F_Gather",	40005,					40008,						40023;
				case 2:
					break;
			}
			break;
		case 2:
			switch(select("- Use Makeshift Axe:- Cancel")){
				case 1:
					callfunc "F_Gather",40029,40008,40027;
				case 2:
					break;
			}
			break;
		case 3:
			switch(select("- Use Stone Knife:- Cancel")){
				case 1:
					callfunc "F_Gather",40005,40008,40190;
				case 2:
					break;
			}
		case 4:
			break;
	}

OnTest:
	end;

}

// DUPLICATE
//=================================================================
new_1-3,92,63,6	duplicate(Green Tree)	Green Tree#1000	11000
new_1-3,96,65,6	duplicate(Green Tree)	Green Tree#1001	11000

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  266
  • Topics Per Day:  0.06
  • Content Count:  729
  • Reputation:   16
  • Joined:  01/07/12
  • Last Seen:  

On 5/13/2024 at 4:16 AM, Akkarin said:

For scripts that keep repeating the same thing over and over but only have minor changes based on scenario, functions are the way to go.

/* Function to check that the player has the requisite item, then accept multiple args to control the rest of the function.
 * @param {int} rental_item	- The item id to check for.
 * @param {int} second_item	- The item id to check for.
 * @param {int} give_item	- The item id to give the player when the function is finished.
 * @syntax callfunc "F_Gather",40005,40008,40023;
 */
function	script	F_Gather	{
	.@rental_item = getarg(0);
	.@second_item = getarg(1);
	.@give_item = getarg(2);
	clear;
	if(rentalcountitem(.@rental_item) < 1){
		mes "You don't have a "+ getitemname(.@rental_item) +"."; // You don't have a Stone Knife.
		close;
	}

	if(countitem(.@second_item) == 1){
		mes "Gathering in progress.", "Do not move or gathering", "progress will be cancelled.";
		soundeffect "gathering.wav",0;
		addtimer 2,strnpcinfo(0)+"::OnTest";
		progressbar "0x00ff00",2;
		next;
		mes "Gathering Completed.";
		soundeffect "menu.wav",0;
		gathering_points += 1;
		dispbottom "Gained +1 Gathering Points";
		getitem .@give_item,1;
		close3;
	}
}

-	script	Green Tree	FAKE_NPC,{
	soundeffect "menu.wav",0;
	mes "What do you want to do ?";
	switch(select("- Gather Branch:- Gather Log:- Gather Tree Sap:- Cancel")){
		case 1:
			switch(select("- Use Stone Knife:- Cancel")){
				case 1:
				//							Rental item needed,		Second item needed,			Item to give
					callfunc "F_Gather",	40005,					40008,						40023;
				case 2:
					break;
			}
			break;
		case 2:
			switch(select("- Use Makeshift Axe:- Cancel")){
				case 1:
					callfunc "F_Gather",40029,40008,40027;
				case 2:
					break;
			}
			break;
		case 3:
			switch(select("- Use Stone Knife:- Cancel")){
				case 1:
					callfunc "F_Gather",40005,40008,40190;
				case 2:
					break;
			}
		case 4:
			break;
	}

OnTest:
	end;

}

// DUPLICATE
//=================================================================
new_1-3,92,63,6	duplicate(Green Tree)	Green Tree#1000	11000
new_1-3,96,65,6	duplicate(Green Tree)	Green Tree#1001	11000

 

it's not a second item, only if player have that item 40008, they will get gathering points, but if player dont have 40008 they can still gather the item but will not get gathering points,

Spoiler
if(countitem(40008) == 1){
		mes "Gathering in progress.", "Do not move or gathering", "progress will be cancelled.";
		soundeffect "gathering.wav",0;
		addtimer 2,strnpcinfo(0)+"::OnTest";
		progressbar "0x00ff00",2;
		next;
		mes "Gathering Completed.";
		soundeffect "menu.wav",0;
		gathering_points += 1;
		dispbottom "Gained +1 Gathering Points";
		getitem .@give_item,1;
		close3;
	}
		mes "Gathering in progress.", "Do not move or gathering", "progress will be cancelled.";
		soundeffect "gathering.wav",0;
		addtimer 2,strnpcinfo(0)+"::OnTest";
		progressbar "0x00ff00",2;
		next;
		mes "Gathering Completed.";
		soundeffect "menu.wav",0;
		getitem .@give_item,1;
		close3;

 

 

Link to comment
Share on other sites

  • 0

  • Group:  Forum Manager
  • Topic Count:  282
  • Topics Per Day:  0.06
  • Content Count:  3127
  • Reputation:   1617
  • Joined:  03/26/12
  • Last Seen:  

Your original script checked for two items so that's what I did.

Just put an extra argument to the function and use an if statement to check inside the function.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  266
  • Topics Per Day:  0.06
  • Content Count:  729
  • Reputation:   16
  • Joined:  01/07/12
  • Last Seen:  

2 minutes ago, Akkarin said:

Your original script checked for two items so that's what I did.

Just put an extra argument to the function and use an if statement to check inside the function.

this is correct?

Spoiler
if(countitem(40008) == 1){
		mes "Gathering in progress.", "Do not move or gathering", "progress will be cancelled.";
		soundeffect "gathering.wav",0;
		addtimer 2,strnpcinfo(0)+"::OnTest";
		progressbar "0x00ff00",2;
		next;
		mes "Gathering Completed.";
		soundeffect "menu.wav",0;
		gathering_points += 1;
		dispbottom "Gained +1 Gathering Points";
		getitem .@give_item,1;
		close3;
	}
		mes "Gathering in progress.", "Do not move or gathering", "progress will be cancelled.";
		soundeffect "gathering.wav",0;
		addtimer 2,strnpcinfo(0)+"::OnTest";
		progressbar "0x00ff00",2;
		next;
		mes "Gathering Completed.";
		soundeffect "menu.wav",0;
		getitem .@give_item,1;
		close3;

 

 

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