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

Solved C++ or LUA Check if player is wearing 2 weapons, if so INCREASE MONSTER DAMAGE

Vesgo

Member
Joined
Dec 4, 2009
Messages
356
Solutions
1
Reaction score
15
Location
Brasil
Hello guys, since i failed to manage de defense formula i changed my strategy.

Using TFs 0.4 rev 3777

How can i manage to verify if a player is wearing 2 weapons at the same time, and if so, monsters will deal more damage to him, but only if he is using 2 weapons.

I tryed to search, but got nothing. I made this piece of shi* script, but it does not check if the player is wearing weapons in SLOT_RIGHT and LEFT. Besides it is in creativescripts, and returns infinite loop!

Code:
function onThink(cid, interval)

local left = getPlayerSlotItem(cid, 6)
local right = getPlayerSlotItem(cid, 5)
local drunk = createConditionObject(CONDITION_DRUNK)

if isPlayer(cid) == TRUE and getPlayerVocation(cid) == 4 or getPlayerVocation(cid) == 8 or getPlayerVocation(cid) == 12 then
if left.itemid ~= 0 and right.itemid ~= 0 then
if getCreatureCondition(cid, CONDITION_INFIGHT) == true then

doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Drunk, Infight, Both Hands!')
doAddCondition(cid, drunk)
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, 'Nevermind.')
end
end
end
return true
end

I would like to include the increased damage from monsters under that condition into player.cpp (already have 2 weapons edited and working), but i dont think i can... so if someone can help me out, event with lua, i will appreciate!

Thank you very much.
 
Solution
Code:
            if (target->getPlayer() && target->getPlayer()->getInventoryItem(SLOT_LEFT) && target->getPlayer()->getInventoryItem(SLOT_LEFT)->isWeapon()&&
                target->getPlayer()->getInventoryItem(SLOT_RIGHT) && target->getPlayer()->getInventoryItem(SLOT_RIGHT)->isWeapon() && attacker && attacker->getMonster())
                damage *= 0.95;

Add This to game.cpp

Under
Code:
if(damage > 0)
        {
Code:
bool Game::combatChangeHealth(const CombatParams& params, Creature* attacker, Creature* target, int64_t healthChange, bool force)
When I get home, I have something exceptionally similar to this that I could edit for you.

But if you want to try on your own and learn some stuff while waiting 12 hours for me to post again..

I'll be using an onStatsChange script in creaturescripts.
Basically, you check if they have a weapon in both hands, and return the damage as false the first time, and resend the damage through a bit higher.

I'm not 100% certain (as I've never really tested this), but I think it may go through armor/resistance calculation twice using this method.
OnStatsChange only tells us the damage that would be afflicted to the player, after it's gone through the sources calculations. afaik
Worst case scenario, you can just adjust the damage multiplier a bit higher. :p
 
Code:
            if (target->getPlayer() && target->getPlayer()->getInventoryItem(SLOT_LEFT) && target->getPlayer()->getInventoryItem(SLOT_LEFT)->isWeapon()&&
                target->getPlayer()->getInventoryItem(SLOT_RIGHT) && target->getPlayer()->getInventoryItem(SLOT_RIGHT)->isWeapon() && attacker && attacker->getMonster())
                damage *= 0.95;

Add This to game.cpp

Under
Code:
if(damage > 0)
        {
Code:
bool Game::combatChangeHealth(const CombatParams& params, Creature* attacker, Creature* target, int64_t healthChange, bool force)
 
Last edited:
Solution
@Xikini Ty very much!

@tetra20 Ty again for trying to help me Tetra! I added the code, it really increases the monster damages, but it does not increases only when the player is wearing 2 weapons, but returns the new damage when the player is with 1 weapon and 1 shield too. I tryed to remove the "
target->getPlayer()->getInventoryItem(SLOT_LEFT)" but i noticed the code needs to read first if the player is wearing any item in that slot, and then, check if that item is a weapon (the server crashed when a monster hit the player).

It seems that the code returns a shield as a weapon, lol! Any ideas? I will check the isWeapon() to learn how it works...

Edit: It really identifies shield as weapon:
WEAPON_NONE = 0,
WEAPON_SWORD,
WEAPON_CLUB,
WEAPON_AXE,
WEAPON_DIST,
WEAPON_SHIELD,
WEAPON_FIST,
WEAPON_WAND,
WEAPON_AMMO

I think i just need to learn the syntax to remove the WEAPON_SHIELD from the isWeapon(), and it will work as needed!

EDIT2: I think i solved t he problem, i found this piece of code:
Code:
bool isWeapon() const {return (items[id].weaponType != WEAPON_NONE);}
, and noticed that it appeared only one time, so i created a new line:
Code:
bool isWeaponn() const {return (items[id].weaponType != WEAPON_SHIELD);}
and voilá! Now it returns the new damage only when the player is using 2 weapons!!
Than you very much @tetra20 !
 
Last edited:
@tetra20 This stuff is very cool, but now i found a bug :( When de player using 2 weapons step on a field, or is hit from anything from monsters/players that adds a condition, eg fire condition (Dragon Lord, demon etc..) the server crashes. Im trying to generate dumps do debug it, but for now, do you have any hints??

Anyone can help?
 
@tetra20 This stuff is very cool, but now i found a bug :( When de player using 2 weapons step on a field, or is hit from anything from monsters/players that adds a condition, eg fire condition (Dragon Lord, demon etc..) the server crashes. Im trying to generate dumps do debug it, but for now, do you have any hints??

Anyone can help?
attacker is most likely nullptr in this situation, so in that if where you have
Code:
&& attacker->getMonster()

Add this before:
Code:
&& attacker && attacker->getMonster()
 
@tetra20 This stuff is very cool, but now i found a bug :( When de player using 2 weapons step on a field, or is hit from anything from monsters/players that adds a condition, eg fire condition (Dragon Lord, demon etc..) the server crashes. Im trying to generate dumps do debug it, but for now, do you have any hints??

Anyone can help?

Forgot to check if the attacker wasn't Nul, well Matheus did the job xD
 
Back
Top