Jump to content
  • 0

Joining 2 variables into 1


ToiletMaster

Question


  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  276
  • Reputation:   7
  • Joined:  08/11/12
  • Last Seen:  

Hi guys,

The script currently works fine, however i'm hoping to get an opinion whether if the script below can be improved or better answer my query which is whether is it possible to join 2 variables into 1 ?

Here's the NPC that i've made so far.

 

	mes "Select Equipment to Craft.";
		for (.@i = 1; .@i < getarraysize(.itemID); .@i++)
			.@menu$ = .@menu$ + "~ "+ getitemname(.itemID[.@i]) + ":";
	switch(select( .@menu$ ) ){
		case 1:
			.@n = 1;
			mes "Item Preview: <ITEM>"+getitemname(.itemID[.@n])+"<INFO>"+.itemID[.@n]+"</INFO></ITEM>";
			mes "====================";
				for(.@i = 0; .@i < getarraysize(.reqItemID1); .@i++){
			mes "^FF0000"+countitem(.reqItemID1[.@i])+"^000000 / "+.reqItemQty1[.@i]+ " ~ "+getitemname(.reqItemID1[.@i]);
				}
			mes "^FF0000"+callfunc("F_InsertComma",Zeny)+" / "+callfunc("F_InsertComma",.Zeny[.@n])+" Zeny";
			next;
			mes "Do you wish to continue?";
			switch(select("Let me think about it: Yes, create item.")){
				case 1:
					mes "Come back anytime";
					close;
					
				case 2:
						if(Zeny <= .Zeny[.@n]){ mes "You have insufficient Zeny!"; close;}	
							for( .@i = 0; .@i < getarraysize(.reqItemID1); .@i++){
							if(countitem(.reqItemID1[.@i]) < .reqItemQty1[.@i]){
								mes "You have insufficient items";
								close;
								}
							}
					for( .@i = 0; .@i < getarraysize(.reqItemID1); .@i++){
						delitem .reqItemID1[.@i],.reqItemQty1[.@i];}				
					Zeny -= .Zeny[.@n];
					getitem .itemID[.@n],1;
					mes "Here you go!";
					close;
				} // mini case end
		
		case 2:
			.@n = 2;
			mes "Item Preview: <ITEM>"+getitemname(.itemID[.@n])+"<INFO>"+.itemID[.@n]+"</INFO></ITEM>";
			mes "====================";
				for(.@i = 0; .@i < getarraysize(.reqItemID2); .@i++){
			mes "^FF0000"+countitem(.reqItemID2[.@i])+"^000000 / "+.reqItemQty2[.@i]+ " ~ "+getitemname(.reqItemID2[.@i]);
				}
			mes "^FF0000"+callfunc("F_InsertComma",Zeny)+" / "+callfunc("F_InsertComma",.Zeny[.@n])+" Zeny";
			next;
			mes "Do you wish to continue?";
			switch(select("Let me think about it: Yes, create item.")){
				case 1:
					mes "Come back anytime";
					close;
					
				case 2:
						if(Zeny <= .Zeny[.@n]){mes "You have insufficient Zeny!";close;}	
							for( .@i = 0; .@i < getarraysize(.reqItemID2); .@i++){
							if(countitem(.reqItemID2[.@i]) < .reqItemQty2[.@i]){
								mes "You have insufficient items";
								close;
								}
							}
					for( .@i = 0; .@i < getarraysize(.reqItemID2); .@i++){
						delitem .reqItemID2[.@i],.reqItemQty2[.@i];}				
					Zeny -= .Zeny[.@n];
					getitem .itemID[.@n],1;
					mes "Here you go!";
					close;
				}
        
OnInit:
	setarray .itemID, 0, 2589, 18600;
	setarray .Zeny,   0, 50000000,20000000;
	//item requirement for each items 
	//Fallen Angel Wing 
	setarray .reqItemID1, 2573, 7441,916,949, 1039, 7063,7511,983,982;
	setarray .reqItemQty1, 1, 300, 300, 300, 300, 100, 50, 20, 20;
	//Cat Ear Beret
	setarray .reqItemID2, 5172, 714, 5057, 919, 7161, 1059, 983;
	setarray .reqItemQty2, 1, 1, 1, 100, 200, 200, 5;

        end;
        
    }

 

