Raised This Month: $ Target: $400
 0% 

Prevent Damage for X seconds before weapon_x can deal damage again


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Triniayo
Senior Member
Join Date: Apr 2011
Location: #include <germany>
Old 04-19-2016 , 08:42   Prevent Damage for X seconds before weapon_x can deal damage again
Reply With Quote #1

Hello,

I wanted to ask, if someone could tell me how I could code how to prevent damage for X seconds, after weapon_x can deal damage again?

So, basically I hit someone with an AK, and after X seconds I can deal damage again. Hope you understand what I mean haha.
Would be nice if the function would work per target, and not an overall count.
__________________
If you need any help, feel free to add me on Steam.



Last edited by Triniayo; 04-19-2016 at 08:43.
Triniayo is offline
Send a message via Skype™ to Triniayo
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 04-19-2016 , 08:56   Re: Prevent Damage for X seconds before weapon_x can deal damage again
Reply With Quote #2

css, csgo or insurgency ?
There are many game mods.

Use sdkhook OnTakeDamge on players.
check attacker is valid client index, attacker index is equal to inflictor index.
Attacker is in game, then look attacker m_hActiveWeapon entity, get entity classname to look is it weapon_ak47.

use adt or trie array to store entity index with timestamp.
or any other method.


(I'm using phone)
__________________
Do not Private Message @me
Bacardi is offline
Triniayo
Senior Member
Join Date: Apr 2011
Location: #include <germany>
Old 04-19-2016 , 08:59   Re: Prevent Damage for X seconds before weapon_x can deal damage again
Reply With Quote #3

It's for CSS/CSGO.

And thanks for the reply, gonna give it a try
__________________
If you need any help, feel free to add me on Steam.


Triniayo is offline
Send a message via Skype™ to Triniayo
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 04-19-2016 , 09:12   Re: Prevent Damage for X seconds before weapon_x can deal damage again
Reply With Quote #4

You could create a global variable, then hook when the player deals damage, set the variable to false, then after a timer for x seconds set it to true again.

PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

bool g_bCanDealDamage[MAXPLAYERS 1] = true;
Handle g_hDamageTimer[MAXPLAYERS 1] = null;

#define LoopValidClients(%1) for(int %1 = 1; %1 < MaxClients; %1++) if(IsValidClient(%1))

public Plugin myinfo 
{
    
name ""
    
author ""
    
description ""
    
version "0.1"
    
url ""
};

public 
void OnPluginStart() {
    
HookEvent("player_hurt"Event_PlayerHurtEventHookMode_Post);
    
    
LoopValidClients(iClient) {
        
OnClientPutInServer(iClient);
    }
}

public 
void OnClientPutInServer(int iClient) {
    
SDKHook(iClientSDKHook_OnTakeDamageHook_TakeDamage);
    
g_bCanDealDamage[iClient] = true;
    
g_hDamageTimer[iClient] = null;
}

public 
void OnClientDisconnect(int iClient) {
    
g_bCanDealDamage[iClient] = true;
    
g_hDamageTimer[iClient] = null;
}

public 
void Event_PlayerHurt(Handle hEventchar[] chNamebool bDontBroadcast)
{
    
int iAttacker GetClientOfUserId(GetEventInt(hEvent"attacker"));
    
int iVictim GetClientOfUserId(GetEventInt(hEvent"userid"));
    
    if (
IsValidClient(iAttacker) && IsValidClient(iVictim) && iVictim != iAttacker && g_bCanDealDamage[iAttacker]) {
        
char chWeapon[48]; GetEventString(hEvent"weapon"chWeapon48); Format(chWeapon48"weapon_%s"chWeapon);
        
        if (
StrEqual(chWeapon"weapon_ak47"false)) {
            
g_bCanDealDamage[iAttacker] = false;
            
            if (
g_hDamageTimer[iAttacker] == null) {
                
g_hDamageTimer[iAttacker] = CreateTimer(5.0Timer_AllowDamageGetClientUserId(iAttacker), TIMER_FLAG_NO_MAPCHANGE);
            }
        }
    }
}

public 
Action Hook_TakeDamage(int iVictimint &iAttackerint &iInflictorfloat &fDamageint &iDamageTypeint &iWeaponfloat fDamageForce[3], float fDamagePosition[3])
{
    if (!
g_bCanDealDamage[iAttacker] && iAttacker != iVictim) {
        
float fNull[3]; fNull[0] = 0.0fNull[1] = 0.0fNull[2] = 0.0;
        
        
// Block the aimpunch.
        
SetEntPropVector(iVictimProp_Send"m_aimPunchAngle"fNull);
        
SetEntPropVector(iVictimProp_Send"m_aimPunchAngleVel"fNull);
        
SetEntPropVector(iVictimProp_Send"m_viewPunchAngle"fNull);
        
        return 
Plugin_Handled// Block Damage.
    
}
    
    return 
Plugin_Continue;
}

public 
Action Timer_AllowDamage(Handle hTimerint iUserId)
{
    
int iClient GetClientOfUserId(iUserId);
    
    if (!
IsValidClient(iClient)) {
        return 
Plugin_Stop;
    }
    
    
g_bCanDealDamage[iClient] = true;
    
g_hDamageTimer[iClient] = null;
    
    return 
Plugin_Stop;
}

stock bool IsValidClient(int iClient) {
    return 
iClient && iClient <= MaxClients && IsClientInGame(iClient);

So to block the player dealing damage then just set g_bCanDealDamage[iClient] = false; then set it to true to allow him to deal damage again.

Last edited by SM9; 04-20-2016 at 09:45.
SM9 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 04-19-2016 , 09:42   Re: Prevent Damage for X seconds before weapon_x can deal damage again
Reply With Quote #5

...but did OP want to block one certain "ak47" in between that time or all "ak47's" sametime ?
__________________
Do not Private Message @me
Bacardi is offline
Triniayo
Senior Member
Join Date: Apr 2011
Location: #include <germany>
Old 04-19-2016 , 10:21   Re: Prevent Damage for X seconds before weapon_x can deal damage again
Reply With Quote #6

I want to block the damage per player.

Example: Player 1 attacks Player 2 with an AK. After X seconds can Player 1 deal damage again on Player 2. Player 2 didn't shoot when Player 1 shot, and can still hurt Player 1 with his bullet.

So, this means that I want a cooldown per player and not a global cooldown for all players at the same time.
__________________
If you need any help, feel free to add me on Steam.



Last edited by Triniayo; 04-19-2016 at 10:22.
Triniayo is offline
Send a message via Skype™ to Triniayo
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 04-20-2016 , 09:27   Re: Prevent Damage for X seconds before weapon_x can deal damage again
Reply With Quote #7

Quote:
Originally Posted by FreakyLike View Post
I want to block the damage per player.

Example: Player 1 attacks Player 2 with an AK. After X seconds can Player 1 deal damage again on Player 2. Player 2 didn't shoot when Player 1 shot, and can still hurt Player 1 with his bullet.

So, this means that I want a cooldown per player and not a global cooldown for all players at the same time.
Oh ok, try this one then:
PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

bool g_bCanDealDamage[MAXPLAYERS 1][MAXPLAYERS 1];
Handle g_hDamageTimer[MAXPLAYERS 1][MAXPLAYERS 1];

#define LoopValidClients(%1) for(int %1 = 1; %1 < MaxClients; %1++) if(IsValidClient(%1))

public Plugin myinfo 
{
    
name ""
    
author ""
    
description ""
    
version "0.1"
    
url ""
};

public 
void OnPluginStart() {
    
HookEvent("player_hurt"Event_PlayerHurtEventHookMode_Post);
    
    
LoopValidClients(iClient) {
        
OnClientPutInServer(iClient);
    }
}

public 
void OnClientPutInServer(int iClient) {
    
SDKHook(iClientSDKHook_OnTakeDamageHook_TakeDamage);
    
    
LoopValidClients(i) {
        
g_bCanDealDamage[iClient][i] = true;
        
g_hDamageTimer[iClient][i] = null;
    }
}

public 
void OnClientDisconnect(int iClient) {
    
LoopValidClients(i) {
        
g_bCanDealDamage[iClient][i] = true;
        
g_hDamageTimer[iClient][i] = null;
    }
}

public 
void Event_PlayerHurt(Handle hEventchar[] chNamebool bDontBroadcast)
{
    
int iAttacker GetClientOfUserId(GetEventInt(hEvent"attacker"));
    
int iVictim GetClientOfUserId(GetEventInt(hEvent"userid"));
    
    if (
IsValidClient(iAttacker) && IsValidClient(iVictim) && iVictim != iAttacker && g_bCanDealDamage[iAttacker][iVictim]) {
        
char chWeapon[48]; GetEventString(hEvent"weapon"chWeapon48); Format(chWeapon48"weapon_%s"chWeapon);
        
        if (
StrEqual(chWeapon"weapon_ak47"false)) {
            
g_bCanDealDamage[iAttacker][iVictim] = false;
            
            if (
g_hDamageTimer[iAttacker][iVictim] == null) {
                
DataPack dPackg_hDamageTimer[iAttacker][iVictim] = CreateDataTimer(5.0Timer_AllowDamagedPackTIMER_FLAG_NO_MAPCHANGE TIMER_DATA_HNDL_CLOSE);
                
WritePackCell(dPackGetClientUserId(iAttacker)); WritePackCell(dPackGetClientUserId(iVictim)); ResetPack(dPack);
            }
        }
    }
}

public 
Action Hook_TakeDamage(int iVictimint &iAttackerint &iInflictorfloat &fDamageint &iDamageTypeint &iWeaponfloat fDamageForce[3], float fDamagePosition[3])
{
    if (!
g_bCanDealDamage[iAttacker][iVictim] && iAttacker != iVictim) {
        
float fNull[3]; fNull[0] = 0.0fNull[1] = 0.0fNull[2] = 0.0;
        
        
// Block the aimpunch.
        
SetEntPropVector(iVictimProp_Send"m_aimPunchAngle"fNull);
        
SetEntPropVector(iVictimProp_Send"m_aimPunchAngleVel"fNull);
        
SetEntPropVector(iVictimProp_Send"m_viewPunchAngle"fNull);
        
        return 
Plugin_Handled// Block Damage.
    
}
    
    return 
Plugin_Continue;
}

public 
Action Timer_AllowDamage(Handle hTimerDataPack dPack)
{
    
int iAttacker GetClientOfUserId(ReadPackCell(dPack));
    
int iVictim GetClientOfUserId(ReadPackCell(dPack));
    
    if (!
IsValidClient(iAttacker) || !IsValidClient(iVictim)) {
        return 
Plugin_Stop;
    }
    
    
g_bCanDealDamage[iAttacker][iVictim] = true;
    
g_hDamageTimer[iAttacker][iVictim] = null;
    
    return 
Plugin_Stop;
}

stock bool IsValidClient(int iClient) {
    return 
iClient && iClient <= MaxClients && IsClientInGame(iClient);

PHP Code:
g_bCanDealDamage[iAttacker][iVictim] = true
Would mean the attacker index can damage the victim index.

Let me know how it works!

Last edited by SM9; 04-20-2016 at 09:54.
SM9 is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 04-20-2016 , 20:09   Re: Prevent Damage for X seconds before weapon_x can deal damage again
Reply With Quote #8

I would personally avoid timers per client and store a time instead.
__________________
Neuro Toxin is offline
Reply



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 02:51.


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