damage feed improvements

This commit is contained in:
Lorenc Pekaj 2018-10-13 23:21:05 +11:00
parent 812e0b2397
commit 763689448f

View File

@ -10,7 +10,6 @@
/* ** Macros ** */ /* ** Macros ** */
#define IsDamageFeedActive(%0) ( IsPlayerSettingToggled( %0, SETTING_HITMARKER ) ) #define IsDamageFeedActive(%0) ( IsPlayerSettingToggled( %0, SETTING_HITMARKER ) )
#define IsPlayerHit(%0) ( p_GotHit{%0} )
/* ** Definitions ** */ /* ** Definitions ** */
#define MAX_FEED_HEIGHT ( 5 ) #define MAX_FEED_HEIGHT ( 5 )
@ -43,20 +42,19 @@ new
; ;
static stock static stock
g_damageGiven [ MAX_PLAYERS ][ MAX_FEED_HEIGHT ][ E_DAMAGE_FEED ], g_damageGiven [ MAX_PLAYERS ] [ MAX_FEED_HEIGHT ] [ E_DAMAGE_FEED ],
g_damageTaken [ MAX_PLAYERS ][ MAX_FEED_HEIGHT ][ E_DAMAGE_FEED ], g_damageTaken [ MAX_PLAYERS ] [ MAX_FEED_HEIGHT ] [ E_DAMAGE_FEED ],
Text3D: g_BulletLabel [ MAX_PLAYERS ], //Text3D: g_BulletLabel [ MAX_PLAYERS ],
g_BulletTimer [ MAX_PLAYERS ], //g_BulletTimer [ MAX_PLAYERS ],
p_PlayerDamageObject [ MAX_PLAYERS ],
bool: p_GotHit [ MAX_PLAYERS char ], bool: p_GotHit [ MAX_PLAYERS char ],
PlayerText: g_damageFeedTakenTD [ MAX_PLAYERS ] = { PlayerText: INVALID_TEXT_DRAW, ... }, PlayerText: g_damageFeedTakenTD [ MAX_PLAYERS ] = { PlayerText: INVALID_TEXT_DRAW, ... },
PlayerText: g_damageFeedGivenTD [ MAX_PLAYERS ] = { PlayerText: INVALID_TEXT_DRAW, ... }, PlayerText: g_damageFeedGivenTD [ MAX_PLAYERS ] = { PlayerText: INVALID_TEXT_DRAW, ... },
//PlayerText: p_DamageTD [ MAX_PLAYERS ] = { PlayerText: INVALID_TEXT_DRAW, ... }, //PlayerText: p_DamageTD [ MAX_PLAYERS ] = { PlayerText: INVALID_TEXT_DRAW, ... },
g_HitmarkerSounds [ ][ E_HITMARKER_SOUND ] = g_HitmarkerSounds [ ] [ E_HITMARKER_SOUND ] =
{ {
{ "Bell Ding", 17802 }, { "Soft Beep", 5205 }, { "Low Blip", 1138 }, { "Med Blip", 1137 }, { "Bell Ding", 17802 }, { "Soft Beep", 5205 }, { "Low Blip", 1138 }, { "Med Blip", 1137 },
{ "High Blip", 1139 }, { "Bling", 5201 } { "High Blip", 1139 }, { "Bling", 5201 }
@ -70,8 +68,8 @@ static stock
hook OnPlayerConnect( playerid ) hook OnPlayerConnect( playerid )
{ {
for( new x = 0; x < sizeof( g_damageGiven[ ] ); x ++) { for( new x = 0; x < sizeof( g_damageGiven[ ] ); x ++) {
g_damageGiven[ playerid ][ x ][ E_TICK ] = 0; g_damageGiven[ playerid ] [ x ] [ E_TICK ] = 0;
g_damageTaken[ playerid ][ x ][ E_TICK ] = 0; g_damageTaken[ playerid ] [ x ] [ E_TICK ] = 0;
} }
p_lastFeedUpdate[ playerid ] = GetTickCount( ); p_lastFeedUpdate[ playerid ] = GetTickCount( );
@ -110,10 +108,9 @@ hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
} }
/* ** Functions ** */ /* ** Functions ** */
function OnHideBulletLabel( playerid ) function DamageFeed_HideBulletLabel( labelid )
{ {
DestroyDynamic3DTextLabel( g_BulletLabel[ playerid ] ); DestroyDynamic3DTextLabel( Text3D: labelid );
KillTimer( g_BulletTimer[ playerid ] ); g_BulletTimer[ playerid ] = -1;
return 1; return 1;
} }
@ -125,34 +122,31 @@ public OnPlayerTakenDamage( playerid, issuerid, Float: amount, weaponid, bodypar
static Float: fromX, Float: fromY, Float: fromZ; static Float: fromX, Float: fromY, Float: fromZ;
static Float: toX, Float: toY, Float: toZ; static Float: toX, Float: toY, Float: toZ;
if ( IsValidDynamic3DTextLabel( g_BulletLabel[ issuerid ] ) )
{
DestroyDynamic3DTextLabel( g_BulletLabel[ issuerid ] );
KillTimer( g_BulletTimer[ issuerid ] );
g_BulletTimer[ issuerid ] = -1;
}
GetPlayerLastShotVectors( issuerid, fromX, fromY, fromZ, toX, toY, toZ ); GetPlayerLastShotVectors( issuerid, fromX, fromY, fromZ, toX, toY, toZ );
g_BulletLabel[ issuerid ] = CreateDynamic3DTextLabel( sprintf( "%.0f", amount ), 0xDD202088, toX, toY, toZ, 100.0, playerid, INVALID_VEHICLE_ID, 0, GetPlayerVirtualWorld( playerid ), GetPlayerInterior( playerid ) ); new
Streamer_Update( issuerid, STREAMER_TYPE_3D_TEXT_LABEL ); Text3D: bullet_label = CreateDynamic3DTextLabel( sprintf( "%.0f", amount ), 0xFFFFFF80, toX, toY, toZ, 100.0, .interiorid = GetPlayerVirtualWorld( playerid ), .worldid = GetPlayerInterior( playerid ), .testlos = 1 );
g_BulletTimer[ issuerid ] = SetTimerEx( "OnHideBulletLabel", 3000, false, "d", issuerid ); if ( IsValidDynamic3DTextLabel( bullet_label ) )
{
Streamer_Update( issuerid, STREAMER_TYPE_3D_TEXT_LABEL );
Streamer_Update( playerid, STREAMER_TYPE_3D_TEXT_LABEL );
SetTimerEx( "DamageFeed_HideBulletLabel", 1250, false, "d", _: bullet_label );
}
/* ** Armour and Health Object Damage ** */ /* ** Armour and Health Object Damage ** */
if ( !IsPlayerHit( playerid ) ) if ( ! p_GotHit{ playerid } )
{ {
static static
Float: fArmour; Float: armour;
if ( GetPlayerArmour( playerid, fArmour ) ) if ( GetPlayerArmour( playerid, armour ) )
{ {
SetPlayerAttachedObject(playerid, 4, fArmour == 0 ? ( 1240 ) : ( 1242 ), 1, 1.400000, -0.004999, 0.034999, 4.499999, 83.500030, -3.799998, 1.000000, 1.000000, 1.026999); SetPlayerAttachedObject( playerid, 4, armour - amount <= 0.0 ? ( 1240 ) : ( 1242 ), 1, 1.400000, -0.004999, 0.034999, 4.499999, 83.500030, -3.799998, 1.000000, 1.000000, 1.026999 );
SetTimerEx( "HideDamageObject", 1000, false, "d", playerid ); SetTimerEx( "HideDamageObject", 1000, false, "d", playerid );
Streamer_Update(playerid, STREAMER_TYPE_OBJECT ); Streamer_Update( playerid, STREAMER_TYPE_OBJECT );
p_GotHit{ playerid } = true; p_GotHit{ playerid } = true;
} }
} }
@ -179,7 +173,6 @@ function HideDamageObject( playerid )
if( IsPlayerAttachedObjectSlotUsed( playerid, 4 ) ) if( IsPlayerAttachedObjectSlotUsed( playerid, 4 ) )
RemovePlayerAttachedObject( playerid, 4 ); RemovePlayerAttachedObject( playerid, 4 );
DestroyObject( p_PlayerDamageObject[ playerid ] );
p_GotHit{ playerid } = false; p_GotHit{ playerid } = false;
return 1; return 1;
} }
@ -283,45 +276,45 @@ stock UpdateDamageFeed( playerid, bool: modified = false )
for( new givenid = 0; givenid < sizeof( g_damageGiven[ ] ) - 1; givenid ++) for( new givenid = 0; givenid < sizeof( g_damageGiven[ ] ) - 1; givenid ++)
{ {
if ( !g_damageGiven[ playerid ][ givenid ][ E_TICK ] ) { if ( !g_damageGiven[ playerid ] [ givenid ] [ E_TICK ] ) {
break; break;
} }
if ( szTick - g_damageGiven[ playerid ][ givenid ][ E_TICK ] >= HIDE_FEED_DELAY ) if ( szTick - g_damageGiven[ playerid ] [ givenid ] [ E_TICK ] >= HIDE_FEED_DELAY )
{ {
modified = true; modified = true;
for( new j = givenid; j < sizeof( g_damageGiven[ ] ) - 1; j++ ) { for( new j = givenid; j < sizeof( g_damageGiven[ ] ) - 1; j++ ) {
g_damageGiven[ playerid ][ j ][ E_TICK ] = 0; g_damageGiven[ playerid ] [ j ] [ E_TICK ] = 0;
} }
break; break;
} }
if ( g_damageGiven[ playerid ][ givenid ][ E_TICK ] < lowest_tick ) { if ( g_damageGiven[ playerid ] [ givenid ] [ E_TICK ] < lowest_tick ) {
lowest_tick = g_damageGiven[ playerid ][ givenid ][ E_TICK ]; lowest_tick = g_damageGiven[ playerid ] [ givenid ] [ E_TICK ];
} }
} }
for( new takenid = 0; takenid < sizeof( g_damageTaken[ ] ) - 1; takenid ++) for( new takenid = 0; takenid < sizeof( g_damageTaken[ ] ) - 1; takenid ++)
{ {
if ( !g_damageTaken[ playerid ][ takenid ][ E_TICK ] ) { if ( !g_damageTaken[ playerid ] [ takenid ] [ E_TICK ] ) {
break; break;
} }
if ( szTick - g_damageTaken[ playerid ][ takenid ][ E_TICK ] >= HIDE_FEED_DELAY ) if ( szTick - g_damageTaken[ playerid ] [ takenid ] [ E_TICK ] >= HIDE_FEED_DELAY )
{ {
modified = true; modified = true;
for( new j = takenid; j < sizeof( g_damageTaken[ ] ) - 1; j++ ) { for( new j = takenid; j < sizeof( g_damageTaken[ ] ) - 1; j++ ) {
g_damageTaken[ playerid ][ j ][ E_TICK ] = 0; g_damageTaken[ playerid ] [ j ] [ E_TICK ] = 0;
} }
break; break;
} }
if ( g_damageTaken[ playerid ][ takenid ][ E_TICK ] < lowest_tick ) { if ( g_damageTaken[ playerid ] [ takenid ] [ E_TICK ] < lowest_tick ) {
lowest_tick = g_damageTaken[ playerid ][ takenid ][ E_TICK ]; lowest_tick = g_damageTaken[ playerid ] [ takenid ] [ E_TICK ];
} }
} }
@ -363,25 +356,25 @@ stock UpdateDamageFeedLabel( playerid )
for( new givenid = 0; givenid < sizeof( g_damageGiven[ ] ) - 1; givenid ++) for( new givenid = 0; givenid < sizeof( g_damageGiven[ ] ) - 1; givenid ++)
{ {
if ( !g_damageGiven[ playerid ][ givenid ][ E_TICK ] ) if ( !g_damageGiven[ playerid ] [ givenid ] [ E_TICK ] )
break; break;
new szWeapon[ 32 ]; new szWeapon[ 32 ];
if ( g_damageGiven[ playerid ][ givenid ][ E_WEAPON ] == -1 ) { if ( g_damageGiven[ playerid ] [ givenid ] [ E_WEAPON ] == -1 ) {
szWeapon = "Multiple"; szWeapon = "Multiple";
} }
else { else {
GetWeaponName( g_damageGiven[ playerid ][ givenid ][ E_WEAPON ], szWeapon, sizeof( szWeapon ) ); GetWeaponName( g_damageGiven[ playerid ] [ givenid ] [ E_WEAPON ], szWeapon, sizeof( szWeapon ) );
} }
if ( g_damageGiven[ playerid ][ givenid ][ E_ISSUER ] == INVALID_PLAYER_ID ) if ( g_damageGiven[ playerid ] [ givenid ] [ E_ISSUER ] == INVALID_PLAYER_ID )
{ {
format( szLabel, sizeof( szLabel ), "%s%s ~w~+%.2f~n~", szLabel, szWeapon, g_damageGiven[ playerid ][ givenid ][ E_AMOUNT ] ); format( szLabel, sizeof( szLabel ), "%s%s +%.2f~n~", szLabel, szWeapon, g_damageGiven[ playerid ] [ givenid ] [ E_AMOUNT ] );
} }
else else
{ {
format( szLabel, sizeof( szLabel ), "%s%s - %s ~w~+%.2f~n~", szLabel, szWeapon, g_damageGiven[ playerid ][ givenid ][ E_NAME ], g_damageGiven[ playerid ][ givenid ][ E_AMOUNT ] ); format( szLabel, sizeof( szLabel ), "%s%s - %s +%.2f~n~", szLabel, szWeapon, g_damageGiven[ playerid ] [ givenid ] [ E_NAME ], g_damageGiven[ playerid ] [ givenid ] [ E_AMOUNT ] );
} }
} }
@ -405,25 +398,25 @@ stock UpdateDamageFeedLabel( playerid )
for( new takenid = 0; takenid < sizeof( g_damageTaken[ ] ) - 1; takenid ++) for( new takenid = 0; takenid < sizeof( g_damageTaken[ ] ) - 1; takenid ++)
{ {
if ( !g_damageTaken[ playerid ][ takenid ][ E_TICK ] ) if ( !g_damageTaken[ playerid ] [ takenid ] [ E_TICK ] )
break; break;
new szWeapon[ 32 ]; new szWeapon[ 32 ];
if ( g_damageTaken[ playerid ][ takenid ][ E_WEAPON ] == -1 ) { if ( g_damageTaken[ playerid ] [ takenid ] [ E_WEAPON ] == -1 ) {
szWeapon = "Multiple"; szWeapon = "Multiple";
} }
else { else {
GetWeaponName( g_damageTaken[ playerid ][ takenid ][ E_WEAPON ], szWeapon, sizeof( szWeapon ) ); GetWeaponName( g_damageTaken[ playerid ] [ takenid ] [ E_WEAPON ], szWeapon, sizeof( szWeapon ) );
} }
if ( g_damageTaken[ playerid ][ takenid ][ E_ISSUER ] == INVALID_PLAYER_ID ) if ( g_damageTaken[ playerid ] [ takenid ] [ E_ISSUER ] == INVALID_PLAYER_ID )
{ {
format( szLabel, sizeof( szLabel ), "%s%s ~w~-%.2f~n~", szLabel, szWeapon, g_damageTaken[ playerid ][ takenid ][ E_AMOUNT ] ); format( szLabel, sizeof( szLabel ), "%s%s -%.2f~n~", szLabel, szWeapon, g_damageTaken[ playerid ] [ takenid ] [ E_AMOUNT ] );
} }
else else
{ {
format( szLabel, sizeof( szLabel ), "%s%s - %s ~w~-%.2f~n~", szLabel, szWeapon, g_damageTaken[ playerid ][ takenid ][ E_NAME ], g_damageTaken[ playerid ][ takenid ][ E_AMOUNT ] ); format( szLabel, sizeof( szLabel ), "%s%s - %s -%.2f~n~", szLabel, szWeapon, g_damageTaken[ playerid ] [ takenid ] [ E_NAME ], g_damageTaken[ playerid ] [ takenid ] [ E_AMOUNT ] );
} }
} }
@ -444,17 +437,17 @@ stock UpdateDamageFeedLabel( playerid )
} }
} }
stock RemoveDamageHit( array[ MAX_FEED_HEIGHT ][ E_DAMAGE_FEED ], index ) stock RemoveDamageHit( array[ MAX_FEED_HEIGHT ] [ E_DAMAGE_FEED ], index )
{ {
for( new i = 0; i < MAX_FEED_HEIGHT; i ++ ) for( new i = 0; i < MAX_FEED_HEIGHT; i ++ )
{ {
if ( i >= index ) { if ( i >= index ) {
array[ i ][ E_TICK ] = 0; array[ i ] [ E_TICK ] = 0;
} }
} }
} }
stock AddDamageHit( array[ MAX_FEED_HEIGHT ][ E_DAMAGE_FEED ], playerid, issuerid, Float: amount, weapon ) stock AddDamageHit( array[ MAX_FEED_HEIGHT ] [ E_DAMAGE_FEED ], playerid, issuerid, Float: amount, weapon )
{ {
if ( ! IsDamageFeedActive( playerid ) ) { if ( ! IsDamageFeedActive( playerid ) ) {
return; return;
@ -466,18 +459,18 @@ stock AddDamageHit( array[ MAX_FEED_HEIGHT ][ E_DAMAGE_FEED ], playerid, issueri
for( new i = 0; i < sizeof( array ); i ++ ) for( new i = 0; i < sizeof( array ); i ++ )
{ {
if ( ! array[ i ][ E_TICK ] ) { if ( ! array[ i ] [ E_TICK ] ) {
break; break;
} }
if ( szTick - array[ i ][ E_TICK ] >= HIDE_FEED_DELAY ) { if ( szTick - array[ i ] [ E_TICK ] >= HIDE_FEED_DELAY ) {
RemoveDamageHit( array, i ); RemoveDamageHit( array, i );
break; break;
} }
if ( array[ i ][ E_ISSUER ] == issuerid ) if ( array[ i ] [ E_ISSUER ] == issuerid )
{ {
amount += array[ i ][ E_AMOUNT ]; amount += array[ i ] [ E_AMOUNT ];
wID = i; wID = i;
break; break;
} }
@ -493,12 +486,12 @@ stock AddDamageHit( array[ MAX_FEED_HEIGHT ][ E_DAMAGE_FEED ], playerid, issueri
} }
} }
array[ wID ][ E_TICK ] = szTick; array[ wID ] [ E_TICK ] = szTick;
array[ wID ][ E_AMOUNT ] = amount; array[ wID ] [ E_AMOUNT ] = amount;
array[ wID ][ E_ISSUER ] = issuerid; array[ wID ] [ E_ISSUER ] = issuerid;
array[ wID ][ E_WEAPON ] = weapon; array[ wID ] [ E_WEAPON ] = weapon;
GetPlayerName( issuerid, array[ wID ][ E_NAME ] , MAX_PLAYER_NAME ); GetPlayerName( issuerid, array[ wID ] [ E_NAME ] , MAX_PLAYER_NAME );
UpdateDamageFeed( playerid, true ); UpdateDamageFeed( playerid, true );
} }