currently i copy and paste case 1 and case 2 and only changing the .@n  variable. If i can add the use .reqitemID + .@n together then i'd be able to save much more on this one.

Would appreciate on your feedback, thanks!

 

P.S., the itemID being 0 for the first array is kinda because i wanna align the case with the .@n >_>

Edited by ToiletMaster
Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  12
  • Topics Per Day:  0.00
  • Content Count:  626
  • Reputation:   188
  • Joined:  11/19/11
  • Last Seen:  

47 minutes ago, ToiletMaster said:

Hey Chris!
 

Thanks for taking the time to script that out, i've tested and it works great, however there seems to be a small little issue though, this is kinda the part that i'm stuck lol


			for( .@i = 0; .@i < getarraysize(.reqItemID1); .@i++)
				if(countitem(.reqItemID1[.@i]) < .reqItemQty1[.@i]){
					mes "You have insufficient items";

The requirements doesn't jump directly to the 2nd requirements from here since .reqItemID1 is fixed :(

i was hoping it'd be something like


.reqItemID+.@n[.@i]  

followed by


.reqItemQty+.@n[.@i] 

so that it automatically rotates based on which selection i chose but, after trying out this one it doesn't work :(, generally hoping for a way to join 2 variables into one

 

Oh and before i forget since you've removed the first array, then i guess this part has to start from 0 then :D, otherwise it'd skipped the first item

 


	for (.@i = 0; .@i < getarraysize(.itemID); .@i++)
		.@menu$ = .@menu$ + "~ "+ getitemname(.itemID[.@i]) + ":";
	set .@n,select( .@menu$) - 1;

 

Okay, mistake on my side.

You need to use as  example:

getd(".reqItemQty"+(.@n+1)+"["+.@i+"]")

getd allows you to make an variable dynamical. 

.@n+1 because we reduced that value in the menu but your arrays don't have 0 in the name. But you could use .reqItemQty0 instead of .reqItemQty1.

Regards,

Chris

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  12
  • Topics Per Day:  0.00
  • Content Count:  626
  • Reputation:   188
  • Joined:  11/19/11
  • Last Seen:  

If you want to get index 0 just add -1 after select(.@menu$) so it looks like this

switch(select(.@menu$)-1) 

That way you can use index 0 as well, but you need to use case 0: too.

Best way for this kind of menu would be like this:

set .@n,select(.@menu$) - 1;

Then remove the switch stuff and just use the .@n for the index.

I'm at work right now, so I can't post an full example. When I'm done, I can write it better.

But you could check my scripts a example.

Regards,

Chris

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  276
  • Reputation:   7
  • Joined:  08/11/12
  • Last Seen:  

9 hours ago, llchrisll said:

If you want to get index 0 just add -1 after select(.@menu$) so it looks like this

switch(select(.@menu$)-1) 

That way you can use index 0 as well, but you need to use case 0: too.

Best way for this kind of menu would be like this:

set .@n,select(.@menu$) - 1;

Then remove the switch stuff and just use the .@n for the index.

I'm at work right now, so I can't post an full example. When I'm done, I can write it better.

But you could check my scripts a example.

Regards,

Chris

Hey Chris!

 

Thanks for the insight! I'll try out removing the switch and adjusting the menu.

 

However I'd still like to know whether if its possible to combine them into one though, perhaps I can show what I plan to achieve? Cause each case requires me to copy and paste so I'm hoping to not copy and paste instead. I have a rough concept in mind but I just can't put my head on how to do it. I'll write it up once I'm back home. 

 

Thanks! 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  12
  • Topics Per Day:  0.00
  • Content Count:  626
  • Reputation:   188
  • Joined:  11/19/11
  • Last Seen:  

4 hours ago, ToiletMaster said:

Hey Chris!

 

Thanks for the insight! I'll try out removing the switch and adjusting the menu.

 

However I'd still like to know whether if its possible to combine them into one though, perhaps I can show what I plan to achieve? Cause each case requires me to copy and paste so I'm hoping to not copy and paste instead. I have a rough concept in mind but I just can't put my head on how to do it. I'll write it up once I'm back home. 

 

Thanks! 

mes "Select Equipment to Craft.";
	for (.@i = 1; .@i < getarraysize(.itemID); .@i++)
		.@menu$ = .@menu$ + "~ "+ getitemname(.itemID[.@i]) + ":";
	set .@n,select( .@menu$) - 1;
	next;
	
	// By seting the .@n via the menu already you don't need the switch anymore
	// So I removed the switch itself as well the extra .@n = x; 
	// I also removed in the .itemID array the 0 and added [0] just for my personal preference xD
	
	mes "Item Preview: <ITEM>"+getitemname(.itemID[.@n])+"<INFO>"+.itemID[.@n]+"</INFO></ITEM>";
	mes "====================";
	
	for(.@i = 0; .@i < getarraysize(.reqItemID1); .@i++)
		mes "^FF0000"+countitem(.reqItemID1[.@i])+"^000000 / "+.reqItemQty1[.@i]+ " ~ "+getitemname(.reqItemID1[.@i]);
	
	mes "^FF0000"+callfunc("F_InsertComma",Zeny)+" / "+callfunc("F_InsertComma",.Zeny[.@n])+" Zeny";
		next;
		mes "Do you wish to continue?";
		switch(select("Let me think about it: Yes, create item.")){
			case 1:
			mes "Come back anytime";
			close;

			case 2:
			if(Zeny <= .Zeny[.@n]){ mes "You have insufficient Zeny!"; close;}	
			for( .@i = 0; .@i < getarraysize(.reqItemID1); .@i++)
				if(countitem(.reqItemID1[.@i]) < .reqItemQty1[.@i]){
					mes "You have insufficient items";
					close;
				}
			for( .@i = 0; .@i < getarraysize(.reqItemID1); .@i++){
				delitem .reqItemID1[.@i],.reqItemQty1[.@i];}				
				Zeny -= .Zeny[.@n];
				getitem .itemID[.@n],1;
				mes "Here you go!";
				close;
		} // mini case end
		
OnInit:
	setarray .itemID[0],2589, 18600;
	setarray .Zeny[0],50000000,20000000;
	//item requirement for each items 
	//Fallen Angel Wing 
	setarray .reqItemID1[0], 2573, 7441,916,949, 1039, 7063,7511,983,982;
	setarray .reqItemQty1[0], 1, 300, 300, 300, 300, 100, 50, 20, 20;
	//Cat Ear Beret
	setarray .reqItemID2[0], 5172, 714, 5057, 919, 7161, 1059, 983;
	setarray .reqItemQty2[0], 1, 1, 1, 100, 200, 200, 5;

        end;
        
    }

