Raised This Month: $12 Target: $400
 3% 

[TF2] SDKHooks_OnTakeDamage Script Not Working


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ThatKidWhoGames
Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
Old 09-01-2017 , 12:41   [TF2] SDKHooks_OnTakeDamage Script Not Working
Reply With Quote #1

Long story short, this script i'm coding isn't working.

PHP Code:
#include <sourcemod>
#include <sdkhooks>

#pragma semicolon 1

#define PLUGIN_VERSION "1.0.0"

new bool:bInfiniteDamage[MAXPLAYERS 1];

/* Functions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

public Plugin myinfo = {
    
name        "Infinite Damage",
    
author      "Sgt. Gremulock",
    
description "Instantly kills players on the first hit from any weapon with a command.",
    
version     PLUGIN_VERSION,
    
url         "grem-co.com"
};

public 
void OnPluginStart() {
    
RegCmds();
    
RegCvars();
}

RegCmds() {
    
RegAdminCmd("sm_idamage"Cmd_DamageADMFLAG_ROOT);
}

RegCvars() {
    
CreateConVar("sm_idamage_version"PLUGIN_VERSION"Infinite damage version."FCVAR_SPONLY || FCVAR_NOTIFY || FCVAR_DONTRECORD);
}

/* Commands ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

public Action Cmd_Damage(clientargs) {
    
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamage);
    if (
IsValidClient(client)) {
        if (!
bInfiniteDamage[client]) {
            
bInfiniteDamage[client] = true;
            
PrintToChat(client"[SM] You have enabled infinite damage.");
        } else {
            
bInfiniteDamage[client] = false;
            
PrintToChat(client"[SM] You have disabled infinite damage.");
        }
    }
    return 
Plugin_Handled;
}

/* Events ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

public Action OnTakeDamage(victim, &attacker, &inflictor, &Float:damage, &damagetype) {
    if (
IsValidClient(victim) && IsValidClient(attacker)) {
        if (
bInfiniteDamage[attacker]) {
            
damage 255.0;
            return 
Plugin_Changed;
        }
    }
    return 
Plugin_Continue;
}

/* Stocks ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

stock bool IsValidClient(int clientbool bAllowBots falsebool bAllowDead true) {
    if (!(
<= client <= MaxClients) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!bAllowDead && !IsPlayerAlive(client))) { 
        return 
false;
    }
    return 
true;

There is nothing in my error logs. Any help would be greatly appreciated!

EDIT: The command works and that but just the damage isn't modified.

Last edited by ThatKidWhoGames; 09-01-2017 at 12:42.
ThatKidWhoGames is offline
StealthGus
Junior Member
Join Date: Mar 2015
Old 09-01-2017 , 14:13   Re: [TF2] SDKHooks_OnTakeDamage Script Not Working
Reply With Quote #2

Any reason why you are mixing the old and new syntax together? I'm not positive but that could potentially be an issue..
StealthGus is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 09-01-2017 , 14:18   Re: [TF2] SDKHooks_OnTakeDamage Script Not Working
Reply With Quote #3

You're only hooking the damage of the players issuing the command, you should hook all clients on plugin start.
Mitchell is offline
ThatKidWhoGames
Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
Old 09-01-2017 , 15:20   Re: [TF2] SDKHooks_OnTakeDamage Script Not Working
Reply With Quote #4

Quote:
Originally Posted by StealthGus View Post
Any reason why you are mixing the old and new syntax together? I'm not positive but that could potentially be an issue..
I've been learning the new syntax and trying to get used to it.
Quote:
Originally Posted by Mitchell View Post
You're only hooking the damage of the players issuing the command, you should hook all clients on plugin start.
I will try that and get back to you, thanks guys.
ThatKidWhoGames is offline
BraveFox
AlliedModders Donor
Join Date: May 2015
Location: Israel
Old 09-03-2017 , 00:16   Re: [TF2] SDKHooks_OnTakeDamage Script Not Working
Reply With Quote #5

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.
__________________
Contact Me:
Steam: NoyB
Discord: Noy#9999
Taking Private Requests
BraveFox is offline
ThatKidWhoGames
Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
Old 09-03-2017 , 11:11   Re: [TF2] SDKHooks_OnTakeDamage Script Not Working
Reply With Quote #6

Quote:
Originally Posted by BraveFox View Post
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"SetDamageADMFLAG_ROOT);

    
HookEvent("player_spawn"OnPlayerSpawn);
    
HookEvent("player_death"OnPlayerDeath);

    
LoadTranslations("common.phrases");
}

public 
Action OnPlayerSpawn(Event event, const char[] namebool dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));

    if (
IsValidClient(client))
    {
        
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamage);
    }
}

public 
Action OnPlayerDeath(Event event, const char[] namebool 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(clientargs)
{
    
char arg1[32];
    
GetCmdArg(1arg1sizeof(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(2arg2sizeof(arg2));
            
int target FindTarget(clientarg2);
            
GetClientName(targetnamesizeof(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 clientbool bAllowBots falsebool bAllowDead true

    if (!(
<= client <= MaxClients) || !IsClientInGame(client) || (IsFakeClient(client) && !bAllowBots) || IsClientSourceTV(client) || IsClientReplay(client) || (!bAllowDead && !IsPlayerAlive(client))) 
    { 
        return 
false
    }
    return 
true;

ThatKidWhoGames is offline
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 06:33.


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