Damage Indicator

allhellnoallhellno Senior
edited May 2015 in Scripting
Recently finished working on this script here to get it working with PVKii
Not very accurate I assume but seems to work well on my server.
Requires sourcemod

#include <sourcemod>
#include <clientprefs>

public Plugin:myinfo = {
	name = "Damage Indicator",
	author = "",
	description = "Damage and hit indicator",
	version = "1.0.",
	url = "http://www.pvkii.com/"
};

bool:block_timer[MAXPLAYERS + 1] = {false,...},
player_damage[MAXPLAYERS + 1],
player_old_health[MAXPLAYERS + 1],
String:DamageEventName[16];
new bool:FrameMod = true;

public OnPluginStart()
{
	HookEvent("player_hurt", Event_PlayerHurt_FrameMod, EventHookMode_Pre);
	FrameMod = true;
	HookEvent("player_spawn", Event_PlayerSpawn, EventHookMode_Post);
}

public OnClientConnected(client)
	block_timer[client] = false;

public Action:Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	block_timer[client] = false;
	
	return Plugin_Continue;
}

public Action:ShowDamage(Handle:timer, any:client)
{
	block_timer[client] = false;
	
	if (player_damage[client] <= 0 || !client || !IsClientInGame(client))
		return;

	PrintCenterText(client, "%i HP", player_damage[client]);
	player_damage[client] = 0;
}

CalcDamage(client, client_attacker, damage)
{
	if (client != 0)
	{
		if (client == client_attacker)
			return;
	}
	
	player_damage[client_attacker] += damage;
	
	if (block_timer[client_attacker])
		return;
	
	CreateTimer(0.01, ShowDamage, client_attacker);
	block_timer[client_attacker] = true;
}

public OnGameFrame()
{
	if (FrameMod)
	{
		for (new client = 1; client <= MaxClients; client++)
		{
			if (IsClientInGame(client))
			{
				player_old_health[client] = GetClientHealth(client);
			}
		}
	}
}

public Action:Event_PlayerHurt_FrameMod(Handle:event, const String:name[], bool:dontBroadcast)
{	
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	new client_attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
	new damage = player_old_health[client] - GetClientHealth(client);
	
	CalcDamage(client, client_attacker, damage);
	
	return Plugin_Continue;
}

public Action:Event_PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
{	
	new client_attacker = GetClientOfUserId(GetEventInt(event, "attacker")),
	client = GetClientOfUserId(GetEventInt(event, "userid")),
	damage = GetEventInt(event, DamageEventName);
	
	CalcDamage(client, client_attacker, damage);
	return Plugin_Continue;
}

public Action:Event_InfectedHurt(Handle:event, const String:name[], bool:dontBroadcast)
{	
	new client_attacker = GetClientOfUserId(GetEventInt(event, "attacker")),
	damage = GetEventInt(event, "amount");
	CalcDamage(0, client_attacker, damage);
	return Plugin_Continue;
}

Comments

  • FelisFelis Glitch Kitty PVKII Team
    edited May 2015
    This does not differ a lot from exvel's damage plugin that is used on most servers already. You could rewrite it to use PVKII's own damage events instead of the generic player_hurt since that seems to show incorrect damage.

    Also if you want to release a plugin, upload the compiled .smx too. Most server admins have no idea on how to compile scripts.
  • El NegroEl Negro The Genuinely Only Sane Person Guests
    edited 6:31AM
    Felis wrote:
    You could rewrite it to use PVKII's own damage events instead of the generic player_hurt since that seems to show incorrect damage.


    What are exactly PVKII's damage events? I'd like to..."Improve" this "Show Damage" script.
    I make mods.
    Your soul cannot be saved.
    Like my mods and think I deserve something? It's always money, you can pay me up on PayPal using this e-mail; TheSandhog@outlook.com
    Or just use this link; https://www.paypal.me/TheSandhog

  • FelisFelis Glitch Kitty PVKII Team
    edited July 2015
    El Negro wrote:

    What are exactly PVKII's damage events? I'd like to..."Improve" this "Show Damage" script.


    "player_bomb_explode" // Explosives.
    {
        "userid" "short"  // user ID of player who tossed it
        "victims" "string" // array of chars representing user IDs of players who were hit (if any)
        "weapon" "string" // explosive type (is weapon name like powderkeg)
        "damage" "float"  // How much total damage was done
    }
    
    "player_melee_swing" // Melee swing.
    {
        "userid" "short"  // user ID of player who swung
        "victims" "string" // array of chars representing user IDs of players who were hit (if any)
        "weapon" "string" // weapon that was swung
        "atkdir" "short"  // melee attack direction
        "damage" "float"  // how much damage was dealt total with the swing
        "hitper" "float"  // what percentage of the swing arc hit actual targets
    }
    
    "player_ranged_impact" // Ranged hit. This also is fired when a powderkeg or chest hits a player. The weapon will be thrownkeg or chest
    {
        "userid" "short"  // user ID of player who fired
        "victim" "short"  // entindex of entity that was hit (if any)
        "weapon" "string" // weapon that was fired
        "damage" "float"  // how much damage was dealt, if 0 obviously missed or blocked by shield if victim is set
        "headshot" "bool"  // headshot
    }
    
    "player_kick" // Someone kicked something.
    {
        "userid" "short"  // user ID of player who kicked
        "victim" "short"  // entindex of the ent that was hit, user ID if player.
        "damage" "float"  // how much damage was dealt
    }
    
Sign In or Register to comment.