Raised This Month: $32 Target: $400
 8% 

Damage problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Fixsek Kot
Member
Join Date: Feb 2022
Old 07-10-2022 , 12:38   Damage problem
Reply With Quote #1

Hi, here I am again.

I really didn't think I would have any other problem, but I didn't expect to have a problem with something stupid I can't resolve:
(This whole code is in ham_takedamage PRE)
PHP Code:
if(farpiece[attacker])
{
    if(
get_user_weapon(attacker) == CSW_AK47 && damagetype DMG_BULLET)
    {
        if(
get_pdata_int(victim75) == HIT_HEAD)
        {
            
SetHamParamFloat(4get_pcvar_float(farpiece_damagehs))
        }
        else
        {
            
SetHamParamFloat(4get_pcvar_float(farpiece_damage))
        }
    }
}
if(
level[id] >= 1)
{
    
SetHamParamFloat(4damage*leveldamage)

So basically I have a weapon that deals 67dmg, called farpiece, and when player reaches level one, all dmg he deals will be increased by 10%. The problem is that I thought the Float:damage receives the damage the farpiece does, and increases it by 10%, however it doesn't take farpiece's damage, it only takes damage that the original gun makes and totally ignores the farpiece... I thought this is going to be easy to resolve, but... it's ripping my guts out. Yeah I can add the damage right in the farpiece damage, but I also need the damage to be increased for other casual guns, but I'd have to add SetHamParamFloat that receives damage, but again, it totally disables farpiece's damage, I couldn't find any solution for this queer issue, so how do I fix it?

Last edited by Fixsek Kot; 07-10-2022 at 12:42.
Fixsek Kot is offline
damage220
Member
Join Date: Jul 2022
Location: Ukraine
Old 07-10-2022 , 14:10   Re: Damage problem
Reply With Quote #2

Do you have a weapon or a player class? I do not get the part farpiece[attacker] which indicates that you check against player flag "farpiece". What is the problem to have 2 damage multipliers for normal weapon and "farpiece"?

Last edited by damage220; 07-10-2022 at 14:44.
damage220 is offline
Fixsek Kot
Member
Join Date: Feb 2022
Old 07-10-2022 , 14:57   Re: Damage problem
Reply With Quote #3

Yeah I should have said the code contains like another 7 special guns, so it would be hard to divide, and also the takedamage register has player class. the farpiece[attacker] is just a variable checking if the player has bought the gun. Trust me I was thinking about dividing the guns into special and normal ones, but for example, if a player has a melee special (like chainsaw), then the "else" wouldn't be called and so the casual guns like M4A1 or AK47 wouldn't deal the increased damage, which I need. Maybe there's a way to do it, but I was trying to do it for HOURS, ran out of ideas and it was no success at all. I'm just asking if there ain't some easier and not time-taking solution to make it work.

Last edited by Fixsek Kot; 07-10-2022 at 14:59.
Fixsek Kot is offline
damage220
Member
Join Date: Jul 2022
Location: Ukraine
Old 07-10-2022 , 16:38   Re: Damage problem
Reply With Quote #4

First of all, I have to say I am noob in amx scripting). I started just a few days ago. I never created neither special weapon nor "takedamage register with player class". I would register client_damage event and check for the wpnindex. For example, we have CSW_KNIFE damage. If a player reaches level 1, increase damage. If a player hold special version, increase damage. See no problem with it. If you are bothered about copying similar code sections, just create an array of relations normal weapon -> special one and loop through it. If this is not the case, then I need to see the full code.
damage220 is offline
zXCaptainXz
Member
Join Date: May 2017
Old 07-10-2022 , 17:46   Re: Damage problem
Reply With Quote #5

Say "damage" is the name of the 4th argument in your Ham_TakeDamage function, when you call SetHamParamFloat(4, somerandomvalue), the "damage" argument remains the same, it's only changed for the next calls of the function. So what you are doing is this.

Original "damage" is 25.
You deal damage with farpiece, so you SetHamParamFloat(4, 500), expecting the damage to become 500.
You are higher than level 1, so you are using SetHamParamFloat(4, damage*leveldamage) to further boost your intended damage, however "damage" is still at 25, not 500, so farpiece damage is ignored.

A fix for this is to assign the "damage" variable to the same value you intend it to be after using SetHamParamFloat, so instead of typing
PHP Code:
       SetHamParamFloat(4get_pcvar_float(farpiece_damagehs)) 
You type
PHP Code:
        SetHamParamFloat(4get_pcvar_float(farpiece_damagehs))
    
damage get_pcvar_float(farpiece_damagehs
However you are calling get_pcvar_float twice for no reason now, so you can do something like what I wrote below.
PHP Code:
if(farpiece[attacker])
{
    if(
get_user_weapon(attacker) == CSW_AK47 && damagetype DMG_BULLET)
    {
        if(
get_pdata_int(victim75) == HIT_HEAD)
        {
            
damage get_pcvar_float(farpiece_damagehs)
        }
        else
        {
            
damage get_pcvar_float(farpiece_damage)
        }    
    }
    if(
level[id] >= 1)
    {
        
SetHamParamFloat(4damage*leveldamage)
    }
    else
    {
        
SetHamParamFloat(4damage)
    }
}
else if(
level[id] >= 1)
{
    
SetHamParamFloat(4damage*leveldamage)

zXCaptainXz is offline
Fixsek Kot
Member
Join Date: Feb 2022
Old 07-11-2022 , 07:02   Re: Damage problem
Reply With Quote #6

Nice, it finally works well! Thank you both for help! (How could I have not realized to just edit the Float:damage bruh.. )
Fixsek Kot is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:51.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode