AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Disable blood animation. (https://forums.alliedmods.net/showthread.php?t=334389)

Napoleon_be 09-19-2021 17:54

Disable blood animation.
 
Hi there

I'm trying to help someone out with the following. I've got this code, but it's only working on the first hit. Also, the animation isn't removed, the color just turns black.

PHP Code:

public PreDisableBlood(id)
{
    if(
g_bUnderstabbed[id])
    {
        
client_print(0print_chat"Disable blood animation");
        
SetHamReturnInteger(-1);
        
g_bUnderstabbed[id] = false;
        return 
HAM_HANDLED;
    }
    return 
HAM_SUPERCEDE;


I'll just leave the entire code for any one who needs more information.

PHP Code:

/* Sublime AMXX Editor v2.2 */

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <engine>
#include <hamsandwich>

#define PLUGIN  "Anti UnderStab"
#define VERSION "1.0"
#define AUTHOR  "NapoleoN#"

#if !defined DMG_GRENADE
        #define DMG_GRENADE ( 1 << 24 )
#endif

#if !defined MAX_PLAYERS
        
const MAX_PLAYERS 32;
#endif

#define g_iIsPlayer(%0) (1 <= (%0) <= MAX_PLAYERS)

new bool:g_bUnderstabbed[MAX_PLAYERS 1];

new 
g_pYOffset;

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR);

    
RegisterHam(Ham_TakeDamage"player""PreTakeDamage");
    
RegisterHam(Ham_BloodColor"player""PreDisableBlood");

    
g_pYOffset register_cvar("aus_offset""20");
}

public 
PreTakeDamage(iVictimiInflictoriAttackerFloat:fDamageiDmgBits)
{
    if(!
is_user_alive(iVictim) || !is_user_alive(iAttacker) || !g_iIsPlayer(iAttacker) || !g_iIsPlayer(iVictim) || iDmgBits    DMG_GRENADE)
    {
        return 
HAM_IGNORED;
    }

    if(
cs_get_user_weapon(iAttacker) == CSW_KNIFE && cs_get_user_team(iAttacker) == CS_TEAM_CT && cs_get_user_team(iVictim) == CS_TEAM_T)
    {
        new 
iAttOrigin[3];
        new 
iVicOrigin[3];

        
get_user_origin(iAttackeriAttOrigin);
        
get_user_origin(iVictimiVicOrigin);

        
iAttOrigin[2] += get_pcvar_num(g_pYOffset);

        if(
iVicOrigin[2] > iAttOrigin[2])
        {
            
g_bUnderstabbed[iVictim] = true;
            return 
HAM_SUPERCEDE;
        }
    }
    return 
HAM_IGNORED;
}

public 
PreDisableBlood(id)
{
    if(
g_bUnderstabbed[id])
    {
        
client_print(0print_chat"Disable blood animation");
        
SetHamReturnInteger(-1);
        
g_bUnderstabbed[id] = false;
        return 
HAM_HANDLED;
    }
    return 
HAM_SUPERCEDE;



Celena Luna 09-20-2021 04:50

Re: Disable blood animation.
 
Maybe this will help

PHP Code:

#include <amxmodx>

]public plugin_init() {
    
register_plugin("No Blood" ,"0.1""ConnorMcLeod")
    
register_message(SVC_TEMPENTITY"blood_message")
}

public 
blood_message() {
    if(!
get_pcvar_num(noblood))
        return 
PLUGIN_CONTINUE

    
static arg1 arg1 get_msg_arg_int(1)

    if(
arg1 == TE_BLOODSPRITE || arg1 == TE_BLOODSTREAM || arg1 == TE_BLOOD)
        return 
PLUGIN_HANDLED

    
return PLUGIN_CONTINUE


Not sure what you mean by blood animation though.

Shadows Adi 09-20-2021 08:08

Re: Disable blood animation.
 
You switched the return values:

Code:
public PreDisableBlood(id) {     if(g_bUnderstabbed[id])     {         client_print(0, print_chat, "Disable blood animation");         SetHamReturnInteger(-1);         g_bUnderstabbed[id] = false;         return HAM_HANDLED;     }     return HAM_SUPERCEDE; }

Code:
public PreDisableBlood(id) {     if(g_bUnderstabbed[id])     {         client_print(0, print_chat, "Disable blood animation");         SetHamReturnInteger(-1);         g_bUnderstabbed[id] = false;         return HAM_SUPERCEDE;     }     return HAM_IGNORE; }

Napoleon_be 09-20-2021 19:38

Re: Disable blood animation.
 
Quote:

Originally Posted by Shadows Adi (Post 2758286)
You switched the return values:

Code:
public PreDisableBlood(id) {     if(g_bUnderstabbed[id])     {         client_print(0, print_chat, "Disable blood animation");         SetHamReturnInteger(-1);         g_bUnderstabbed[id] = false;         return HAM_HANDLED;     }     return HAM_SUPERCEDE; }

Code:
public PreDisableBlood(id) {     if(g_bUnderstabbed[id])     {         client_print(0, print_chat, "Disable blood animation");         SetHamReturnInteger(-1);         g_bUnderstabbed[id] = false;         return HAM_SUPERCEDE;     }     return HAM_IGNORE; }

Thanks, i'll try this tomorrow. I misread some things on the wiki.

Also, i realized this part:
Code:

Disabling Hooks
Similar to how FakeMeta allows for unregistering of hooks with unregister_forward(), HamSandwich will allow you to disable and enable hooks whenever you want.

The RegisterHam() function will return a handle (tagged with HamHook). You can then make subsequent calls to DisableHamForward() and EnableHamForward() with the handle to stop it from forwarding, or enable its forwards again.

Would this be an option to use? The basic idea is to disable the blood animation whenever damage has been ignored by the same plugin. If so, could someone provide me an example of how i could make this work? In my opinion, this would be the right call.

Shadows Adi 09-21-2021 07:31

Re: Disable blood animation.
 
Quote:

Originally Posted by Napoleon_be (Post 2758338)
Also, i realized this part:
Code:

Disabling Hooks
Similar to how FakeMeta allows for unregistering of hooks with unregister_forward(), HamSandwich will allow you to disable and enable hooks whenever you want.

The RegisterHam() function will return a handle (tagged with HamHook). You can then make subsequent calls to DisableHamForward() and EnableHamForward() with the handle to stop it from forwarding, or enable its forwards again.

Would this be an option to use? The basic idea is to disable the blood animation whenever damage has been ignored by the same plugin. If so, could someone provide me an example of how i could make this work? In my opinion, this would be the right call.

No, disabling and enabling the hook, just stops the hook from calling.
Example:
You hook Ham_Spawn with RegisterHam. In return, you get a unique index for that hook. You can enable or disable that hook if a boolean is true or false.
If the boolean is true, you could enable the hook and at next player spawn it will be called, otherwise, you could disable the hook and at next player spawn it won't be called.

P.S.: It won't stop the function Ham_Spawn from being called, only your hook.

If you didn't understood, I will leave a code example later.

DJEarthQuake 09-21-2021 10:12

Re: Disable blood animation.
 
Stopping blood on individual stab basis but leaving it on otherwise for all other 'hits'?

PHP Code:

#!/bin/sh
echo "violence_ablood 0;violence_agibs 0;violence_hblood 0;violence_hgibs 0;rem spinx was here!" >> server.cfg 

When I saw title I immediately was wondering why the CVARs are not being utilized otherwise.


All times are GMT -4. The time now is 11:40.

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