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

Two weapons for knights!

Kakaher

Member
Joined
Nov 2, 2009
Messages
129
Reaction score
7
Hello everyone!!
I'm using the script by John992 that allows players to use 2 weapons

The script works like this:

on player.cpp change:
Code:
ret = RET_CANONLYUSEONEWEAPON;
to
Code:
ret = RET_NOERROR;

on weapons.h below:
Code:
const Weapon* getWeapon(const Item* item) const;
add:
Code:
   static int32_t getAttackLeft;
            static int32_t getAttackRigth;
            static int32_t getLeftExtraAttack;
            static int32_t getRigthExtraAttack;

on weapons.cpp change:
Code:
int32_t WeaponMelee::getWeaponDamage(const Player* player, const Creature* target, const Item* item, bool maxDamage /*= false*/) const
{
        int32_t attackSkill = player->getWeaponSkill(item);
        int32_t attackValue = std::max((int32_t)0, (int32_t(item->getAttack() + item->getExtraAttack()) - elementDamage));
        float attackFactor = player->getAttackFactor();

to:

Code:
int32_t WeaponMelee::getWeaponDamage(const Player* player, const Creature* target, const Item* item, bool maxDamage /*= false*/) const
{
                
    int32_t getAttackLeft;
    int32_t getAttackRigth;
    int32_t getLeftExtraAttack;
        int32_t getRigthExtraAttack;
    
    getAttackLeft = 0;
    getAttackRigth = 0;
    getLeftExtraAttack = 0;
        getRigthExtraAttack = 0;
    
    if (getAttackLeft == 0)
    { 
        if (player->getInventoryItem(SLOT_LEFT) != NULL)
        {
        getAttackLeft = player->getInventoryItem(SLOT_LEFT)->getAttack();
        getLeftExtraAttack = player->getInventoryItem(SLOT_LEFT)->getExtraAttack();
        }
        else if (player->getInventoryItem(SLOT_LEFT) == NULL)
        {
        getAttackLeft = 0;
        getLeftExtraAttack = 0;  
        }
    }  
    
    if (getAttackRigth == 0)
    { 
        if (player->getInventoryItem(SLOT_RIGHT) != NULL)
        {
        getAttackRigth = player->getInventoryItem(SLOT_RIGHT)->getAttack();
        getRigthExtraAttack = player->getInventoryItem(SLOT_RIGHT)->getExtraAttack();
        }
        else if (player->getInventoryItem(SLOT_RIGHT) == NULL)
        {
        getAttackRigth = 0;
        getRigthExtraAttack = 0;  
        }
    }                                                 
    
    
    int32_t attackValue = std::max((int32_t)0, (int32_t)((getAttackLeft + getLeftExtraAttack + getAttackRigth + getRigthExtraAttack) - elementDamage));                                               
             
    int32_t attackSkill = player->getWeaponSkill(item);
    float attackFactor = player->getAttackFactor();

and it is working great...

But I need someone to make this script useable ony for knights...

I tried but I couldn't do it...

I made this:

on creaturescripts I made this script:
Code:
function isWeapon(uid) -- Function by Mock the bear.
                 uid = uid or 0
                 local f = getItemWeaponType(uid)
                 if f == 1 or f == 2 or f == 3 then
                         return TRUE
                 end
                 return FALSE
end


function onThink(cid, interval)

local item = getPlayerSlotItem(cid, 6)

if isPlayer(cid) == TRUE and isWeapon(item.uid) and isWeapon(item2.uid) and getPlayerVocation(cid) == 1 or getPlayerVocation(cid) == 2 or getPlayerVocation(cid) == 3 or getPlayerVocation(cid) == 5 or getPlayerVocation(cid) == 6 or getPlayerVocation(cid) == 7 then
bag = getPlayerSlotItem(cid, 8)
doRemoveItem(item.uid,item.type)
doAddContainerItem(bag.uid,item.itemid,item.type)
doPlayerSendCancel(cid, "You must be an oger to use two weapons.")
end
return true
end

on login.lua I added:
Code:
registerCreatureEvent(cid, "KnightOnly")

and on creaturescripts.xml I added:
Code:
 <event type="think" name="KnightOnly" event="script" value="2swordeschecker.lua"/>

But, still any vocation can use two swords... I got no errors on console or on the server, the script just doesn't work..

BTW, I don't like to use attribute key="dualwield" because still every voc will be able to use 2 weapons, and I want every weapon on server "dual wieldable" but I don't wanna make them all to knights only...

Using TFS 0.4
Thanks already for the help everyone!!!!


--- EDIT
There is an error on the console:
Code:
[ERROR - CreatureScript Interface]
data/creaturescripts/scripts/2swordeschecker.lua:onThink
Description:
<luaGetThing> Thing not found
 
Last edited:
Go to players.cpp

find:
Code:
else if(inventory[SLOT_LEFT]) //We will add it for left and right hand.

after this
Code:
else if(!leftItem->isWeapon() || !item->isWeapon() ||
						leftType == WEAPON_SHIELD || leftType == WEAPON_AMMO
						|| type == WEAPON_SHIELD || type == WEAPON_AMMO)				
						ret = RET_NOERROR;

add this code:
Code:
else if(Player::getVocationId() == 4)
                       ret = RET_NOERROR;


Then found this right hand
Code:
else if(inventory[SLOT_RIGHT])

and after this
Code:
else if(!rightItem->isWeapon() || !item->isWeapon() ||
						rightType == WEAPON_SHIELD || rightType == WEAPON_AMMO
						|| type == WEAPON_SHIELD || type == WEAPON_AMMO)
						ret = RET_NOERROR;

add this code
Code:
else if(Player::getVocationId() == 4)
                        ret = RET_NOERROR;
 
for tfs 0.3.7 ... use the attribute on items
Code:
<attribute key="dualWield" value="1"/>

As I said, it won't work... Because I want all weapons to be "dual wieldable", but at the same time I don't want to make all the words on the server for knights only


Go to players.cpp

find:
Code:
else if(inventory[SLOT_LEFT]) //We will add it for left and right hand.

after this
Code:
else if(!leftItem->isWeapon() || !item->isWeapon() ||
						leftType == WEAPON_SHIELD || leftType == WEAPON_AMMO
						|| type == WEAPON_SHIELD || type == WEAPON_AMMO)				
						ret = RET_NOERROR;

add this code:
Code:
else if(Player::getVocationId() == 4)
                       ret = RET_NOERROR;


Then found this right hand
Code:
else if(inventory[SLOT_RIGHT])

and after this
Code:
else if(!rightItem->isWeapon() || !item->isWeapon() ||
						rightType == WEAPON_SHIELD || rightType == WEAPON_AMMO
						|| type == WEAPON_SHIELD || type == WEAPON_AMMO)
						ret = RET_NOERROR;

add this code
Code:
else if(Player::getVocationId() == 4)
                        ret = RET_NOERROR;

Thank you SO MUCH!!! It is working perfectly!!!!
 
How to get the Weapons.cpp Edit works on TFS 1.1?

Its show like here:
Code:
int32_t WeaponMelee::getElementDamage(const Player* player, const Creature*, const Item* item) const
{
    if (elementType == COMBAT_NONE) {
        return 0;
    }

    int32_t attackSkill = player->getWeaponSkill(item);
    int32_t attackValue = std::max<int32_t>(0, elementDamage);
    float attackFactor = player->getAttackFactor();
 
Back
Top