Here you go, the corrected menu read the // comments what I did xD

Regards,

Chris

Edited by llchrisll
  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  276
  • Reputation:   7
  • Joined:  08/11/12
  • Last Seen:  

7 hours ago, llchrisll said:

mes "Select Equipment to Craft.";
	for (.@i = 1; .@i < getarraysize(.itemID); .@i++)
		.@menu$ = .@menu$ + "~ "+ getitemname(.itemID[.@i]) + ":";
	set .@n,select( .@menu$) - 1;
	next;
	
	// By seting the .@n via the menu already you don't need the switch anymore
	// So I removed the switch itself as well the extra .@n = x; 
	// I also removed in the .itemID array the 0 and added [0] just for my personal preference xD
	
	mes "Item Preview: <ITEM>"+getitemname(.itemID[.@n])+"<INFO>"+.itemID[.@n]+"</INFO></ITEM>";
	mes "====================";
	
	for(.@i = 0; .@i < getarraysize(.reqItemID1); .@i++)
		mes "^FF0000"+countitem(.reqItemID1[.@i])+"^000000 / "+.reqItemQty1[.@i]+ " ~ "+getitemname(.reqItemID1[.@i]);
	
	mes "^FF0000"+callfunc("F_InsertComma",Zeny)+" / "+callfunc("F_InsertComma",.Zeny[.@n])+" Zeny";
		next;
		mes "Do you wish to continue?";
		switch(select("Let me think about it: Yes, create item.")){
			case 1:
			mes "Come back anytime";
			close;

			case 2:
			if(Zeny <= .Zeny[.@n]){ mes "You have insufficient Zeny!"; close;}	
			for( .@i = 0; .@i < getarraysize(.reqItemID1); .@i++)
				if(countitem(.reqItemID1[.@i]) < .reqItemQty1[.@i]){
					mes "You have insufficient items";
					close;
				}
			for( .@i = 0; .@i < getarraysize(.reqItemID1); .@i++){
				delitem .reqItemID1[.@i],.reqItemQty1[.@i];}				
				Zeny -= .Zeny[.@n];
				getitem .itemID[.@n],1;
				mes "Here you go!";
				close;
		} // mini case end
		
