• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[7.6][C++]Only profesion knight can use this weapon

legadoss

Member
Joined
Jun 1, 2014
Messages
142
Reaction score
5
hey, i have one problems. how i can block item id 2433 use by sorcerer,druid,paladin?
only knight can equip this weapon

my code
Code:
    if(weaponid == 2433 & player->vocation == VOCATION_KNIGHT)
    {
        dist = g_config.swordxx;
        if (abs(player->pos.x - attackedCreature->pos.x) > dist ||
            abs(player->pos.y - attackedCreature->pos.y) > dist)
            return;

        runeAreaSpell.attackType = ATTACK_FIRE;
        runeAreaSpell.animationEffect = NM_ANI_FIRE;
        runeAreaSpell.hitEffect = NM_ME_FIRE_AREA;
        runeAreaSpell.areaEffect = NM_ME_FIRE_AREA;
        runeAreaSpell.animationColor = 0xC7;

        runeAreaSpell.minDamage = 14;
        runeAreaSpell.maxDamage = 24;
        mana = g_config.swordxx;
    }

now all profesion can equip and use this weapon
 
Solution
You already have access to the item and player object.

You need to edit CONST_SLOT_RIGHT, and CONST_SLOT_LEFT, before last return true in the switch case statement (assuming this is not a two-handed weapon).

If it is a two-handed weapon you need to add it before the first return true in the switch case.

C++:
// If itemid is the one we only want to allow Knights to equip, and vocation is NOT a knight
if ((item->getItemId() == 2433) && (player->vocation != VOCATION_KNIGHT)) {
    player->sendCancel("This weapon can only be equipped by Knights.");
    return false; // Don't equip it.
}

Don't know the source of the item object, so the getItemId() function property is just a wild guess. Could also be getId(), or just plain ->itemid etc...
Link us the source code of your server, preferably an online git repo or something.
We need to find something similar to onEquip. And inject some checks for itemid and character vocation and stop the event if those conditions are not set.
 
Link us the source code of your server, preferably an online git repo or something.
We need to find something similar to onEquip. And inject some checks for itemid and character vocation and stop the event if those conditions are not set.
no't have onEquip in source, i use kentana 3.0
 
no't have onEquip in source, i use kentana 3.0
I said something similar, and you didnt link me any source code. How can we help without knowing the code?

I have never heard of kentana.

There is some code in there for the general functionality of equipping or moving items between slots, assuming its an OT server that works.
 
I said something similar, and you didnt link me any source code. How can we help without knowing the code?

I have never heard of kentana.

There is some code in there for the general functionality of equipping or moving items between slots, assuming its an OT server that works.
you can download it from chomikuj.pl
btw i can show you on tv

