• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Trying to combine skills enums.h gives a lot of error

Stanos

Veteran OT User
Joined
Jun 12, 2018
Messages
587
Solutions
4
Reaction score
315
Location
Europe
Hi
so i'm trying to combine SKILL_SWORD = SKILL_AXE, so lets say if i kill my sword axe should skill to.
Code:
enum skills_t : uint8_t {
    SKILL_FIST = 0,
    SKILL_CLUB = 1,
    SKILL_SWORD = 2,
    SKILL_AXE = 3,
    SKILL_DISTANCE = 4,
    SKILL_SHIELD = 5,
    SKILL_FISHING = 6,

    SKILL_MAGLEVEL = 7,
    SKILL_LEVEL = 8,

    SKILL_FIRST = SKILL_FIST,
    SKILL_SWORD = SKILL_AXE,
    SKILL_LAST = SKILL_FISHING
};
So now when i try to compile source it gives me a lot of errors. What am i doing wrong?
 
Solution
In weapons.cpp
C++:
void Weapon:onUsedWeapon(Player* player, Item* item, Tile* destTile) const

Search for:
C++:
        if (getSkillType(player, item, skillType, skillPoint)) {
            player->addSkillAdvance(skillType, skillPoint);
        }

and replace it to:
C++:
        if (getSkillType(player, item, skillType, skillPoint)) {
            player->addSkillAdvance(skillType, skillPoint);
          
            if(skillType == SKILL_AXE)
                player->addSkillAdvance(SKILL_SWORD, 1);
        }

Next find:
C++:
bool Weapon::useFist(Player* player, Creature* target)

and below this:
C++:
player->addSkillAdvance(SKILL_FIST, 1);
add:
C++:
player->addSkillAdvance(SKILL_SWORD, 1);
First of all, you have SKILL_SWORD defined twice; remove one of them. Second, we can‘t help you with compile errors if you don’t give us the compile errors.
 
or set the number from 3 to 2
1>..\src\tools.cpp(743): error C2196: case value '2' already used

First of all, you have SKILL_SWORD defined twice; remove one of them. Second, we can‘t help you with compile errors if you don’t give us the compile errors.
If i delete skill_sword it says error C2065: 'SKILL_AXE': undeclared identifier (and there is links of sources)
 
If i delete skill_sword it says error C2065: 'SKILL_AXE': undeclared identifier (and there is links of sources)
In your original post, just remove “SKILL_SWORD = 2,” and leave “SKILL_SWORD = SKILL_AXE,”. “SKILL_SWORD = SKILL_AXE,” has to come after “SKILL_AXE = 3,”, otherwise the compiler can’t find SKILL_AXE and will fail. Also, you’ll get an error in tools.cpp->getSkillName() because SKILL_SWORD and SKILL_AXE now use the same value. You need to decide which case to remove depending on which string you don’t care about.
 
In your original post, just remove “SKILL_SWORD = 2,” and leave “SKILL_SWORD = SKILL_AXE,”. “SKILL_SWORD = SKILL_AXE,” has to come after “SKILL_AXE = 3,”, otherwise the compiler can’t find SKILL_AXE and will fail. Also, you’ll get an error in tools.cpp->getSkillName() because SKILL_SWORD and SKILL_AXE now use the same value. You need to decide which case to remove depending on which string you don’t care about.
So if i remove skill_sword=2 and place it after skill_axe=3
Code:
enum skills_t : uint8_t {
    SKILL_FIST = 0,
    SKILL_CLUB = 1,
    SKILL_AXE = 3,
    SKILL_DISTANCE = 4,
    SKILL_SHIELD = 5,
    SKILL_FISHING = 6,

    SKILL_MAGLEVEL = 7,
    SKILL_LEVEL = 8,

    SKILL_FIRST = SKILL_FIST,
    SKILL_SWORD = SKILL_AXE,
    SKILL_LAST = SKILL_FISHING
};
I get error C2196: case value '3' already used
So doesnt this mean code should look like this?
Code:
enum skills_t : uint8_t {
    SKILL_FIST = 0,
    SKILL_CLUB = 1,
    SKILL_DISTANCE = 4,
    SKILL_SHIELD = 5,
    SKILL_FISHING = 6,

