[C++/SOURCE]6/7 Bonus direkt im Item

12/08/2015 21:02 Creek'#1
Hallo,
Ich habe auf manchen Servern gesehen, dass gedropte Items mit einer geringen Wahrscheinlichkeit schon einen 6/7 Bonus drauf hatten.
Aus diesem Grund hab ich mich mal hingesetzt und das in C++ für euch geschrieben^^

Ihr öffnet item_manager.cpp und such nach:
Code:
LPITEM ITEM_MANAGER::CreateItem(DWORD vnum, DWORD count, DWORD id, bool bTryMagic, int iRarePct, bool bSkipSave)
Fügt darüber folgendes:
Code:
bool inArr(int* tab, int line) {
        for(int i = 0; i < sizeof(tab); i++){
                if(tab[i] == line)
                        return true;           
        }
        return false;
}
Nun sucht ihr in der Datei noch nach:
Code:
                        if (number(1, 100) <= iRarePct)
                                item->AlterToMagicItem();
Und fügt darunter folgendes ein:
Code:
                        int RareArray[2] = {1,2}; //Hier alle Typ angeben welche 6/7 Boni droppen sollen.
                        if(inArr(RareArray,item->GetType())){
                                if (number(1, 100) <= 20){ //20% Chance
                                        item->AddRareAttribute();
                                        if (number(1, 100) <= 10) // 10% Chance
                                                item->AddRareAttribute();
                                }                              
                        }
Kleine Erklärung zur Anpassung:
Code:
        int RareArray[2] = {1,2};
       
       
        //Wenn ihr hier in dem Array z.B. noch Gürtel haben wollt dann ändert es zu:
        int RareArray[3] = {1,2,34};
Ich hoffe ihr könnt etwas mit dem Release anfangen^^

Sollte soweit alles verständlich sein :)
Falls ihr fragen habt schreibt mich einfach in Skype an, ich beiße nicht ;)
12/08/2015 21:22 He3o Crysis#2
Danke für dein Release!

Verbesserungsvorschlag:
C-style arrays zu verwenden ist seit C++11 nicht mehr nötig.
Gibt noch vereinzelt Dinge bei denen uns C-style arrays noch was bringen, sind aber nicht für M2 relevant. (Außer evtl. string literals... char[] ist in machen Situationen schon was tolles..)
Du kannst std::array verwenden. Ist ein besseres Interface für die gleiche "Containerart".
Wenn du std::array verwendest kannste auch nen Range-based loop verwenden, da std::array über .begin und .end Methoden verfügt.

- Socialized
12/08/2015 21:31 Creek'#3
Quote:
Originally Posted by Socialized View Post
Danke für dein Release!

Verbesserungsvorschlag:
C-style arrays zu verwenden ist seit C++11 nicht mehr nötig.
Gibt noch vereinzelt Dinge bei denen uns C-style arrays noch was bringen, sind aber nicht für M2 relevant. (Außer evtl. string literals... char[] ist in machen Situationen schon was tolles..)
Du kannst std::array verwenden. Ist ein besseres Interface für die gleiche "Containerart".
Wenn du std::array verwendest kannste auch nen Range-based loop verwenden, da std::array über .begin und .end Methoden verfügt.

- Socialized
Danke für deinen Tipp. Bin noch nicht so erfahren in C++, aber werde mal versuchen deinen Vorschlag umzusetzen :D

Grüße ^.^
12/09/2015 13:00 kstmr#4
for(int i = 0; i < sizeof(tab); i++)i pretty much do not get it.
since sizeof tab is going to be bigger (unless you are under a system that has int set to 16bit only) then the length of your array. (here 4 btw)
there sizeof cannot detect the size of arrays passed from function to another one.
here is a sample of the bug:
PHP Code:
// sizeof-problem.cpp
// illustrates a bug of getting the size of an array using sizeof
#include <iostream>

void inArr(int*,int[]);

int main()
{
    
int ar_x[2] = {1,2};
    
// showing the sizeif ar_x where it was declared
    
std::cout << sizeof(ar_x) << std::endl; // 8
    // passing ar_x to another function
    
inArr(ar_x,ar_x);
}

void inArr(int* tab, int line[]) // tab and line are both pointers to int there is no difference
{
    
std::cout << sizeof(tab) << " " << sizeof(line) << std::endl; // 4
} 
thus the size of a passed array of int is always 4 (under a system that set it to be 32bit (aka 4 byte))
consider using the array class next time.
btw im not german so sorry if someone already told you the same thing.

