Raised This Month: $235 Target: $400
 58% 

Solved In player_death Check for weapon_healthshot ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Austin
Senior Member
Join Date: Oct 2005
Old 09-13-2021 , 02:44   In player_death Check for weapon_healthshot ?
Reply With Quote #1

I am writing a pluginfor CSGO that when a player dies if they have a weapon_healthshot a center text message will print.
This works but I only want to see this message if I was the person that killed them and made them drop the healthshot.

Edit:
After a LOT of messing around, Got it working!

PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdkhooks>

new droppedShot[MAXPLAYERS];

public 
OnPluginStart()
{
    
HookEvent("round_start"Event_RoundStartEventHookMode_Post);
    
HookEvent("player_death",    Event_PlayerDeathEventHookMode_Post);
     
HookEvent("player_spawn"Event_PlayerSpawnEventHookMode_Post);
}

public 
Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
    for (
int i 1<= MaxClientsi++)
        
droppedShot[i] = 0;
}

public 
OnClientPutInServer(client)
{
    
SDKHook(clientSDKHook_WeaponDropPostHook_WeaponDropPost);
}

public 
Hook_WeaponDropPost(clientweapon)
{
    if(
weapon >= 0)
    {
        new 
String:weaponName[128];
        
GetEdictClassname(weaponweaponNamesizeof(weaponName));
        if (
strcmp(weaponName"weapon_healthshot") == 0)
            if (
client <= MaxClients)
                
droppedShot[client] = 1;
    }
}

public 
Event_PlayerDeath(Event event, const char[] namebool dontBroadcast)
{
    
int attacked GetClientOfUserId(event.GetInt("userid"));
    
int attacker GetClientOfUserId(event.GetInt("attacker"));
    if (
droppedShot[attacked] == && ((attacked <= MaxClients) && (attacker <= MaxClients)))
    {
        
droppedShot[attacked] = 0;
        
PrintToServer("Event_PlayerDeath - %d-%N - Dropped Shot! - <><><><><><><><>"attackedattacked);
        
PrintCenterText(attacker,"<><><><><><><><><> - %N - Dropped SHOT! - <><><><><><><><><>"attacked);
    }
}

public 
void Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("userid"));
    if (
client <= MaxClients)
        
droppedShot[client] = 0;


Last edited by Austin; 09-14-2021 at 20:24.
Austin is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 09-13-2021 , 11:52   Re: In player_death Check for weapon_healthshot ?
Reply With Quote #2

Which game?