    SKILL_MAGLEVEL = 7,
    SKILL_LEVEL = 8,

    SKILL_FIRST = SKILL_FIST,
    SKILL_SWORD = SKILL_AXE,
    SKILL_LAST = SKILL_FISHING
};
 
I get error C2196: case value '3' already used
Did you read my whole post? That error isn’t from that enum, it’s from the switch in tools.cpp (if you’re using Visual Studio you can double-click on the error in the Output window and it will take you to the code that the error came from).

I’ll put what I said in my last post here again so you don’t miss it:
“Also, you’ll get an error in tools.cpp->getSkillName() because SKILL_SWORD and SKILL_AXE now use the same value. You need to decide which case to remove depending on which string you don’t care about.”
 
Did you read my whole post? That error isn’t from that enum, it’s from the switch in tools.cpp (if you’re using Visual Studio you can double-click on the error in the Output window and it will take you to the code that the error came from).

I’ll put what I said in my last post here again so you don’t miss it:
“Also, you’ll get an error in tools.cpp->getSkillName() because SKILL_SWORD and SKILL_AXE now use the same value. You need to decide which case to remove depending on which string you don’t care about.”
Oh shit sorry :D I have to decide which case i dont care about. This sounds really weird and stupid so doesnt this mean i can delete what ever case i want? Or technically i have to remove
case SKILL_SWORD:
return "sword fighting";
because this is the case value 3 which gives me that error?
 
The enum you are providing makes no sense,
1- Remove the line which redefines SKILL_SWORD = SKILL_AXE.
2- ```C2196: case value 'X' already used``` This error is related to `switch` statement.
So please provide the code where the error is shown..

From the previous comment, i read that you said this is a stupid conversation.
I assume the 'stupid' comes from the main post. You said you have compile errors without giving the error until somebody asked you for it. You are not really giving the code where the error occurs. Some more? Please don't be rude otherwise you gotta get banned.

--- PS
In your enum, i can assume it compiled fine.
SKILL_AXE and SKILL_SWORD have the same value.

Code:
switch(skill) {
    // axe = 3, sword = 3 (both cases match, ERROR)....
    case SKILL_SWORD:
    case SKILL_AXE:
}
 
The enum you are providing makes no sense,
1- Remove the line which redefines SKILL_SWORD = SKILL_AXE.
2- ```C2196: case value 'X' already used``` This error is related to `switch` statement.
So please provide the code where the error is shown..

From the previous comment, i read that you said this is a stupid conversation.
I assume the 'stupid' comes from the main post. You said you have compile errors without giving the error until somebody asked you for it. You are not really giving the code where the error occurs. Some more? Please don't be rude otherwise you gotta get banned.

--- PS
In your enum, i can assume it compiled fine.
SKILL_AXE and SKILL_SWORD have the same value.

Code:
switch(skill) {
    // axe = 3, sword = 3 (both cases match, ERROR)....
    case SKILL_SWORD:
    case SKILL_AXE:
}
1. If i remove SKILL_SWORD=SKILL_AXE i get no errors in the tools.cpp because they are not have the same value anymore so this is not a solution because this thread is made to combine these two
2. C2196 case value '3' already used so i suppose
Code:
std::string getSkillName(uint8_t skillid)
{
    switch (skillid) {
        case SKILL_FIST:
            return "fist fighting";

        case SKILL_CLUB:
            return "club fighting";

        case SKILL_SWORD:
            return "sword fighting";

        case SKILL_AXE:
            return "axe fighting";

        case SKILL_DISTANCE:
            return "distance fighting";

        case SKILL_SHIELD:
            return "shielding";

        case SKILL_FISHING:
            return "fishing";

        case SKILL_MAGLEVEL:
            return "magic level";

        case SKILL_LEVEL:
            return "level";

        default:
            return "unknown";
    }
}
Is this part
Code:
        case SKILL_SWORD:
            return "sword fighting";

Btw i'm not rude i'm just saying my opinion i have full rights to tell what i'm thinking. Everyone in this forum are toxic in the different ways
 
