Raised This Month: $32 Target: $400
 8% 

[L4D2]How to get the active weapon before the incapacitated player is incapacitated


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
sorallll
Senior Member
Join Date: Oct 2018
Old 01-15-2022 , 06:46   [L4D2]How to get the active weapon before the incapacitated player is incapacitated
Reply With Quote #1

Is it possible to get the active weapon before the incapacitated player is incapacitated by offset
sorallll is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 01-15-2022 , 09:17   Re: [L4D2]How to get the active weapon before the incapacitated player is incapacitat
Reply With Quote #2

Hmmm
WeaponSwitch Pre + m_hActiveWeapon, then timer 0.0 seconds to look is player incapacitated
__________________
Do not Private Message @me
Bacardi is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 01-15-2022 , 09:50   Re: [L4D2]How to get the active weapon before the incapacitated player is incapacitat
Reply With Quote #3

0.1 is minimum the timer resolution. If you need something like 0.0 use RequestFrame to do stuff on the next frame.
__________________
Silvers is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 01-15-2022 , 16:29   Re: [L4D2]How to get the active weapon before the incapacitated player is incapacitat
Reply With Quote #4

SDKHook_WeaponSwitch works, however it get executed many times, on all items you carried.

There is also two event. I think first works fine.
PHP Code:
"player_incapacitated_start" // before player switch weapon
"player_incapacitated" // after player switch weapon 
"m_hActiveWeapon" is returning item which player is holding.

PHP Code:
public void OnPluginStart()
{
    
HookEventEx("player_incapacitated_start"player_incapacitated_start);
}

public 
void player_incapacitated_start(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("userid"));

    if(
IsFakeClient(client)) return;

    
DataPack pack;
    
CreateDataTimer(0.1delaypack);
    
pack.WriteCell(client);
    
pack.WriteCell(GetEntPropEnt(clientProp_Send"m_hActiveWeapon"));
    
pack.Reset();
}

public 
Action delay(Handle timerDataPack data)
{
    
int client data.ReadCell();
    
int previtem data.ReadCell();

    
int m_hActiveWeapon GetEntPropEnt(clientProp_Send"m_hActiveWeapon");

    
char previtemclsname[30];
    if(
previtem != -1)
    {
        
GetEntityClassname(previtemprevitemclsnamesizeof(previtemclsname));
    }

    
char activeweaponclsname[30];
    if(
m_hActiveWeapon != -1)
    {
        
GetEntityClassname(m_hActiveWeaponactiveweaponclsnamesizeof(activeweaponclsname));
    }
    
PrintToServer("Player %N previous item %s, active weapon %s"clientprevitemclsnameactiveweaponclsname);

__________________
Do not Private Message @me
Bacardi is offline
sorallll
Senior Member
Join Date: Oct 2018
Old 01-16-2022 , 04:10   Re: [L4D2]How to get the active weapon before the incapacitated player is incapacitat
Reply With Quote #5

Is there a way to get this weapon after incapacitating it, I think there should be a player data that saves it. I didn't find it in CTerrorPlayer::OnRevived

Last edited by sorallll; 01-16-2022 at 04:12.
sorallll is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 01-16-2022 , 04:35   Re: [L4D2]How to get the active weapon before the incapacitated player is incapacitat
Reply With Quote #6

...there is event
Code:
01/15/2022 - 22:17:56: Server event "revive_success", Tick 13951:
01/15/2022 - 22:17:56: - "userid" = "3"
01/15/2022 - 22:17:56: - "subject" = "2"
01/15/2022 - 22:17:56: - "lastlife" = "0"
01/15/2022 - 22:17:56: - "ledge_hang" = "0"
or is there important reason to look/use "offsets" ?

*edit
here previous post event
Code:
01/15/2022 - 22:17:49: Server event "player_incapacitated_start", Tick 13758:
01/15/2022 - 22:17:49: - "userid" = "2"
01/15/2022 - 22:17:49: - "attacker" = "0"
01/15/2022 - 22:17:49: - "attackerentid" = "163"
01/15/2022 - 22:17:49: - "weapon" = ""
01/15/2022 - 22:17:49: - "type" = "128"
01/15/2022 - 22:17:49: m_hActiveWeapon -1, WeaponSwitch 279, m_isIncapacitated 1
01/15/2022 - 22:17:49: m_hActiveWeapon 279, WeaponSwitch 279, m_isIncapacitated 1
01/15/2022 - 22:17:49: Server event "item_pickup", Tick 13758:
01/15/2022 - 22:17:49: - "userid" = "2"
01/15/2022 - 22:17:49: - "item" = "pistol"
01/15/2022 - 22:17:49: Server event "player_incapacitated", Tick 13758:
01/15/2022 - 22:17:49: - "userid" = "2"
01/15/2022 - 22:17:49: - "attacker" = "0"
01/15/2022 - 22:17:49: - "attackerentid" = "163"
01/15/2022 - 22:17:49: - "weapon" = ""
01/15/2022 - 22:17:49: - "type" = "128"
__________________
Do not Private Message @me

Last edited by Bacardi; 01-16-2022 at 04:37.
Bacardi 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 17:06.


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