Jump to content
  • 0

[Paid] Modified npc exchanger


Question

Posted
prontera,196,141,4	script	POD	831,{
mes "[Trader]"; 
mes "Hello dear! I exchange your ITEM A to ITEM B.";
mes " ";
mes "You currently have ^ff0000"+countitem(itema)+"^000000 ITEM A.";
menu "Exchange ITEM A to "+getitemname(itemb)+"", L_PODS, "Nevermind", L_Cancel;
close;

L_PODS:
next;
	mes "[Trader]";
	mes "How many ITEM B you want to get?";
	mes "^ff0000Note^000000: 1 "+getitemname(itemb)+" = 5 "+getitemname(itemb)+"";
	input .@count;
	if (.@count == 0) close;
	if (countitem(itemb) < .@count*1) goto L_Noitem;
	delitem itema,.@count*5;
	getitem itemb,.@count*1;
	close;
	
L_Noitem:
next;
	mes "[Trader]";
	mes "You dont have enough "+getitemname(itema)+"";
	close;
L_Cancel:
	mes "[Trader]";
	mes "Come back anytime!";
	close;
end;
}

This script is working but I want to have a random rate of ITEM A to be exchanged to ITEM B. Numbers are 1, 2 or 3 maximum. So for example, the script returned 1 as the exchange rate, it would be like this: 1 ITEM A = 1 ITEM B. Then another session if the script returned 3 as the exchange rate, then 3 ITEM A = 1 ITEM B. The npc must show the random rate after the player has got the exchanged item.

 

I can pay to have something like this.

 

EXAMPLE: When the npc is clicked, it will ask how many ITEM A the player wants to exchange. So for example, if the player has 20 pcs ITEM A, and he puts all 20 to exchange and the script gave him 3 as the exchange rate, he will only receive 6 ITEM B and only 18 ITEM A will be decreased in his inventory. Meaning, 2 ITEM A will be left. 

 

Alternatively, if the player puts 20 to exchange and the script gave him 1 as the exchange rate, then he will receive 20 ITEM B all in all with no ITEM A left in his inventory.

12 answers to this question

Recommended Posts

Posted (edited)

Wow fantastic work. O.O Thanks Emistry! However, I noticed one small detail

getitem .@item_id[1],.@rate;

This code above is problematic. I exchanged 20 pcs ITEM A, but accdg to the screenshot below i only exchanged 18 pcs? Also, the rate that turned out is the same amount of ITEM B I got which is not supposed to be that way. Must be AMT OF ITEM A divided by EXCHANGE RATE, right? So for example I exchanged 20 pcs ITEM A, and the rate is 3, I must get 9pcs ITEM B and have 2 pcs ITEM A left in my inventory because the NPC will only get 18pcs ITEM A due to the rate. Pls check this screenshot below

 

2e1ww75.png


I'm very ready to give a tip. I hope you can further help. TY


Ok I have modified it and now it's partially working, calculation is 100% correct with this code:

gonryun,172,132,5	script	Exchanger#rand_exchange	757,{
setarray .@item_id,
	111,	// item give
	222;	// item gain

mes "You currently have ^ff0000"+countitem(111)+"^000000 ITEM A.";
mes " ";
mes "^777777Exchange rate of ITEM A to ITEM B are random to 1-3.^000000";
if( select( "Exchange","Cancel" ) == 1 ){
	next;
	.@current_count = countitem( .@item_id[0] );
	if( .@current_count ){
		mes "How many "+getitemname( .@item_id[0] )+" do you want to exchange?";
		input .@amount,0,.@current_count;
		if( .@amount ){
			.@rate = rand( 1,3 ); 
			.@amount = ( .@amount );
			if( .@amount ){
				delitem .@item_id[0],( .@amount * .@rate );
				getitem .@item_id[1],( .@amount / .@rate );
				mes "[Randomized exchange rate for this session: ^777777"+.@rate+":1^000000]";
				mes "Exchanged "+( .@amount )+"x "+getitemname( .@item_id[0] )+" to "+( .@amount / .@rate )+"x "+getitemname( .@item_id[1] )+" .";

			}
		}
	}
	else{
		mes "You didnt have any "+getitemname( .@item_id[0] )+" to exchange.";
	}
} 
close;
}

But my problem is, I want to retain the left ITEM A in the inventory if the computation didn't equal to @amount. For example, I input 20pcs ITEM A, and the rate turned to be 3. So 20 divided by 3 = 6 pcs ITEM B to be added in the inventory, 6 x 3 = 18 pcs ITEM A to be removed in the inventory, and there will be 2pcs left of ITEM A needed to remain, on the other hand . So I guess the ff code must be edited?

				delitem .@item_id[0],( .@amount * .@rate );
Edited by c2greentea
Posted

isnt that it's what you wanted ??

 

he puts all 20 to exchange and the script gave him 3 as the exchange rate, he will only receive 6 ITEM B and only 18 ITEM A will be decreased in his inventory.

 

in your case...there could be bugged.

example:

  1. i got 100 apple
  2. i exchange 99 apple to the npc ( rate 3 )
  3. the npc delete 297 apple ( 3 x 99 )
  4. but you only have 100 apple...the npc is bugged.
Posted (edited)

What i mean is when you put 20 pcs ITEM A in the npc, and the npc returned 3 as the rate, the player receives 6 pcs ITEM B right? But the npc takes ALL 20 pcs ITEM A instead of just 18 pcs. So 20 pcs item A gets deleted instead of just 18 pcs. Because 6 pcs item B is just equal to 18 pcs ITEM A, given that the player entered 20 pcs and the rate is 3.

 

I hope you got what Im trying to say. T_T

Edited by c2greentea
Posted

Emistry, what if the player enters an EVEN number with 2 and 4 as the only rate, the NPC will still get all ITEM A? For example, the player inputs 7 to be exchanged, and the script returned 2 as the rate, so obviously he'll just get 3 pcs ITEM B right? But the NPC will delete or get all 7 pcs ITEM A instead of just 6 pcs? How to fix it?

Posted

the script delete item based on what number they have entered.

 

 

 

What i mean is when you put 20 pcs ITEM A in the npc, and the npc returned 3 as the rate, the player receives 6 pcs ITEM B right? But the npc takes ALL 20 pcs ITEM 

this is what you requested.

Posted

No Emistry, the "but" word is a contradicting statement. This is what I said:

What i mean is when you put 20 pcs ITEM A in the npc, and the npc returned 3 as the rate, the player receives 6 pcs ITEM B right? But the npc takes ALL 20 pcs ITEM A instead of just 18 pcs. So 20 pcs item A gets deleted instead of just 18 pcs. Because 6 pcs item B is just equal to 18 pcs ITEM A, given that the player entered 20 pcs and the rate is 3.

Can we still script it? Also, when the player enters 3 pcs ITEM A and the script returned 4 as the rate, the player gets nothing and the 3pcs ITEM A is deleted. Can we still do this? :(

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