• 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!

TFS 0.X How to make that only one vocation can use DUALWIELD?

caquinha

Member
Joined
Aug 8, 2016
Messages
248
Solutions
1
Reaction score
24
How to make that only one vocation can use DUALWIELD?

My source already have DUALWIELD:

But for all vocation...

How to block to all vocation and allow only to vocation 15 and 16?
 
Solution
Code:
In file included from player.h:30:0,
                 from player.cpp:20:
vocation.h:125:23: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
   bool dualwielding = false; // Nobody can dual-wield by default.
                       ^~~~~
player.cpp: In member function ‘virtual bool Player::canSeeCreature(const Creature*) const’:
player.cpp:889:2: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
  if(const Player* player = creature->getPlayer())
  ^~
player.cpp:891:3: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘if’
   return !creature->isInvisible() || canSeeInvisibility();
   ^~~~~~
player.cpp: In member function...
yes is it can :)

just make an movement OnEquip script that check if player vocation is 15 or 16 and make an array with the dualwield items

I did change
dualWield default to true

so every one hand weapon is dualWield

should i add each weapon in itemid?
<movevent type="Equip" itemid="XXX" slot="???" event="script" value="script.lua"/>
 
can we check slot hands with onmove like this script?
 
I guess the easy way to do that is putting every weapon that is dual usable only for the class that u want, if all the one handed swords can be dual then this means that everyone who can equip this swords is dual.
 
I guess the easy way to do that is putting every weapon that is dual usable only for the class that u want, if all the one handed swords can be dual then this means that everyone who can equip this swords is dual.
but that is what i ask for
every one hand is already dual usable
because of dualWield default to true i told before

the only problem now is make it able only for two vocations
 
Try with a capital W just to make sure.

don't work, every vocation are able to equip the weapon

looking for dualWield on sources i found this:

but idk what to do with this :/
 
Vocation.h, give Vocation class new attribute "dualwielding"

bool dualwielding= false; // Nobody can dual-wield by default.

And add new public setter/getter for it:

C++:
        bool canDualWield() const {return dualwielding;}
        void setCanDualWield(bool v) {dualwielding= v;}


In vocations.cpp in parseVocationNode add

C++:
    if(readXMLString(p, "candualwield", strValue))
        voc->setCanDualWield(booleanString(strValue));

Now we use the new Vocation method in player.cpp in Player::__queryAdd func to add a new check when equipping item into hand slot whether the player's vocation can dualwield it:


C++:
else if(!leftItem->isWeapon() || !item->isWeapon() ||
                        leftType == WEAPON_AMMO || type == WEAPON_AMMO ||
                        leftType == WEAPON_SHIELD || type == WEAPON_SHIELD ||
                        (leftItem->isDualWield() && item->isDualWield() && player->getVocation()->canDualWield() ))
                        ret = RET_NOERROR;

And you can set in vocations.xml attribute "candualwield" now to vocs you want to enable this feature for.

EDIT: Changed name of variable one variable, was confusing and same as the name of a function.

EDIT2: I missed it, you also have to do the above edit for the Right hand too
here.
 
Vocation.h, give Vocation class new attribute "dualwielding"

bool dualwielding= false; // Nobody can dual-wield by default.

And add new public setter/getter for it:

C++:
        bool canDualWield() const {return dualwielding;}
        void setCanDualWield(bool v) {dualwielding= v;}


In vocations.cpp in parseVocationNode add

C++:
    if(readXMLString(p, "candualwield", strValue))
        voc->setCanDualWield(booleanString(strValue));

Now we use the new Vocation method in player.cpp in Player::__queryAdd func to add a new check when equipping item into hand slot whether the player's vocation can dualwield it:


C++:
else if(!leftItem->isWeapon() || !item->isWeapon() ||
                        leftType == WEAPON_AMMO || type == WEAPON_AMMO ||
                        leftType == WEAPON_SHIELD || type == WEAPON_SHIELD ||
                        (leftItem->isDualWield() && item->isDualWield() && player->getVocation()->canDualWield() ))
                        ret = RET_NOERROR;

And you can set in vocations.xml attribute "candualwield" now to vocs you want to enable this feature for.

EDIT: Changed name of variable one variable, was confusing and same as the name of a function.

EDIT2: I missed it, you also have to do the above edit for the Right hand too
here.


Code:
In file included from player.h:30:0,
                 from player.cpp:20:
vocation.h:125:23: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
   bool dualwielding = false; // Nobody can dual-wield by default.
                       ^~~~~
player.cpp: In member function ‘virtual bool Player::canSeeCreature(const Creature*) const’:
player.cpp:889:2: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
  if(const Player* player = creature->getPlayer())
  ^~
player.cpp:891:3: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘if’
   return !creature->isInvisible() || canSeeInvisibility();
   ^~~~~~
player.cpp: In member function ‘virtual ReturnValue Player::__queryAdd(int32_t, const Thing*, uint32_t, uint32_t) const’:
player.cpp:2730:29: error: ‘creature’ was not declared in this scope
      const Player* player = creature->getPlayer();
                             ^~~~~~~~
Makefile:33: recipe for target 'player.o' failed
make: *** [player.o] Error 1