OnInit:
	setarray .itemID[0],2589, 18600;
	setarray .Zeny[0],50000000,20000000;
	//item requirement for each items 
	//Fallen Angel Wing 
	setarray .reqItemID1[0], 2573, 7441,916,949, 1039, 7063,7511,983,982;
	setarray .reqItemQty1[0], 1, 300, 300, 300, 300, 100, 50, 20, 20;
	//Cat Ear Beret
	setarray .reqItemID2[0], 5172, 714, 5057, 919, 7161, 1059, 983;
	setarray .reqItemQty2[0], 1, 1, 1, 100, 200, 200, 5;

        end;
        
    }

Here you go, the corrected menu read the // comments what I did xD

Regards,

Chris

Hey Chris!
 

Thanks for taking the time to script that out, i've tested and it works great, however there seems to be a small little issue though, this is kinda the part that i'm stuck lol

			for( .@i = 0; .@i < getarraysize(.reqItemID1); .@i++)
				if(countitem(.reqItemID1[.@i]) < .reqItemQty1[.@i]){
					mes "You have insufficient items";

The requirements doesn't jump directly to the 2nd requirements from here since .reqItemID1 is fixed :(

i was hoping it'd be something like

.reqItemID+.@n[.@i]  

followed by

.reqItemQty+.@n[.@i] 

so that it automatically rotates based on which selection i chose but, after trying out this one it doesn't work :(, generally hoping for a way to join 2 variables into one

 

Oh and before i forget since you've removed the first array, then i guess this part has to start from 0 then :D, otherwise it'd skipped the first item

 

	for (.@i = 0; .@i < getarraysize(.itemID); .@i++)
		.@menu$ = .@menu$ + "~ "+ getitemname(.itemID[.@i]) + ":";
	set .@n,select( .@menu$) - 1;

 

Edited by ToiletMaster
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  12
  • Topics Per Day:  0.00
  • Content Count:  88
  • Reputation:   23
  • Joined:  01/30/12
  • Last Seen:  

I think getd / setd are the commands that you are looking for

setd ".@" + .@var$ + "123$", "Poporing is cool";

mes getd ".@" + .@var$ + "123$";

 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  76
  • Topics Per Day:  0.02
  • Content Count:  276
  • Reputation:   7
  • Joined:  08/11/12
  • Last Seen:  

10 hours ago, Digos said:

I think getd / setd are the commands that you are looking for


setd ".@" + .@var$ + "123$", "Poporing is cool";

mes getd ".@" + .@var$ + "123$";

 

 

9 hours ago, llchrisll said:

Okay, mistake on my side.

You need to use as  example:

getd(".reqItemQty"+(.@n+1)+"["+.@i+"]")

getd allows you to make an variable dynamical. 

.@n+1 because we reduced that value in the menu but your arrays don't have 0 in the name. But you could use .reqItemQty0 instead of .reqItemQty1.

Regards,

Chris

Thanks! I wasn't aware that this was the specific command that I was looking for. I'm not sure how I missed as well ._. but thanks for clearing that up! 

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  12
  • Topics Per Day:  0.00
  • Content Count:  626
  • Reputation:   188
  • Joined:  11/19/11
  • Last Seen:  

You're welcome, if you want you can take a look at my Fame System.

I use it there the most. But nearly in every script of mine it's present.  

But it's just an average example in comparison of the scripts of the real pro scripts out there. ?

Regards,

Chris

  • Upvote 1
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...