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

C++ (or lua) Using 2 weapons will low you defense

Vesgo

Member
Joined
Dec 4, 2009
Messages
356
Solutions
1
Reaction score
15
Location
Brasil
Hello guys, i´ve recently implemented the possiblity to use 2 weapons ate the same time, just for Knights. I´ve made some code changes but im stuck at this part:

Using TFS 0.4 rev 3777

How can i manage to, when the player wears the 2nd weapon, create somekind of condition to reduce his (global) defense (to all kinds of damage). I tryed to search for 3 days now, tryed lots of scripts (creature scripts), but without success.

I dont have problems to recompile my source codes, so if its easier to add this feature using C++, let me know ok?

Thank you guys!
 
Player.cpp
Code:
int32_t Player::getDefense() const

Add this line before the return
Code:
    Item* left = getInventoryItem(SLOT_RIGHT);
    Item* right = getInventoryItem(SLOT_LEFT);
    if (left && right)
    {
        if (left->isWeapon() && right->isWeapon())
            return ((int32_t)std::ceil(((float)(defenseSkill * (defenseValue * 0.015)) + (defenseValue * 0.1)) * defenseFactor)) * 0.123;
    }

I dont have a 0.4 to perform on but this should be fine enough

Change the 0.123 to anything you would want
 
Wow, that was fast! Thank you very much!
I already compiled, withou errors. Now im trying to set it up, let me see if i got it right!

the defense will get LOWER as i get closer to zero changing the *0.123 right?

and just to be sure, is it correct?
Code:
defenseValue += extraDefense;
    if(vocation->getMultiplier(MULTIPLIER_DEFENSE) != 1.0)
        defenseValue = int32_t(defenseValue * vocation->getMultiplier(MULTIPLIER_DEFENSE));

    Item* left = getInventoryItem(SLOT_RIGHT);
    Item* right = getInventoryItem(SLOT_LEFT);
    if (left && right)
    {
        if (left->isWeapon() && right->isWeapon())
            return ((int32_t)std::ceil(((float)(defenseSkill * (defenseValue * 0.015)) + (defenseValue * 0.1)) * defenseFactor)) * 0.123;
    }

    return ((int32_t)std::ceil(((float)(defenseSkill * (defenseValue * 0.015)) + (defenseValue * 0.1)) * defenseFactor));
 
Technically, 0.~ means X / Y where as Y > X so as long as you are getting nearer to zero the more it will decrease.. just put whatever number you like there and test if it even works cuz i am unsure
 
Is that supposed to help anyone?

I'm sorry. Instead of actually asking the community "and just to be sure, is it correct", download a common used IDE to actually test and validate your code.

It is of course possible to judge out of experience and knowledge whether it should or would work, but it is still no guarantee until tested since you can't be sure you've looked over every single case.
 
Last edited:
I'm sorry. Instead of actually asking the community "and just to be sure, is it correct", download a common used IDE to actually test and validate your code.

It is of course possible to judge out of experience and knowledge whether it should or would work, but it is still no guarantee until tested since you can't be sure you've looked over every single case.
Is That For Me? Cuz if it is really is then i got no reply for this :|
 
@tetra20 I compiled some versions, with higher and lower values, setup a new monster and tested with equipments, full set, without set, with/without 2 weapons. Im pretty sure its not returning any diferences in defense.

@tokenzz Im doing my best, dont you think im not testing at the best conditions my experience allows. I just asked that in respect of tetra20, just to minimize the possible errors at the posterior analisys of working/not working/possible errors. Just respect the community ok? Dont you think im stupid man, i may be a piece of shit coder/programmer/compiler, but im not dumb. I dont want to disrespect you, so if you have anything to teach us, be my guest ok?
 
Is That For Me? Cuz if it is really is then i got no reply for this :|
I think it was for Vesgo, while trying to be funny.

Basically just saying, if you want to know if the code works, try it. If it doesn't work, post errors, blah blah.

Text on a forum isn't the best place to be funny/ironic.
 
Vesgo, Try setting it for a very high number then a very low number and test against physical dmg
@tetra20 i was affraind of bugging it somehow, crashing the server, but right now im compiling with *100. I already compiled with *0.123, *0 and *0 inside all the "parentheses". I will give you feedback in some minutes! Thank you for your patience!
 
@tetra20 I compiled some versions, with higher and lower values, setup a new monster and tested with equipments, full set, without set, with/without 2 weapons. Im pretty sure its not returning any diferences in defense.

@tokenzz Im doing my best, dont you think im not testing at the best conditions my experience allows. I just asked that in respect of tetra20, just to minimize the possible errors at the posterior analisys of working/not working/possible errors. Just respect the community ok? Dont you think im stupid man, i may be a piece of shit coder/programmer/compiler, but im not dumb. I dont want to disrespect you, so if you have anything to teach us, be my guest ok?

Alright, I was harsh, I'm sorry.

A tip: refrain from using regular casts when programming in c++ (when you don't have to). This is unsafe since a regular cast (a c-style cast) is trying a range of sequences by taking the first that works in c++. This leads to it being more powerful but at the same time quite unnecessary and you can't foresee the possible bugs as easy if you were to use a specific c++ cast. Since we're working in an object oriented language with class hierarchies, we make use of polymorphism. Since we know what type we're expecting, just use a static cast.

Hope that helped you a bit code-wise.
 
@tetra20 It is working, i could notice that when i increased the value to *100. Using 2 weapons i got no damage at all. But even if i reduce to zero the result of the defense ((defenseSkill * (defenseValue * 0)) + (defenseValue * 0)) * defenseFactor)) * 0, i dont know why, it makes no significant difference. I think we may have some part of the "damage results" calculation not only just inside player.cpp.

EDIT: Not working at all guys.

EDIT2: Started a new thread, trying to increase damage from monsters, i dont think lowering defense will solve the problem. TY very much @tetra20
 
Last edited:
Back
Top