Jump to content
  • 0

Script Optimization Request


Fily

Question


  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.01
  • Content Count:  51
  • Reputation:   4
  • Joined:  10/23/16
  • Last Seen:  

Hello,

I created an exchanger for my Fishing System. Basically I want to exchange the fishes for receipts. Here's the script I made. 

-	script	fishvendor	-1,{
mes "[Fish Vendor]";
mes "Hi there, if you went fishing, I can buy your rare catch!";
next;
mes "[Fish Vendor]";
mes "If you caught a Shark, Whale, or Octopus, I can give you 10 Fish Market Receipt for each of them";
next;
mes "Here's the list of the fishes I want to buy";
switch(select("10x Eel:10x Tuna:10x Squid:10x Carp:5x Marlin:5x Starfish:5x Giant Squid:5x Crab:5x Snapper:5x Piranha:5x Salmon:5x Mackerel:5x Crucian Carp:1x Whale:1x Octopus:1x Shark")) {
	case 1: // eel
		next;
		if (countitem(32189)<10) { mes "[Fish Vendor]"; mes "Sorry but you don't have enough Eels with you"; close; }
		delitem 32189,10;
		getitem 32196,1;
		mes "[Fish Vendor]";
		mes "Thanks! Here's your Fish Market Receipt!";
		close;
		
	case 2: //tuna
		next;
		if (countitem(32195)<10) { mes "[Fish Vendor]"; mes "Sorry but you don't have enough Tuna with you"; close; }
		delitem 32195,10;
		getitem 32196,1;
		mes "[Fish Vendor]";
		mes "Thanks! Here's your Fish Market Receipt!";
		close;
		
	case 3: //squid
		next;
		if (countitem(32191)<10) { mes "[Fish Vendor]"; mes "Sorry but you don't have enough Squid with you"; close; }
		delitem 32191,10;
		getitem 32196,1;
		mes "[Fish Vendor]";
		mes "Thanks! Here's your Fish Market Receipt!";
		close;
		
	case 4: //carp
		next;
		if (countitem(32190)<10) { mes "[Fish Vendor]"; mes "Sorry but you don't have enough Carp with you"; close; }
		delitem 32190,10;
		getitem 32196,1;
		mes "[Fish Vendor]";
		mes "Thanks! Here's your Fish Market Receipt!";
		close;
		
	case 5: //marlin
		next;
		if (countitem(32180)<5) { mes "[Fish Vendor]"; mes "Sorry but you don't have enough Marlin with you"; close; }
		delitem 32180,5;
		getitem 32196,1;
		mes "[Fish Vendor]";
		mes "Thanks! Here's your Fish Market Receipt!";
		close;
		
	case 6: //starfish
		next;
		if (countitem(32181)<5) { mes "[Fish Vendor]"; mes "Sorry but you don't have enough Starfish with you"; close; }
		delitem 32181,5;
		getitem 32196,1;
		mes "[Fish Vendor]";
		mes "Thanks! Here's your Fish Market Receipt!";
		close;
		
	case 7: //giant squid
		next;
		if (countitem(32182)<5) { mes "[Fish Vendor]"; mes "Sorry but you don't have enough Giant Squid with you"; close; }
		delitem 32182,5;
		getitem 32196,1;
		mes "[Fish Vendor]";
		mes "Thanks! Here's your Fish Market Receipt!";
		close;
		
	case 8: //crab
		next;
		if (countitem(32183)<5) { mes "[Fish Vendor]"; mes "Sorry but you don't have enough Crab with you"; close; }
		delitem 32183,5;
		getitem 32196,1;
		mes "[Fish Vendor]";
		mes "Thanks! Here's your Fish Market Receipt!";
		close;
		
	case 9: //snapper
		next;
		if (countitem(32186)<5) { mes "[Fish Vendor]"; mes "Sorry but you don't have enough Snapper with you"; close; }
		delitem 32186,5;
		getitem 32196,1;
		mes "[Fish Vendor]";
		mes "Thanks! Here's your Fish Market Receipt!";
		close;
		
	case 10: //piranha
		next;
		if (countitem(32187)<5) { mes "[Fish Vendor]"; mes "Sorry but you don't have enough Piranha with you"; close; }
		delitem 32187,5;
		getitem 32196,1;
		mes "[Fish Vendor]";
		mes "Thanks! Here's your Fish Market Receipt!";
		close;
		
	case 11: //Salmon
		next;
		if (countitem(32188)<5) { mes "[Fish Vendor]"; mes "Sorry but you don't have enough Salmon with you"; close; }
		delitem 32188,5;
		getitem 32196,1;
		mes "[Fish Vendor]";
		mes "Thanks! Here's your Fish Market Receipt!";
		close;
		
	case 12: //Mackerel
		next;
		if (countitem(32192)<5) { mes "[Fish Vendor]"; mes "Sorry but you don't have enough Mackerel with you"; close; }
		delitem 32192,5;
		getitem 32196,1;
		mes "[Fish Vendor]";
		mes "Thanks! Here's your Fish Market Receipt!";
		close;
		
	case 13: //Crucian Carp
		next;
		if (countitem(32193)<5) { mes "[Fish Vendor]"; mes "Sorry but you don't have enough Crucian Carp with you"; close; }
		delitem 32193,5;
		getitem 32196,1;
		mes "[Fish Vendor]";
		mes "Thanks! Here's your Fish Market Receipt!";
		close;
	
	case 14: //Whale
		next;
		if (countitem(32184)<1) { mes "[Fish Vendor]"; mes "Sorry but you don't have enough Whale with you"; close; }
		delitem 32184,1;
		getitem 32196,10;
		mes "[Fish Vendor]";
		mes "Thanks! Here's your Fish Market Receipt!";
		close;
	
	case 15: //Octopus
		next;
		if (countitem(32185)<1) { mes "[Fish Vendor]"; mes "Sorry but you don't have enough Octopus with you"; close; }
		delitem 32185,1;
		getitem 32196,10;
		mes "[Fish Vendor]";
		mes "Thanks! Here's your Fish Market Receipt!";
		close;
	
	case 16: //Shark
		next;
		if (countitem(32194)<1) { mes "[Fish Vendor]"; mes "Sorry but you don't have enough Shark with you"; close; }
		delitem 32194,1;
		getitem 32196,10;
		mes "[Fish Vendor]";
		mes "Thanks! Here's your Fish Market Receipt!";
		close;
}
}