You can store the client's killer (get from "player_death" event, "attacker" parameter) in some client array
e.g:
PHP Code:
int g_iKiller[MAXPLAYERS+1
and then use this var in the PrintCenterText

PHP Code:
PrintCenterText(g_iKiller[client], " %N - Dropped %s"clientweaponName); 
Don't forget to do the basic checks (IsClientInGame, valid index, etc)

Btw if you won't do anything on WeaponDrop (I mean, change the behaviour) I recommend using WeaponDropPost.
__________________

Last edited by Marttt; 09-13-2021 at 12:11.
Marttt is offline
Austin
Senior Member
Join Date: Oct 2005
Old 09-13-2021 , 12:37   Re: In player_death Check for weapon_healthshot ?
Reply With Quote #3

Got it.
Thanks.
Austin is offline
Austin
Senior Member
Join Date: Oct 2005
Old 09-14-2021 , 20:25   Re: In player_death Check for weapon_healthshot ?
Reply With Quote #4

After a LOT of messing around, Got it working.
Looks like the player drops his items BEFORE the player_death event is fired and I even saw sometimes player_death was intermixed with the items being dropped.

And when you use a shot it generates an item drop for it.

This isn't perfect since if a player drops a heathshot while still alive it will still be reported when they die but it's a bot server and they never use or drop shots unless it is on death.

I updated the original post with the working code.

thanks

Last edited by Austin; 09-14-2021 at 20:26.
Austin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-17-2021 , 05:55   Re: In player_death Check for weapon_healthshot ?
Reply With Quote #5

one example with SDKHook
PHP Code:
#include <sdktools>
#include <sdkhooks>
#include <cstrike>

public void OnPluginStart()
{
    for(
int i 1<= MaxClientsi++)
    {
        if(
IsClientInGame(i)) OnClientPutInServer(i);
    }
}

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


public 
void OnTakeDamageAlivePost(int victimint attackerint inflictorfloat damageint damagetype)
{

    if(
attacker || attacker MaxClients || !IsClientInGame(attacker) || !IsPlayerAlive(attacker) || IsFakeClient(attacker))
    {
        return;
    }


    if(
GetClientHealth(victim) > 0)
    {
        return;
    }

    
int entity;
    
char classname[64];

    
int arraysize GetEntPropArraySize(victimProp_Send"m_hMyWeapons");
    
    for(
int x 0arraysizex++)
    {
        
entity GetEntPropEnt(victimProp_Send"m_hMyWeapons"x);
        
        if(
entity != -1)
        {
            
GetEntityClassname(entityclassnamesizeof(classname));
            
PrintToServer("%i Victim %i %s"victimentityclassname);

            
CS_GetTranslatedWeaponAlias(classnameclassnamesizeof(classname));
            
CSWeaponID weaponID CS_AliasToWeaponID(classname);

            if(
weaponID == CSWeapon_HEALTHSHOT)
            {
                
PrintToServer("%i Victim CSWeapon_HEALTHSHOT %i %s"victimentityclassname);
            }
        }
    }

__________________
Do not Private Message @me

Last edited by Bacardi; 09-18-2021 at 09:00. Reason: what if we check victim health on Post event...
Bacardi is offline
Austin
Senior Member
Join Date: Oct 2005
Old 09-18-2021 , 00:29   Re: In player_death Check for weapon_healthshot ?
Reply With Quote #6

Bacardi, thanks for this.
It is it cleaner and less of a hack then my original solution.
Your plugin compiles and runs but it lists the weapons twice for each kill.
Why is that and it makes the solution unusable.

From some testing.

bot 1 killed
Victim weapon weapon_knife
Victim weapon weapon_fiveseven
Victim weapon weapon_mac10
Victim weapon weapon_knife
Victim weapon weapon_fiveseven
Victim weapon weapon_mac10

bot 2 killed
Victim weapon weapon_knife
Victim weapon weapon_fiveseven
Victim weapon weapon_knife
Victim weapon weapon_fiveseven

bot 3 killed
Victim weapon weapon_knife
Victim weapon weapon_fiveseven
Victim weapon weapon_ak47
Victim weapon weapon_c4
Victim weapon weapon_knife
Victim weapon weapon_fiveseven
Victim weapon weapon_ak47
Victim weapon weapon_c4

Last edited by Austin; 09-18-2021 at 02:14.
Austin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-18-2021 , 07:31   Re: In player_death Check for weapon_healthshot ?
Reply With Quote #7

ok, I think because I used SDKHook_OnTakeDamageAlivePost.
I did not notice, player health was already decreased when this event happen.
And when player health go low, it printed extra message, before last shoot -> death.

I changed to SDKHook_OnTakeDamageAlive
and now player health is before damage applies.
Code:
...
public void OnClientPutInServer(int client)
{
    SDKHook(client, SDKHook_OnTakeDamageAlive, OnTakeDamageAlive);
}


public Action OnTakeDamageAlive(int victim, int &attacker, int &inflictor, float &damage, int &damagetype)
{
...
*edit
Using OnTakeDamagePost, again. I put check only victim health, not applied damage amount.
Maybe it work now. #5
__________________
Do not Private Message @me

Last edited by Bacardi; 09-18-2021 at 09:03.
Bacardi is offline
Austin
Senior Member
Join Date: Oct 2005
Old 09-18-2021 , 15:21   Re: In player_death Check for weapon_healthshot ?
Reply With Quote #8

Bacardi, it works!

This is a much cleaner and better solution.
Thank you!
Austin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-19-2021 , 07:02   Re: In player_death Check for weapon_healthshot ?
Reply With Quote #9

For clarify more, in my example it look through player weapons when player is dying.

But does actual healthshot drop happens ? Dunno.
For example in CSGO deathmatch, those healthshots disappear when victim die.
And on CSGO survived mode, dying player drop healtshot.

So, your example could be much better.

Dunno, can you check weapon_healthshot m_iOwner (or what was it name ?) on SDKHook WeaponDrop and check is player alive ? I have not tested.
__________________
Do not Private Message @me
Bacardi is offline
Austin
Senior Member
Join Date: Oct 2005
Old 09-20-2021 , 17:22   Re: In player_death Check for weapon_healthshot ?
Reply With Quote #10

Quote:
Originally Posted by Bacardi View Post
But does actual healthshot drop happens ? Dunno.
For example in CSGO deathmatch, those healthshots disappear when victim die.
And on CSGO survived mode, dying player drop healtshot.
For my server classic casual with my healthshot plugin that gives healthshots,
they definitely drop and you can pick them up.
I only have these settings:

ammo_item_limit_healthshot 4
mp_death_drop_healthshot 1

And a find on healthshot doesn't show any setting that would limit them so I don't know how they are limited in deathmatch other than
mp_death_drop_healthshot 0

Quote:
Originally Posted by Bacardi View Post
Dunno, can you check weapon_healthshot m_iOwner (or what was it name ?) on SDKHook WeaponDrop and check is player alive ? I have not tested.
When a player with a healthshot dies the attackers sees the message and hears the sound and the console prints the player is dead at that point.

3 Victim Brandon IsAlive= n

PHP Code:
if(weaponID == CSWeapon_HEALTHSHOT)
{
   
EmitSoundToAll("ui/item_drop_personal.wav",attacker);
   
PrintCenterText(attacker,"<><><><> - %N - Dropped SHOT! - <><><><>"victim);
   
PrintToServer("%i Victim %N IsAlive= %n"victimvictimIsPlayerAlive(victim));

Here is the full plugin in case anyone is interested.
It has been well tested and working 100%

1) Randomly give health shots on round start to bots and humans
2) Disallow team bots to have shots
(they will drop them on round start if given and humans and enemy bots can pick them up).
3) On death if victim has shot attacker will see a message and hear a sound.
Attached Files
File Type: sp Get Plugin or Get Source (ABS_CSGO_HealthShot.sp - 4 views - 4.4 KB)

Last edited by Austin; 09-20-2021 at 17:26.
Austin 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 04:11.


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