Raised This Month: $ Target: $400
 0% 

Headshot damage not changing


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
boynedmaster
Member
Join Date: Jun 2012
Old 07-20-2015 , 13:31   Headshot damage not changing
Reply With Quote #1

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.
__________________
I mean Venusaur...with a question mark
boynedmaster is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-20-2015 , 14:23   Re: Headshot damage not changing
Reply With Quote #2

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);

__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
boynedmaster
Member
Join Date: Jun 2012
Old 07-20-2015 , 14:25   Re: Headshot damage not changing
Reply With Quote #3

Quote:
Originally Posted by Powerlord View Post
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
__________________
I mean Venusaur...with a question mark
boynedmaster is offline
boynedmaster
Member
Join Date: Jun 2012
Old 07-20-2015 , 14:27   Re: Headshot damage not changing
Reply With Quote #4

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); 
__________________
I mean Venusaur...with a question mark

Last edited by boynedmaster; 07-20-2015 at 17:36.
boynedmaster is offline
pcmaster
AlliedModders Donor
Join Date: Sep 2009
Old 07-20-2015 , 17:15   Re: Headshot damage not changing
Reply With Quote #5

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).
__________________
Stopped hosting servers as of November 2018, no longer active around here.
pcmaster is offline
boynedmaster
Member
Join Date: Jun 2012
Old 07-20-2015 , 17:35   Re: Headshot damage not changing
Reply With Quote #6

Quote:
Originally Posted by pcmaster View Post
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.
__________________
I mean Venusaur...with a question mark
boynedmaster is offline
boynedmaster
Member
Join Date: Jun 2012
Old 07-20-2015 , 17:36   Re: Headshot damage not changing
Reply With Quote #7

Quote:
Originally Posted by pcmaster View Post
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.
__________________
I mean Venusaur...with a question mark
boynedmaster is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 07-20-2015 , 19:30   Re: Headshot damage not changing
Reply With Quote #8

If your using OnTakeDamage from SDKHooks, you don't need to do GetClientOfUserId as SDKHooks OnTakeDamage passes a client index.
__________________
WildCard65 is offline
boynedmaster
Member
Join Date: Jun 2012
Old 07-20-2015 , 19:37   Re: Headshot damage not changing
Reply With Quote #9

Quote:
Originally Posted by WildCard65 View Post
If your using OnTakeDamage from SDKHooks, you don't need to do GetClientOfUserId as SDKHooks OnTakeDamage passes a client index.
Oh
__________________
I mean Venusaur...with a question mark
boynedmaster is offline
boynedmaster
Member
Join Date: Jun 2012
Old 07-20-2015 , 20:04   Re: Headshot damage not changing
Reply With Quote #10

Quote:
Originally Posted by WildCard65 View Post
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.
__________________
I mean Venusaur...with a question mark
boynedmaster is offline
Reply



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 11:19.


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