Jump to content
  • 0

Efficient condition comparison. How to compare properly?


Jannah

Question


  • Group:  Members
  • Topic Count:  4
  • Topics Per Day:  0.01
  • Content Count:  6
  • Reputation:   0
  • Joined:  03/06/22
  • Last Seen:  

I am planning to make an NPC where players can choose to combine 4 different type of items in any order and guess the formula but I don't know how to do it better without putting too many if conditions.

Example: 
Materials available for combination
Apple
Red Herb
Grapes
Bottle

Formula example:  
Apple Juice: Red Herb, Bottle, Apple, Apple (can be in any order)
Grape Juice: Red Herb, Bottle, Grapes, Grapes 

Now what I want is if player chose materials even if it's not in order, the NPC will recognize it if it's the similar with the secret formula. Due to my limited knowledge in scripting the only way I know how to do it is by adding if's condition like:

if ( .@mat1 == 507 && .@mat2 == 713 && .@mat3 == 512 && .@mat4 == 512 ) {

mes "Success, you found a formula!";
mes "Apple Juice Formula";
close;

}
 

if ( .@mat1 == 713 && .@mat2 == 507 && .@mat3 == 512 && .@mat4 == 512 ) {

mes "Success, you found a formula!";
mes "Apple Juice Formula";
close;

}
and so on and so forth...
 

I want to learn how I can do it efficiently where regardless of order the NPC can recognize that the player found the correct formula without repeating that "if condition" too much because I am planning to add at least 50 hidden formula. Hope someone can give me an example or idea on how to do it efficiently. Thank you! 
 

Edited by Jannah
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  25
  • Topics Per Day:  0.01
  • Content Count:  928
  • Reputation:   170
  • Joined:  04/05/13
  • Last Seen:  

Correct formula for Apple Juice

1.)

setarray .formula_applie_juice[0],713,507,512,512;

 

2.) Use OnSellItem: (4 times or 1 time in sell order) (Store it as Character variables)

 

3.) Compare variable 1 2 3 4 to array[0] [1] [2] [3]

 

I think that's it.

 

---

I had done 50,000 Items that can be craft with 5 material (Different amount each recipes) before.

You can find it here but it's Thai language https://github.com/kaninhot004/rathena/blob/7ce92c2097110b251bd8872740fd8dc731c6d1ab/npc/team_craft/craft.txt

Commit: https://github.com/kaninhot004/rathena/commit/98f137b681235f423d7d277e624b851468da4227

Edited by Start_
  • MVP 1
Link to comment
Share on other sites

  • 0

  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10015
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

perhaps consider to use db/re/produce_db.txt ?

 

there are also other tricks like .... 

1. sum all ingredient's item id, use that as an identifier to search which items to craft. (as long as the number you sum up doesn't repeat, everything should be fine)

2. or sort the numbers, then store into a variables and use it to compare the item list. (you probably need to write a sorting method)

etc

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