jawaii,219,117,0	duplicate(fishvendor)	Fish Vendor#dup1	49

Item ID 32196 is the receipt. Everything exchanges for 1 receipt except for the last 3 which is Shark, Whale and Octopus which exchanges to 10 receipts. Can anyone optimize it so that everytime I want to add a new fish to exchange, I won't go over editing a lot of lines. maybe an array or something?

 

Thanks guys.

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  663
  • Reputation:   671
  • Joined:  11/12/12
  • Last Seen:  

You can try the following:

-	script	fishvendor	-1,{
	.@n$ = "[Fish Vendor]";
	
	if (checkweight(1201, 1) == 0) {
		mes .@n$, "You have too many items in your inventory!";
		close;
	}
	
	mes .@n$, "Hi there, if you went fishing, I can buy your rare catch!";
	next;
	mes .@n$, "If you caught a Shark, Whale, or Octopus, I can give you 10 Fish Market Receipt for each of them";
	next;
	mes .@n$, "Here's the list of the fishes I want to buy";
	next;
	
	setarray .@items,  32189, 32195, 32191, 32190, 32180, 32181, 32182, 32183, 32186, 32187, 32188, 32192, 32193, 32184, 32185, 32194;
	setarray .@amounts,   10,    10,    10,    10,     5,     5,     5,     5,     5,     5,     5,     5,     5,     1,     1,     1;
	setarray .@rewards,    1,     1,     1,     1,     1,     1,     1,     1,     1,     1,     1,     1,     1,    10,    10,    10;
	
	for (.@i = 0; .@i < getarraysize(.@items); .@i++) {
		// Optional, but I usually make such items with blue links so that players click the right ones more easily
		if (countitem(.@items[.@i]) >= .@amounts[.@i])
			.@menu$ = .@menu$ + "^0000ff" + .@amounts[.@i] + "x " + getitemname(.@items[.@i]) + "^000000:";
		else
			.@menu$ = .@menu$ + .@amounts[.@i] + "x " + getitemname(.@items[.@i]) + ":";
	}
	
	.@opt = select(.@menu$) - 1;
	
	if (.@opt < 0 || .@opt >= getarraysize(.@items))
		end;
	
	.@item = .@items[.@opt];
	.@amount = .@amounts[.@opt];
	
	if (countitem(.@item) < .@amount) {
		mes .@n$, "Sorry but you don't have enough " + getitemname(.@item) + " with you"; 
		close;
	}
	
	delitem .@item, .@amount;
	getitem 32196, .@rewards[.@opt];
	mes .@n$, "Thanks! Here's your Fish Market Receipt!";
	close;
}

You may want to double check the receipts to make sure all the values are right.

  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  18
  • Topics Per Day:  0.01
  • Content Count:  51
  • Reputation:   4
  • Joined:  10/23/16
  • Last Seen:  

Thank you @Tokei It works perfectly as needed :) also  thanks for the blue link thing hehe.

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