Quote:
Originally Posted by BraveFox
I don't know why, but if you try to set the damage(damage = 50....) it does not working, I always use damage *= 50.. if I want instant kill.
|
This worked for me:
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#define PLUGIN_NAME "Set Damage"
#define PLUGIN_AUTHOR "Sgt. Gremulock"
#define PLUGIN_DESCRIPTION "Set the damage that you do with a command."
#define PLUGIN_VERSION "1.0.0"
#define PLUGIN_CONTACT "grem-co.com"
// Booleans
new bool:bDamageActive[MAXPLAYERS + 1];
// Variables
int iDamageAmount[MAXPLAYERS + 1];
Float:fDamageAmount[MAXPLAYERS + 1];
/* Functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
public Plugin myinfo =
{
name = PLUGIN_NAME,
author = PLUGIN_AUTHOR,
description = PLUGIN_DESCRIPTION,
version = PLUGIN_VERSION,
url = PLUGIN_CONTACT
};
public OnPluginStart()
{
RegAdminCmd("sm_damage", SetDamage, ADMFLAG_ROOT);
HookEvent("player_spawn", OnPlayerSpawn);
HookEvent("player_death", OnPlayerDeath);
LoadTranslations("common.phrases");
}
public Action OnPlayerSpawn(Event event, const char[] name, bool dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if (IsValidClient(client))
{
SDKHook(client, SDKHook_OnTakeDamage, OnTakeDamage);
}
}
public Action OnPlayerDeath(Event event, const char[] name, bool dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if (bDamageActive[client])
{
bDamageActive[client] = false;
}
}
public Action OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype)
{
if (IsValidClient(attacker))
{
if (bDamageActive[attacker])
{
damage = fDamageAmount[attacker];
return Plugin_Changed;
}
}
return Plugin_Continue;
}
/* Commands ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
public Action SetDamage(client, args)
{
char arg1[32];
GetCmdArg(1, arg1, sizeof(arg1));
iDamageAmount[client] = StringToInt(arg1);
if (IsValidClient(client))
{
if (args < 1)
{
ReplyToCommand(client, "[SM] Usage: sm_damage <amount>");
return Plugin_Handled;
}
if (args == 1)
{
if (iDamageAmount[client] == 0)
{
ReplyToCommand(client, "[SM] Custom damage disabled.");
bDamageActive[client] = false;
return Plugin_Handled;
}
else if (iDamageAmount[client] > 0)
{
ReplyToCommand(client, "[SM] Damage set to %i.", iDamageAmount[client]);
bDamageActive[client] = true;
fDamageAmount[client] = float(iDamageAmount[client]);
return Plugin_Handled;
}
}
else if (args == 2)
{
char arg2[32], name[MAX_NAME_LENGTH];
GetCmdArg(2, arg2, sizeof(arg2));
int target = FindTarget(client, arg2);
GetClientName(target, name, sizeof(name));
if (iDamageAmount[client] == 0)
{
ReplyToCommand(client, "[SM] Custom damage disabled for %s.", name);
bDamageActive[target] = false;
return Plugin_Handled;
}
else if (iDamageAmount[client] > 0)
{
ReplyToCommand(client, "[SM] Damage set to %i for %s.", iDamageAmount[client], name);
bDamageActive[target] = true;
fDamageAmount[target] = float(iDamageAmount[client]);
return Plugin_Handled;
}
}
}
return Plugin_Handled;
}
/* Stocks ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
stock bool IsValidClient(int client, bool bAllowBots = false, bool bAllowDead = true)
{
if (!(1 <= client <= MaxClients) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!bAllowDead && !IsPlayerAlive(client)))
{
return false;
}
return true;
}