did i've done something wrong in player.cpp?
Code:
                else if(inventory[SLOT_LEFT])
                {
                    const Item* leftItem = inventory[SLOT_LEFT];
                    WeaponType_t type = item->getWeaponType(), leftType = leftItem->getWeaponType();
                    
                    // only some vocation can dual wield 1
                    const Player* player = creature->getPlayer();

                    if(leftItem->getSlotPosition() & SLOTP_TWO_HAND)
                        ret = RET_DROPTWOHANDEDITEM;
                    else if(item == leftItem && item->getItemCount() == count)
                        ret = RET_NOERROR;
                    else if(leftType == WEAPON_SHIELD && type == WEAPON_SHIELD)
                        ret = RET_CANONLYUSEONESHIELD;
                    // only some vocation can dual wield 2
                    else if(!leftItem->isWeapon() || !item->isWeapon() ||
                        leftType == WEAPON_AMMO || type == WEAPON_AMMO ||
                        leftType == WEAPON_SHIELD || type == WEAPON_SHIELD ||
                        (leftItem->isDualWield() && item->isDualWield() && player->getVocation()->canDualWield() ))
                        ret = RET_NOERROR;
                    else
                        ret = RET_CANONLYUSEONEWEAPON;
                }
 
Code:
In file included from player.h:30:0,
                 from player.cpp:20:
vocation.h:125:23: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11
   bool dualwielding = false; // Nobody can dual-wield by default.
                       ^~~~~
player.cpp: In member function ‘virtual bool Player::canSeeCreature(const Creature*) const’:
player.cpp:889:2: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
  if(const Player* player = creature->getPlayer())
  ^~
player.cpp:891:3: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘if’
   return !creature->isInvisible() || canSeeInvisibility();
   ^~~~~~
player.cpp: In member function ‘virtual ReturnValue Player::__queryAdd(int32_t, const Thing*, uint32_t, uint32_t) const’:
player.cpp:2730:29: error: ‘creature’ was not declared in this scope
      const Player* player = creature->getPlayer();
                             ^~~~~~~~
Makefile:33: recipe for target 'player.o' failed
make: *** [player.o] Error 1

did i've done something wrong in player.cpp?
Code:
                else if(inventory[SLOT_LEFT])
                {
                    const Item* leftItem = inventory[SLOT_LEFT];
                    WeaponType_t type = item->getWeaponType(), leftType = leftItem->getWeaponType();
                  
                    // only some vocation can dual wield 1
                    const Player* player = creature->getPlayer();

                    if(leftItem->getSlotPosition() & SLOTP_TWO_HAND)
                        ret = RET_DROPTWOHANDEDITEM;
                    else if(item == leftItem && item->getItemCount() == count)
                        ret = RET_NOERROR;
                    else if(leftType == WEAPON_SHIELD && type == WEAPON_SHIELD)
                        ret = RET_CANONLYUSEONESHIELD;
                    // only some vocation can dual wield 2
                    else if(!leftItem->isWeapon() || !item->isWeapon() ||
                        leftType == WEAPON_AMMO || type == WEAPON_AMMO ||
                        leftType == WEAPON_SHIELD || type == WEAPON_SHIELD ||
                        (leftItem->isDualWield() && item->isDualWield() && player->getVocation()->canDualWield() ))
                        ret = RET_NOERROR;
                    else
                        ret = RET_CANONLYUSEONEWEAPON;
                }
Yeah my bad, since this is already this player's object, we should be able to get his vocation with just accessing member vocation, so replace `player->getVocation()->canDualWeild()) with vocation->canDualWield(). Delete this other thing you added.

(Alternatively, you could access it through public getter, which might be more appropriate getVocation()->canDualWield()) or even grab vocation object by utilizing the ID of the voc only: Vocation* voc = Vocations::getInstance()->getVocation(vocationId); and then voc->canDualWield(). I see it was used several times in player.cpp code but this seems redundant to me since getVocation() already exists 🤔 )

Make sure to do this in both left hand and right hand code.

Then in vocation.h change
bool dualwielding= false;
To just
bool dualwielding;

Seems like you are using older c++ version where this is not allowed.
Instead, now we will have to initialize value to this member elsewhere.
Even though XML parser is giving it value after reading it, we still want to have a guarantee that there will be a default value for this attribute.

In vocation.cpp in void Vocation::reset() add:
dualwielding = false;
 
Solution
Yeah my bad, since this is already this player's object, we should be able to get his vocation with just accessing member vocation, so replace `player->getVocation()->canDualWeild()) with vocation->canDualWield(). Delete this other thing you added.

(Alternatively, you could access it through public getter, which might be more appropriate getVocation()->canDualWield()) or even grab vocation object by utilizing the ID of the voc only: Vocation* voc = Vocations::getInstance()->getVocation(vocationId); and then voc->canDualWield(). I see it was used several times in player.cpp code but this seems redundant to me since getVocation() already exists 🤔 )

Make sure to do this in both left hand and right hand code.

Then in vocation.h change
bool dualwielding= false;
To just
bool dualwielding;

Seems like you are using older c++ version where this is not allowed.
Instead, now we will have to initialize value to this member elsewhere.
Even though XML parser is giving it value after reading it, we still want to have a guarantee that there will be a default value for this attribute.

In vocation.cpp in void Vocation::reset() add:
dualwielding = false;

everything works!!!
thank you so much!
 
Back
Top