Raised This Month: $ Target: $400
 0% 

Check if Attack has recieved damage from Victim


Post New Thread Reply   
 
Thread Tools Display Modes
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-12-2022 , 05:20   Re: Check if Attack has recieved damage from Victim
Reply With Quote #11

Here you go thats how to properly do it....


PHP Code:
#define IsPlayer(%1) (1 <= %1 <= MAX_PLAYERS)

enum DAMAGE_PARAMS
{
    
Float:DAMAGE_AMOUNT,
    
Float:DAMAGE_TIME
}

new 
g_aDamageData[MAX_PLAYERS+1][MAX_PLAYERS+1][DAMAGE_PARAMS]

public @
PlayerTakeDamage_Post__int_Victim__int_Inflictor__int_AttackerFloat:__float_Damage__int_DamageBits 
{
    if(
IsPlayer(__int_Attacker))
    {
        
g_aDamageData[__int_Victim][__int_Attacker][DAMAGE_AMOUNT] += __float_Damage;
        
g_aDamageData[__int_Victim][__int_Attacker][DAMAGE_TIME] = get_gametime();
    }

    static 
iplayers[32], pnumplayer;
    
get_players(playerspnum);

    for(
0pnumi++)
    {
        
player players];

        if ( 
g_aDamageData[player][__int_Victim][DAMAGE_TIME] > 0.0 && floatabs(g_aDamageData[__int_Victim][player][DAMAGE_TIME] - g_aDamageData[player][__int_Victim][DAMAGE_TIME]) <= 1.0 )
        {
            
PlayersExchangeAttacks(__int_Victimplayerg_aDamageData[__int_Victim][player][DAMAGE_AMOUNT], g_aDamageData[player][__int_Victim][DAMAGE_AMOUNT]);
        }
    }
}

PlayersExchangeAttacks(iPlayerOneiPlayerTwoFloat:fDealtDamage_PlayerOneFloat:fDealtDamage_PlayerTwo)
{
    
// Make sure to reset players time fire exchange to prevent calling it for them multiple times...
    
g_aDamageData[iPlayerOne][iPlayerTwo][DAMAGE_TIME] = 0.0;
    
g_aDamageData[iPlayerTwo][iPlayerOne][DAMAGE_TIME] = 0.0;
    
// Both players attacked each other in less  than 1 second...

__________________
@Jailbreak Main Mod v2.6.6 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 08-12-2022 at 05:53.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
MrPickles
Member
Join Date: Aug 2022
Location: Colombia
Old 08-12-2022 , 15:50   Re: Check if Attack has recieved damage from Victim
Reply With Quote #12

Quote:
Originally Posted by Natsheh View Post
Here you go thats how to properly do it....


PHP Code:
#define IsPlayer(%1) (1 <= %1 <= MAX_PLAYERS)

enum DAMAGE_PARAMS
{
    
Float:DAMAGE_AMOUNT,
    
Float:DAMAGE_TIME
}

new 
g_aDamageData[MAX_PLAYERS+1][MAX_PLAYERS+1][DAMAGE_PARAMS]

public @
PlayerTakeDamage_Post__int_Victim__int_Inflictor__int_AttackerFloat:__float_Damage__int_DamageBits 
{
    if(
IsPlayer(__int_Attacker))
    {
        
g_aDamageData[__int_Victim][__int_Attacker][DAMAGE_AMOUNT] += __float_Damage;
        
g_aDamageData[__int_Victim][__int_Attacker][DAMAGE_TIME] = get_gametime();
    }

    static 
iplayers[32], pnumplayer;
    
get_players(playerspnum);

    for(
0pnumi++)
    {
        
player players];

        if ( 
g_aDamageData[player][__int_Victim][DAMAGE_TIME] > 0.0 && floatabs(g_aDamageData[__int_Victim][player][DAMAGE_TIME] - g_aDamageData[player][__int_Victim][DAMAGE_TIME]) <= 1.0 )
        {
            
PlayersExchangeAttacks(__int_Victimplayerg_aDamageData[__int_Victim][player][DAMAGE_AMOUNT], g_aDamageData[player][__int_Victim][DAMAGE_AMOUNT]);
        }
    }
}

PlayersExchangeAttacks(iPlayerOneiPlayerTwoFloat:fDealtDamage_PlayerOneFloat:fDealtDamage_PlayerTwo)
{
    
// Make sure to reset players time fire exchange to prevent calling it for them multiple times...
    
g_aDamageData[iPlayerOne][iPlayerTwo][DAMAGE_TIME] = 0.0;
    
g_aDamageData[iPlayerTwo][iPlayerOne][DAMAGE_TIME] = 0.0;
    
// Both players attacked each other in less  than 1 second...

mmm I'm not a fan of taking the index of all the players in a loop, thinking that forward is executed many times in a few seconds, but it's a start, I'll think of a way to make it more optimized
MrPickles is online now
Natsheh
Veteran Member
Join Date: Sep 2012
Old 08-13-2022 , 06:23   Re: Check if Attack has recieved damage from Victim
Reply With Quote #13

There is no worries calling a players loop inside player takedamage forward, and the code couldn't be optimize more than that, otherwise you will start creating some bugs.
__________________
@Jailbreak Main Mod v2.6.6 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
MrPickles
Member
Join Date: Aug 2022
Location: Colombia
Old 08-13-2022 , 16:09   Re: Check if Attack has recieved damage from Victim
Reply With Quote #14

Quote:
Originally Posted by Natsheh View Post
There is no worries calling a players loop inside player takedamage forward, and the code couldn't be optimize more than that, otherwise you will start creating some bugs.
there will always be a better way
MrPickles is online now
wilian159
Member
Join Date: Dec 2013
Old 08-13-2022 , 20:54   Re: Check if Attack has recieved damage from Victim
Reply With Quote #15

I don't answer this guy anymore
__________________
Hmm, nice....... www.addonscs.com
wilian159 is offline
MrPickles
Member
Join Date: Aug 2022
Location: Colombia
Old 08-15-2022 , 02:00   Re: Check if Attack has recieved damage from Victim
Reply With Quote #16

Quote:
Originally Posted by wilian159 View Post
I don't answer this guy anymore
Quote:
Originally Posted by MrPickles View Post
???????????? what are u talking about?? i think u dont understand( the example is very clear )

pd: if u dont understand dont post nonsense to gain posts and dont try to reply cause i will not read u
I already told you, do not bother me and do not try to win useless posts (no offense)
MrPickles is online now
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 15:33.


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