here is code
C++:
/*->inventory*/
bool Game::onPrepareMoveThing(Player *player, const Item *item, slots_t toSlot, int count)
{
    switch(toSlot)
    {
    case CONST_SLOT_HEAD:
        if(item->getSlotPosition() & SLOTP_HEAD)
            return true;
        break;
    case CONST_SLOT_NECKLACE:
        if(item->getSlotPosition() & SLOTP_NECKLACE)
            return true;
        break;
    case CONST_SLOT_BACKPACK:
        if(item->getSlotPosition() & SLOTP_BACKPACK)
            return true;
        break;
    case CONST_SLOT_ARMOR:
        if(item->getSlotPosition() & SLOTP_ARMOR)
            return true;
        break;
    case CONST_SLOT_RIGHT:
        if(item->getSlotPosition() & SLOTP_RIGHT){
             if(item->isWeapon() && !item->isShield() && player->items[CONST_SLOT_LEFT] && player->items[CONST_SLOT_LEFT]->isWeapon() && !player->items[CONST_SLOT_LEFT]->isShield() && (item != player->items[CONST_SLOT_LEFT]))
             {
                player->sendCancel("Sorry, you cannot use two weapons one time.");
             return false;
             }
             if(item->isShield() && player->items[CONST_SLOT_LEFT] && player->items[CONST_SLOT_LEFT]->isShield() && (item != player->items[CONST_SLOT_LEFT]))
             {
               player->sendCancel("Sorry, you cannot use two shields one time.");
             return false;
             }
            if(item->getSlotPosition() & SLOTP_TWO_HAND){
                if(player->items[CONST_SLOT_LEFT] != nullptr){
                    player->sendCancel("First remove the two-handed item.");
                    return false;
                }
                return true    ;
            }
            else{
                if(player->items[CONST_SLOT_LEFT]){
                    if(player->items[CONST_SLOT_LEFT]->getSlotPosition() & SLOTP_TWO_HAND){
                        player->sendCancel("First remove the two-handed item.");
                        return false;
                    }
                    return true;
                }
                return true;
            }
        }
        break;
    case CONST_SLOT_LEFT:
        if(item->getSlotPosition() & SLOTP_LEFT){
              if(item->isWeapon() && !item->isShield() && player->items[CONST_SLOT_RIGHT] && player->items[CONST_SLOT_RIGHT]->isWeapon() && !player->items[CONST_SLOT_RIGHT]->isShield() && (item != player->items[CONST_SLOT_RIGHT]))
              {
                   player->sendCancel("Sorry, you cannot use two weapons once.");
              return false;
              }
              if(item->isShield() && player->items[CONST_SLOT_RIGHT] && player->items[CONST_SLOT_RIGHT]->isShield() && (item != player->items[CONST_SLOT_RIGHT]))
              {
                  player->sendCancel("Sorry, you cannot use two shields once.");
              return false;
              }
            if(item->getSlotPosition() & SLOTP_TWO_HAND){
                if(player->items[CONST_SLOT_RIGHT] != nullptr){
                    player->sendCancel("First remove the two-handed item.");
                    return false;
                }
                return true    ;
            }
            else{
                if(player->items[CONST_SLOT_RIGHT]){
                    if(player->items[CONST_SLOT_RIGHT]->getSlotPosition() & SLOTP_TWO_HAND){
                        player->sendCancel("First remove the two-handed item.");
                        return false;
                    }
                    return true;
                }
                return true;
            }
        }
        break;
    case CONST_SLOT_LEGS:
        if(item->getSlotPosition() & SLOTP_LEGS)
            return true;
        break;
    case CONST_SLOT_FEET:
        if(item->getSlotPosition() & SLOTP_FEET)
            return true;
        break;
    case CONST_SLOT_RING:
        if(item->getSlotPosition() & SLOTP_RING)
            return true;
        break;
    case CONST_SLOT_AMMO:
        if(item->getSlotPosition() & SLOTP_AMMO)
            return true;
        break;
    }

    player->sendCancel("You cannot put that object in that place.");
    return false;
}
 
You already have access to the item and player object.

You need to edit CONST_SLOT_RIGHT, and CONST_SLOT_LEFT, before last return true in the switch case statement (assuming this is not a two-handed weapon).

If it is a two-handed weapon you need to add it before the first return true in the switch case.

C++:
// If itemid is the one we only want to allow Knights to equip, and vocation is NOT a knight
if ((item->getItemId() == 2433) && (player->vocation != VOCATION_KNIGHT)) {
    player->sendCancel("This weapon can only be equipped by Knights.");
    return false; // Don't equip it.
}

Don't know the source of the item object, so the getItemId() function property is just a wild guess. Could also be getId(), or just plain ->itemid etc.

If you just don't care about which slot / Just want to block it from any slot, you can add the code above the switch statement. Maybe add an additional condition to allow it in the backpack slot.
 
Last edited:
Solution
You already have access to the item and player object.

You need to edit CONST_SLOT_RIGHT, and CONST_SLOT_LEFT, before last return true in the switch case statement (assuming this is not a two-handed weapon).

If it is a two-handed weapon you need to add it before the first return true in the switch case.

C++:
// If itemid is the one we only want to allow Knights to equip, and vocation is NOT a knight
if ((item->getItemId() == 2433) && (player->vocation != VOCATION_KNIGHT)) {
    player->sendCancel("This weapon can only be equipped by Knights.");
    return false; // Don't equip it.
}

Don't know the source of the item object, so the getItemId() function property is just a wild guess. Could also be getId(), or just plain ->itemid etc.

If you just don't care about which slot / Just want to block it from any slot, you can add the code above the switch statement. Maybe add an additional condition to allow it in the backpack slot.
thanks its work! just change getItemId to getID
 
Back
Top