AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Headshot damage not changing (https://forums.alliedmods.net/showthread.php?t=266820)

boynedmaster 07-20-2015 13:31

Headshot damage not changing
 
I have this snippet of code.
Code:

if(headshotProtect[victimId]){
                if(damagecustom == TF_CUSTOM_HEADSHOT){
                        damage = floatModulus(damage, 90.0);
                        PrintToServer("%f", damage);
                        changed = true;
                }
        }
       
        return changed ? Plugin_Changed : Plugin_Continue;

I have a bunch of other if statements that change the damage, and they all work just fine.
floatModulus is this function:
Code:

public float floatModulus(float a, float b){
        while(a > b)
                a -= b;
       
        return a;
}

How can I fix this? I've tried putting + 0.0, - 0.0, and * 1.0 at the end of the float, but none work.
The PrintToServer function tells me the damage I want it to be, but it doesn't actually change the damage.

Powerlord 07-20-2015 14:23

Re: Headshot damage not changing
 
Just to make sure, this function looks something like this, right?

PHP Code:

public Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetypeint &weapon,
        
float damageForce[3], float damagePosition[3], int damagecustom)
{
    
bool changed;

    if(
headshotProtect[victimId]){
        if(
damagecustom == TF_CUSTOM_HEADSHOT){
            
damage floatModulus(damage90.0);
            
PrintToServer("%f"damage);
            
changed true;
        }
    }
    
    return 
changed Plugin_Changed Plugin_Continue;


With the hook being created like this?

PHP Code:

public void OnClientPutInServer(int client)
{
    
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamage);



boynedmaster 07-20-2015 14:25

Re: Headshot damage not changing
 
Quote:

Originally Posted by Powerlord (Post 2322291)
Just to make sure, this function looks something like this, right?

PHP Code:

public Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetypeint &weapon,
        
float damageForce[3], float damagePosition[3], int damagecustom)
{
    
bool changed;

    if(
headshotProtect[victimId]){
        if(
damagecustom == TF_CUSTOM_HEADSHOT){
            
damage floatModulus(damage90.0);
            
PrintToServer("%f"damage);
            
changed true;
        }
    }
    
    return 
changed Plugin_Changed Plugin_Continue;


With the hook being created like this?

PHP Code:

public void OnClientPutInServer(int client)
{
    
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamage);



Yep, except it's:
PHP Code:

bool changed false


boynedmaster 07-20-2015 14:27

Re: Headshot damage not changing
 
Also victimId is this:
PHP Code:

int victimId GetEventInt(event"userid");
int attackerId GetEventInt(event"attacker"); 

But like I said, other if statements that change the damage work just fine with these.

EDIT:
I copied and pasted from the wrong function, lol.
PHP Code:

int attackerId GetClientUserId(attacker);
int victimId GetClientUserId(victim); 


pcmaster 07-20-2015 17:15

Re: Headshot damage not changing
 
If you are using victimid like that, you need to convert it to a client index first (otherwise your array access won't work properly).

boynedmaster 07-20-2015 17:35

Re: Headshot damage not changing
 
Quote:

Originally Posted by pcmaster (Post 2322375)
If you are using victimid like that, you need to convert it to a client index first (otherwise your array access won't work properly).

What? It's working perfectly fine. Everything works except the damage doesn't change. I get the PrintToServer that's said right after damage is set, and other if statements using victimId work 100% as intended.

boynedmaster 07-20-2015 17:36

Re: Headshot damage not changing
 
Quote:

Originally Posted by pcmaster (Post 2322375)
If you are using victimid like that, you need to convert it to a client index first (otherwise your array access won't work properly).

Oh, I copied and pasted from the wrong code. I edited the post.

WildCard65 07-20-2015 19:30

Re: Headshot damage not changing
 
If your using OnTakeDamage from SDKHooks, you don't need to do GetClientOfUserId as SDKHooks OnTakeDamage passes a client index.

boynedmaster 07-20-2015 19:37

Re: Headshot damage not changing
 
Quote:

Originally Posted by WildCard65 (Post 2322441)
If your using OnTakeDamage from SDKHooks, you don't need to do GetClientOfUserId as SDKHooks OnTakeDamage passes a client index.

Oh

boynedmaster 07-20-2015 20:04

Re: Headshot damage not changing
 
Quote:

Originally Posted by WildCard65 (Post 2322441)
If your using OnTakeDamage from SDKHooks, you don't need to do GetClientOfUserId as SDKHooks OnTakeDamage passes a client index.

Tested this. It's wrong.


All times are GMT -4. The time now is 03:32.

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