[TUTORIAL] How to add your own Item-Code!

07/05/2018 15:38 ImTheReal#1
Hey Guys, this tutorial will show you how to add your own Item-Code!


Knowledge: 6/10

Step 1: Visit OpenNos.GameObject/Item/then choose the wished handler.
For example:
- Special Item = Speaker, Bubbles, Fairy-Booster etc.
- Magic Item = Dowsing Rod, Airwaves etc.
- No Function Item = Quest Items, some Materials

Step 2: After u choose the handler, let's start with adding a case!
For this, you write:
Code:
case <INSERT_RANDOM_NUMBER>:
break;
What is meant with INSERT_RANDOM_NUMBER? That means, you can add a number you want to have in there.
I personally start behind 9000
so: case 9000:

Step 3: After writing the code, you have to insert the case as effect to the wished item.
If you want to create your own Random Box, then search for the Item in the Database, and insert the case Number in "Effect" on the item values.
Item: Random Box of divine Fairys
Case Number: 9000
Effect Value: 9000

Step 4: Insert your code!
As i already said, we will add the Random Box of divine Fairy.

HELPER

The code i will show now, is a bit complexer. Its just to show you, how to add a randomizer for Random Boxes.
Code:
// Random Box of Divine Fairys
                case 9000:
//For this Code, you have to add also 9000 as EffectValue to the Database
                    if (EffectValue == 9000)
                    {
                        int rnd = ServerManager.RandomNumber(0, 1);
                        if (rnd < 1)
                        {
                            short[] vnums =
                            {
                            //ID's of the Items, you will get
                                4129, 4130, 4131, 4132
                            };
                            //This Code counts the Items, you inserted
                            byte[] counts = { 1, 1, 1, 1};
                            int item = ServerManager.RandomNumber(0, 4);
                            session.Character.GiftAdd(vnums[item], counts[item]);
                        }
                            //This Code, deltes the Item from the Inventory                      session.Character.Inventory.RemoveItemFromInventory(inv.Id);
                    }
                    break;
Another Example:
Code:
//Item: White Tiger Costume Set
//ID: 5487
                case 9001: //9000 already in use, so just go up
//Adds the Costume and the Hat to the inventory
                    session.Character.GiftAdd(4248, 1);
                    session.Character.GiftAdd(4256, 1);
//Deletes the Item from Inventory
                   session.Character.Inventory.RemoveItemFromInventory(inv.Id);
//You can also add a message, ON_USE
//session.SendPacket("msg 5 Success! You recieved your Items.");
                    break;
DB_HELPER
07/05/2018 16:11 Blowa#2
This solution is the result of what OpenNos became : An unmaintainable project.

Having a Dictionary, with Id/Effect/EffectValue as keys and Lambdas as values (splitted over files) would be much more maintainable than a 4054305340 length switch case.
(Even if the dictionary is slower than switch statement, you would not notice the difference)
07/05/2018 16:30 ImTheReal#3
Quote:
Originally Posted by val77 View Post
This solution is the result of what OpenNos became : An unmaintainable project.

Having a Dictionary, with Id/Effect/EffectValue as keys and Lambdas as values (splitted over files) would be much more maintainable than a 4054305340 length switch case.
(Even if the dictionary is slower than switch statement, you would not notice the difference)
Im just willing to help, and ye prob. that is a better solution, but i like this way and its easy to explain for newbies. But Blowa, i please you to be more kind cuz the way u comment, is like an insult. Im just willing to help, nothing more.
07/06/2018 05:47 Worldie#4
I don't understand, why not use the table RollGeneratedItem ?
07/06/2018 10:02 Blowa#5
Quote:
Originally Posted by Worldie View Post
I don't understand, why not use the table RollGeneratedItem ?
He tried to explain to add a custom handling when an item is used

But his solution will actually result in an unmaintainable code :(
07/10/2018 18:29 [NH]Pyro#6
RollgeneratedItem?? have we forgotten? :rtfm:
07/10/2018 19:13 BladeTiger12#7
Quote:
Originally Posted by [NH]Pyro View Post
RollgeneratedItem?? have we forgotten? :rtfm:
Where is the dislike button... We actually need one.
And I guess he just want some posts.
07/10/2018 19:14 Zanouu#8
RollGeneratedItem is For , ONLY 1 item random But if you have Box " Not random " ( exemple :Box for Suit , Box for wedding etc U cant ** )

** If you do not Added Another Column in RollGenerated
07/10/2018 21:05 ImTheReal#9
Quote:
Originally Posted by [NH]Pyro View Post
RollgeneratedItem?? have we forgotten? :rtfm:
First: What kind of english is that?
Secondly: ????????????????????????????????????
I guess some people don't understand Examples.
Although, have fun adding a Ancelloan Blessing in RollGeneratedItems
07/10/2018 21:27 [NH]Pyro#10
Ancelloan non a box, but divine fairy yes
07/10/2018 23:31 roxas9797#11
This tutorial is awesome
Useless
But awesome