good luck.
12/09/2015 14:24 Creek'#5
Quote:
Originally Posted by kstmr View Post
for(int i = 0; i < sizeof(tab); i++)i pretty much do not get it.
since sizeof tab is going to be bigger (unless you are under a system that has int set to 16bit only) then the length of your array. (here 4 btw)
there sizeof cannot detect the size of arrays passed from function to another one.
here is a sample of the bug:
PHP Code:
// sizeof-problem.cpp
// illustrates a bug of getting the size of an array using sizeof
#include <iostream>

void inArr(int*,int[]);

int main()
{
    
int ar_x[2] = {1,2};
    
// showing the sizeif ar_x where it was declared
    
std::cout << sizeof(ar_x) << std::endl; // 8
    // passing ar_x to another function
    
inArr(ar_x,ar_x);
}

void inArr(int* tab, int line[]) // tab and line are both pointers to int there is no difference
{
    
std::cout << sizeof(tab) << " " << sizeof(line) << std::endl; // 4
} 
thus the size of a passed array of int is always 4 (under a system that set it to be 32bit (aka 4 byte))
consider using the array class next time.
btw im not german so sorry if someone already told you the same thing.

good luck.
I have to thank you.
Now i tested it with the "_countof" and it seems to work.

_countof will always print the right size.

Code:
                        int RareArray[2] = {1,2}; //Hier alle Typ angeben welche 6/7 Boni droppen sollen.
                        if(inArr(RareArray,item->GetType(),_countof(RareArray))){
                                if (number(1, 100) <= 20){ //20% Chance
                                        item->AddRareAttribute();
                                        if (number(1, 100) <= 10) // 10% Chance
                                                item->AddRareAttribute();
                                }                              
                        }
Code:
bool inArr(int* tab, int line,int size) {
        for(int i = 0; i < size; i++){
                if(tab[i] == line)
                        return true;           
        }
        return false;
}
11/04/2017 05:27 Lauling#6
u have this proble after paste this code?
some sf needs to implate 6/7 boni first to use
11/07/2017 23:51 Kryptonit.'#7
Funktioniert.
Tested nice thanks.
03/10/2018 22:12 voldakov#8
Do not work, try to connect with a ninja

syserr: number_ex: number(): first argument is bigger than second argument 0 -> -1, item_attribute.cpp 405
03/13/2018 20:27 voldakov#9
Bump

There is a fix somewhere ? :x
03/15/2018 13:22 synthou1234#10
Quote:
Originally Posted by voldakov View Post
Do not work, try to connect with a ninja

syserr: number_ex: number(): first argument is bigger than second argument 0 -> -1, item_attribute.cpp 405

same problem ^^
03/15/2018 21:43 Ex0dia#11
Quote:
Originally Posted by voldakov View Post
Do not work, try to connect with a ninja

syserr: number_ex: number(): first argument is bigger than second argument 0 -> -1, item_attribute.cpp 405
It doesn't matter what race your character has.
Can u maybe post your code so we can help you?

Kind regards
Ex0dia
03/22/2018 20:20 voldakov#12
I use exactly same code here, compile fine, but when i want to log in my serveur, core dumped with this error :

syserr: number_ex: number(): first argument is bigger than second argument 0 -> -1, item_attribute.cpp 405

I never touch item_attribute.cpp file

my function in item_attribute.cpp


Line 405 : const TItemAttrTable& r = g_map_itemRare[avail[number(0, avail.size() - 1)]];
03/23/2018 13:36 FetteRatte.#13
Quote:
Originally Posted by voldakov View Post
I use exactly same code here, compile fine, but when i want to log in my serveur, core dumped with this error :

syserr: number_ex: number(): first argument is bigger than second argument 0 -> -1, item_attribute.cpp 405

I never touch item_attribute.cpp file

my function in item_attribute.cpp


Line 405 : const TItemAttrTable& r = g_map_itemRare[avail[number(0, avail.size() - 1)]];
post gdb you also should use this
[Only registered and activated users can see links. Click Here To Register...]
03/28/2018 10:49 voldakov#14
Fixed, missing function in AddRareATTR
04/02/2018 23:09 x'Radon#15
Quote:
Originally Posted by voldakov View Post
Fixed, missing function in AddRareATTR
Can you share the fix please?