AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   hp problem (https://forums.alliedmods.net/showthread.php?t=320695)

generals 01-04-2020 11:01

hp problem
 
hi

I have no idea how to make for one player with variable damage reduced by 40%. Can u tell me how?

I want do this work when player switch weapon to knife (for css)

PHP Code:

#pragma semicolon 1

#include <sourcemod>
#include <sdkhooks>

new bool:adminabuser[MAXPLAYERS+1];

public 
OnClientPutInServer(client) {

    
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamagePre);
}

public 
Action:OnTakeDamagePre(victim, &attacker, &inflictor, &Float:damage, &damagetype) {

    if (
victim && victim <= MAXPLAYERS) {
        if (
adminabuser[victim]) {
            
damage -= damage 0.4// Reduce damage by 40%
            
return Plugin_Changed;
        }
    }



ThatOneGuy 01-04-2020 19:42

Re: Reduced Damage
 
If I understand correctly, you are saying you want the 40% reduction on knife only? Your code was close to what is needed. I assume it was copied from another plugin, given the admin abuser variable. Here you go:

PHP Code:

#include <sourcemod>
#include <sdkhooks>

public void OnClientPutInServer(int client)
{
    
SDKHook(clientSDKHook_OnTakeDamageEvent_OnTakeDamage);
}

public 
Action Event_OnTakeDamage(int victimint &attackerint &inflictorfloat &fDamageint &damagetypeint &weaponfloat a_fDmgForce[3], float a_fDmgPosition[3])
{
    
char sWeaponClass[20]; 
    
GetEntityClassname(inflictorsWeaponClasssizeof(sWeaponClass)); 
    if(
StrContains(sWeaponClass"knife"false) != -1)         //check if knife
    

        
fDamage *= 0.6;        //60% of original dmg (40% reduction)
        
return Plugin_Changed;
    }
    
    return 
Plugin_Continue;



generals 01-05-2020 08:36

Re: Reduced Damage
 
hi ..
Yes, you know exactly what I mean

compile error = i added :

PHP Code:

new bool:iWeapon

but damage don't reduced.. when i switch weapon to knife

Can't use this?

PHP Code:

public OnClientPutInServer(int client)
{
    
SDKHook(clientSDKHook_WeaponSwitchOnWeaponSwitch);
}
public 
Action:OnWeaponSwitch(clientweapon
{
    
char WeaponName[32];
    
GetEdictClassname(weaponWeaponNamesizeof(WeaponName));
    if(!
StrEqual(WeaponName"weapon_knife"))
    {
        
//Some Codes
    
}


Edit:

i removed bool and fix this line But it didn't work again :

PHP Code:

    GetEntityClassname(weaponsWeaponClasssizeof(sWeaponClass)); 

when ct attack to terror: terror not die

but when t attack to ct: ct die without hp reduction 40%

generals 01-07-2020 19:24

Re: Reduced Damage
 
hi again

when i change this code and add inflictor to this :

PHP Code:

GetEntityClassname(inflictorsWeaponClasssizeof(sWeaponClass)); 

And I'll delete this line :

PHP Code:

if(StrContains(sWeaponClass"knife"false) != -1)         //check if knife 

plugin working .. But can't detect the knife.. I think the bet is wrong

Someone can help? this plugin very important for me

ThatOneGuy 01-07-2020 21:15

Re: Reduced Damage
 
Recompile my updated post. The compile error you mention was a single word that needed changing. It should work just fine.

Side note: I apparently made a plugin that does similar to this and a bit more in the past:
https://forums.alliedmods.net/showthread.php?t=317685

Figure out what the 40% reduction is and set the following 4 variables accordingly:
HTML Code:

togknifedmg_reg_left        [left click knife]
togknifedmg_reg_right      [right click knife]
togknifedmg_back_left      [left click back stab]
togknifedmg_back_right      [right click back stab]

Moral of the story, consider doing a more thorough search of the forums prior to making requests.

generals 01-08-2020 03:56

Re: Reduced Damage
 
Brother, I think you don't understand me

I don't want to do less damage to the enemy when I get the knife

I want it when the knife is in my hand. The enemy will do me less damage by 40%

i searched of the forums before created this topic.. but I didn't find anything

Marttt 01-08-2020 04:36

Re: Reduced Damage
 
Well you could hook OnTakeDamage in OnWeaponSwitch and if it's not a knife you unhook OnTakeDamage
Maybe is not 100% safe but try it.

PHP Code:

#include <sourcemod>
#include <sdkhooks>

public OnClientPutInServer(int client)
{
    
SDKHook(clientSDKHook_WeaponSwitchOnWeaponSwitch);
}
public 
Action:OnWeaponSwitch(clientweapon
{
    
char WeaponName[32];
    
GetEdictClassname(weaponWeaponNamesizeof(WeaponName));
    if(
StrEqual(WeaponName"weapon_knife"false))
    {
        
SDKHook(clientSDKHook_OnTakeDamageEvent_OnTakeDamage);
    }
    else
    {
        
SDKUnhook(clientSDKHook_OnTakeDamageEvent_OnTakeDamage);
    }
}

public 
Action Event_OnTakeDamage(int victimint &attackerint &inflictorfloat &fDamageint &damagetypeint &weaponfloat a_fDmgForce[3], float a_fDmgPosition[3])
{
    
fDamage *= 0.6;        
    return 
Plugin_Changed;



generals 01-08-2020 05:13

Re: Reduced Damage
 
really thanks brother

its working

OhHai 01-08-2020 07:08

Re: Reduced Damage
 
Quote:

Originally Posted by Marttt (Post 2679355)
Well you could hook OnTakeDamage in OnWeaponSwitch and if it's not a knife you unhook OnTakeDamage
Maybe is not 100% safe but try it.

PHP Code:

#include <sourcemod>
#include <sdkhooks>

public OnClientPutInServer(int client)
{
    
SDKHook(clientSDKHook_WeaponSwitchOnWeaponSwitch);
}
public 
Action:OnWeaponSwitch(clientweapon
{
    
char WeaponName[32];
    
GetEdictClassname(weaponWeaponNamesizeof(WeaponName));
    if(
StrEqual(WeaponName"weapon_knife"false))
    {
        
SDKHook(clientSDKHook_OnTakeDamageEvent_OnTakeDamage);
    }
    else
    {
        
SDKUnhook(clientSDKHook_OnTakeDamageEvent_OnTakeDamage);
    }
}

public 
Action Event_OnTakeDamage(int victimint &attackerint &inflictorfloat &fDamageint &damagetypeint &weaponfloat a_fDmgForce[3], float a_fDmgPosition[3])
{
    
fDamage *= 0.6;        
    return 
Plugin_Changed;



So, you're hooking/unhooking SDKHook_OnTakeDamage every time a player switches weapons? Super sloppy.

Marttt 01-08-2020 07:13

Re: hp problem
 
Of course is not the best way to do it, as I said
Quote:

Maybe is not 100% safe
but there is a lot of worse plugin shared here in the forum

If you want to help, guide the user to a better way to do it instead of just blaming the code, which is not helpful.


All times are GMT -4. The time now is 05:32.

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