View Single Post
Author Message
Ark_Procession
Senior Member
Join Date: Jun 2020
Location: Argentina
Old 03-01-2022 , 22:04   (Req)How to make this plugin only apply to human players
Reply With Quote #1

Can someone add the code for this plugin so it only applies to human players?

HTML Code:
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <fun>

#define PLUGIN "True Armor"
#define VERSION "1.1a"
#define AUTHOR "Soccdoodcss"

new pOn, pPerc

public plugin_init() {
	register_plugin(PLUGIN, VERSION, AUTHOR)
	RegisterHam(Ham_TakeDamage, "player", "beforeDamage")
	RegisterHam(Ham_Spawn, "player", "onSpawn")
	
	pOn = register_cvar("ta_on", "1.0")
	pPerc = register_cvar("ta_perc", "1.0")
	register_cvar(PLUGIN, AUTHOR, FCVAR_SERVER|FCVAR_SPONLY)
}

public onSpawn(id)
{
	if(get_pcvar_num(pOn))
	{
		set_hudmessage(15, 15, 15, -1.0, 0.0, 0, 6.0, 12.0, 0.1, 0.2, 4)
		show_hudmessage(id, "True Armor^nDepletes Armor Before Health")
	}
}

public beforeDamage(this, id, attacker, Float:damage, damagebits)
{
	if(get_pcvar_num(pOn))
	{
		passDamage(this, id, attacker, Float:damage, damagebits)
		return HAM_SUPERCEDE
	}
	return HAM_IGNORED
}

public passDamage(this, id, attacker, Float:damage, damagebits)
{
    new Float:armor = float(get_user_armor(this))
    if(armor>0)
    {
        new Float:new_armor = armor - (damage / get_pcvar_float(pPerc))
        if(new_armor<0)
        {
            set_user_armor(this, 0)
            
            ExecuteHam(Ham_TakeDamage, this, id, attacker, (-new_armor)*get_pcvar_float(pPerc), damagebits);
        }
        
        else
            set_user_armor(this, floatround(new_armor))
    }
    else
        ExecuteHam(Ham_TakeDamage, this, id, attacker, damage, damagebits);
    
}
Ark_Procession is offline