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

Solved Getting amount of damage to entity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
farawayf
Senior Member
Join Date: Jan 2019
Old 04-21-2019 , 16:30   Getting amount of damage to entity
Reply With Quote #1

Im trying to store players damage to entity with sdkhook ontakedamagepost, and when entity destroyed print to chat amount of damage dealed by player, but it prints random numbers like 1mil.

PHP Code:

public void OnTakeDamagePost(int entityint attackerint inflictorfloat damageint damagetype) {
    if (
attacker) {
        
Damage[attacker] += damage;
    }     
}    

public 
void OnEntityDestroyed(int entity) {

.....

    for (
int client 1client <= MaxClientsclient++) {
        
PrintToChat(client"dmg %i"Damage[test]
    }


Last edited by farawayf; 04-21-2019 at 16:56.
farawayf is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 04-21-2019 , 16:39   Re: Getting amount of damage to entity
Reply With Quote #2

It is a float (an assumption, as you haven't provided enough code) but you're printing it as an integer, use %f not %i, also don't forget to reset it back to 0 somewhere.
__________________
asherkin is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 04-21-2019 , 16:56   Re: Getting amount of damage to entity
Reply With Quote #3

The plugin is fine, everything is set. There was only a problem with that. Thank you.

Solved
PHP Code:

    
if (attacker) {
        
int idamage RoundToFloor(damage);
        
Damage[attacker] += idamage;
    } 

Last edited by farawayf; 04-21-2019 at 16:58.
farawayf is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 04-21-2019 , 17:05   Re: Getting amount of damage to entity
Reply With Quote #4

You only assign damage to the attacker with zero connection to the damaged entity.

Use this:

float Damage[MAXPLAYERS+1][4096]

The first size is player index and the second is the entity that was damaged
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 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 23:33.


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