So remove that part (since sword & axe have the same value).
I was thinking the same. I'll try it out.
You mean that a player, using axe and sword, increases the 2 types of skill ?
Or that the player using axe or sword, the skills are combined?
First option using axe and sword increase the 2 type of skills. Because i have critical system which based on sword fighting so my idea is to change sword fighting as i critical and axe keep as a main weapon in the server.
 
in your player.cpp change the SKILL_AXE,CLUB per only SWORD
Code:
int32_t Player::getWeaponSkill(const Item* item) const
{
    if (!item) {
        return getSkillLevel(SKILL_FIST);
    }

    int32_t attackSkill;

    WeaponType_t weaponType = item->getWeaponType();
    switch (weaponType) {
        case WEAPON_SWORD: {
            attackSkill = getSkillLevel(SKILL_SWORD);
            break;
        }

        case WEAPON_CLUB: {
            attackSkill = getSkillLevel(SKILL_CLUB);
            break;
        }

        case WEAPON_AXE: {
            attackSkill = getSkillLevel(SKILL_AXE);
            break;
        }

        case WEAPON_DISTANCE: {
            attackSkill = getSkillLevel(SKILL_DISTANCE);
            break;
        }

        default: {
            attackSkill = 0;
            break;
        }
    }
    return attackSkill;
}

and on weapons.cpp
search the function
Code:
bool WeaponMelee::getSkillType(const Player* player, const Item* item,
                               skills_t& skill, uint32_t& skillpoint) const
{
    if (player->getAddAttackSkill() && player->getLastAttackBlockType() != BLOCK_IMMUNITY) {
        skillpoint = 1;
    } else {
        skillpoint = 0;
    }

    WeaponType_t weaponType = item->getWeaponType();
    switch (weaponType) {
        case WEAPON_SWORD: {
            skill = SKILL_SWORD;
            return true;
        }

        case WEAPON_CLUB: {
            skill = SKILL_CLUB;
            return true;
        }

        case WEAPON_AXE: {
            skill = SKILL_AXE;
            return true;
        }

        default:
            break;
    }
    return false;
}
and change SKILL_AXE,CLUB per only SWORD

not is necesary change nothing here:
Code:
enum skills_t : uint8_t {
 
So yea like Slavi Dodo said i remov
in your player.cpp change the SKILL_AXE,CLUB per only SWORD
Code:
int32_t Player::getWeaponSkill(const Item* item) const
{
    if (!item) {
        return getSkillLevel(SKILL_FIST);
    }

    int32_t attackSkill;

    WeaponType_t weaponType = item->getWeaponType();
    switch (weaponType) {
        case WEAPON_SWORD: {
            attackSkill = getSkillLevel(SKILL_SWORD);
            break;
        }

        case WEAPON_CLUB: {
            attackSkill = getSkillLevel(SKILL_CLUB);
            break;
        }

        case WEAPON_AXE: {
            attackSkill = getSkillLevel(SKILL_AXE);
            break;
        }

        case WEAPON_DISTANCE: {
            attackSkill = getSkillLevel(SKILL_DISTANCE);
            break;
        }

        default: {
            attackSkill = 0;
            break;
        }
    }
    return attackSkill;
}

and on weapons.cpp
search the function
Code:
bool WeaponMelee::getSkillType(const Player* player, const Item* item,
                               skills_t& skill, uint32_t& skillpoint) const
{
    if (player->getAddAttackSkill() && player->getLastAttackBlockType() != BLOCK_IMMUNITY) {
        skillpoint = 1;
    } else {
        skillpoint = 0;
    }

    WeaponType_t weaponType = item->getWeaponType();
    switch (weaponType) {
        case WEAPON_SWORD: {
            skill = SKILL_SWORD;
            return true;
        }

        case WEAPON_CLUB: {
            skill = SKILL_CLUB;
            return true;
        }

        case WEAPON_AXE: {
            skill = SKILL_AXE;
            return true;
        }

        default:
            break;
    }
    return false;
}
and change SKILL_AXE,CLUB per only SWORD

not is necesary change nothing here:
Code:
enum skills_t : uint8_t {
Just to make sure you mean
  1. case WEAPON_AXE: {
  2. attackSkill = getSkillLevel(SKILL_AXE);
  3. break;
  4. }
To
case WEAPON_AXE: {
attackSkill = getSkillLevel(SKILL_SWORD);
break;
}
 
Back
Top