Jump to content
  • 0
kamirie

Custom Enchant NPC : script line for success percentage

Question

Good Day,

 I want to create my custom script for an enchanting npc like this .

I'm currently studying this script with malangdo enchant script for guidance. I'm a newbie in scripting and this will only be my 2nd npc script to date. I have the following questions .

How do I specify success rate based on enchant results like this :

Success%     Enchant Result

       1%      -    4900 // MHP+5%

       10%    -    4686 // MHP+4%

       30%    -    4867 // MHP+3%

       75%    -    6743 // HP+1%

 

Thanks in Advance

Edited by kamirie
Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

I tried to study the Armor Enchant Script and Correct me if I'm wrong but as to my understanding of this ,

switch (rand(1,[email protected])) {
			case 1: set [email protected],4702;break;
			case 2: set [email protected],4712;break;
			case 3: set [email protected],4722;break;
			case 4: set [email protected],4732;break;
			case 5: set [email protected],4742;break;
			case 6: set [email protected],4752;break;
			case 7:
			case 8: set [email protected],4701;break;
			case 9:
			case 10: set [email protected],4711;break;
			case 11:
			case 12: set [email protected],4721;break;
			case 13:
			case 14: set [email protected],4731;break;
			case 15:
			case 16: set [email protected],4741;break;
			case 17:
			case 18: set [email protected],4751;break;
			case 19:
			case 20:
			case 21: set [email protected],4700;break;
			case 22:
			case 23:
			case 24: set [email protected],4710;break;
			case 25:
			case 26:
			case 27: set [email protected],4720;break;
			case 28:
			case 29:
			case 30: set [email protected],4730;break;
			case 31:
			case 32:
			case 33: set [email protected],4740;break;
			case 34:
			case 35:
			case 36: set [email protected],4750;break;
			default:
				specialeffect2 EF_PHARMACY_FAIL;
				mes "[Apprentice Craftsman]";
				mes "Well that's too bad.";
				mes "The requested equipment has failed to enchant.";
				close;
		}
getitem2 [email protected], 1, 1, 0, 0, 0, 0, 0, [email protected];

This is the line that adds the specific stat to the chosen armor. So If I chose a High Grade armor, I will have a @failrate of 60 as set to this line


S_EnchantArmor:
	set [email protected],getarg(0);
set [email protected],getarg(1);

which is 60 based on this

case 3:
			setarray [email protected][0],2364,2365,2391,2374,2375,2376,2377,2378,2379,2380,2381,2382,2387,2388,2389,2390;
set [email protected],60;

So I will get an enchant based on what case # I get from rand(1,60)

If I get a case # without set , My enchantment failed? AND if get any rand()  37-59 It will also fail because there's no case# 37-59?

 Is this random result basis rather than percentage basis of some sort?

 

Edited by kamirie
Link to comment
Share on other sites

  • 0

Well, kinda... that makes it almost 50% chance...

 

36/60... where as ALL 60 #'s would be 100%

so 36/60 would be 60/100 = 36/X   .... so cross multiply / divide ==.... 100  * 36 / 60 = 60% chance refine rate... it would have been the same as doing... 1 outta 5... and only accept 1,2,3 and not accepting 4,5 ...

The issue, is that you have to break it down to the common denominator... since you want a 1% chance you will most likely need to do it out of a full 100....

set [email protected], rand(1,100);

if ([email protected] == 1) { // The 1% chance is successful! }
elseif ([email protected] <= 10) { // 10% chance }
elseif ([email protected] <= 30) { // 30% chance }
elseif ([email protected] <= 75) { // 75% chance }
else {
  mes "Failed"; close;
}

Link to comment
Share on other sites

  • 0

Thanks @ZER0 so using this , I just have to goto to the specific addparts

 set [email protected], rand(1,100);

if ([email protected] == 1) { goto E_mhp5 // The 1% chance is successful! }
elseif ([email protected] <= 10) { goto E_mhp4 // 10% chance }
elseif ([email protected] <= 30) { goto E_mhp3  // 30% chance }
elseif ([email protected] <= 75) { goto E_mhp1  // 75% chance }
else {
  mes "Failed"; close;
} 

 

Link to comment
Share on other sites

  • 0

I think I understand now malangdo. So it doesn't give higher chances of enchant depending on coins, just additional or improved versions of the enchantments.

case 1: //Anger_Seagod - Short Range
			set [email protected], rand(1,555);
			     if ([email protected] < 81)  set [email protected],4732; //Agility3 (I will get agi+3 if [email protected] is 2-80)
			else if ([email protected] < 161) set [email protected],4820; //Fighting_Spirit5 (I will get FS5 if [email protected] is 81-160)
			else if ([email protected] < 241) set [email protected],4843; //Sharp4 (I will get sharp4 if [email protected] is 161-240)
			else if ([email protected] < 311) set [email protected],4733; //Agility4 (I will get agi+4 if [email protected] is 240-310)
			else if ([email protected] < 371) set [email protected],4821; //Fighting_Spirit6 (I will get FS6 if [email protected] is 311-370)
			else if ([email protected] < 431) set [email protected],4844; //Sharp5 (I will get sharp5 if [email protected] is 371-430)
			else if ([email protected] < 476) set [email protected],4734; //Agility5 (I will get agi+5 if [email protected] is 431-475)
			else if ([email protected] < 516) set [email protected],4822; //Fighting_Spirit7 (I will get FS7 if [email protected] is 476-515)
			else if ([email protected] < 526) set [email protected],4807; //Atk_Speed1 (I will get aspd+1 if [email protected] is 515-525)
			else if ([email protected] < 546) set [email protected],4735; //Agility6 (I will get agi+ if [email protected] is 525-545)
			else if ([email protected] < 551) set [email protected],4823; //Fighting_Spirit8 (I will get FS8 if [email protected] is 546-550)
			else if ([email protected] < 556) set [email protected],4807; //Atk_Speed1 (I will get aspd+1 if [email protected] is 550-555)
			else set [email protected],9; 
break;

I

Edited by kamirie
Link to comment
Share on other sites

  • 0

Correct it will continue down to the next else if if the first if fails... so it just tiers downwards...

 

so if it never falls between X number then it doesn't work... the difference, is the more "chance" you want to give, the higher the initial value needs to be...

especially when dealing with multiple cases... for instance in that case he went from 1 to 555... he could have gone from 1 to 100, but that would lower the chances between the items since you only have 100 total options, and have to split them among X number of items... so by increasing the base number from 100 to 555, he increased the chance range between goods so that they have a higher chance of hitting...

 

Link to comment
Share on other sites

  • 0
10 hours ago, Z3R0 said:

Correct it will continue down to the next else if if the first if fails... so it just tiers downwards...

 

so if it never falls between X number then it doesn't work... the difference, is the more "chance" you want to give, the higher the initial value needs to be...

especially when dealing with multiple cases... for instance in that case he went from 1 to 555... he could have gone from 1 to 100, but that would lower the chances between the items since you only have 100 total options, and have to split them among X number of items... so by increasing the base number from 100 to 555, he increased the chance range between goods so that they have a higher chance of hitting...

 

Thanks Z3R0 , I was able to make my script function as intended with your help .

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

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.