Raised This Month: $ Target: $400
 0% 

How to detect weapon switch


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Wliu
Veteran Member
Join Date: Apr 2013
Old 01-02-2016 , 11:18   How to detect weapon switch
Reply With Quote #1

Specifically, I'd like to be able to tell when the Half-Zatoichi (TF2) is sheathed so that I can do some custom logic based on whether a kill was made or not.

Also, while we're here, is there an easy way to tell if a weapon is a reskin or not? Preferably just the collection-type ones, but all reskins are fine too.
__________________
~Wliu
Wliu is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 01-02-2016 , 11:37   Re: How to detect weapon switch
Reply With Quote #2

Quote:
Originally Posted by Wliu View Post
Specifically, I'd like to be able to tell when the Half-Zatoichi (TF2) is sheathed so that I can do some custom logic based on whether a kill was made or not.
SDKHooks. Specifically SDKHook_WeaponSwitch.

Quote:
Originally Posted by Wliu View Post
Also, while we're here, is there an easy way to tell if a weapon is a reskin or not? Preferably just the collection-type ones, but all reskins are fine too.
The collection-type items all have item definition indexes >= 15000. Right now, that's 15000 through 15158.

There used to be template items starting with 16000, but those have since been removed from the schema.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 01-02-2016 , 11:50   Re: How to detect weapon switch
Reply With Quote #3

You can use TF2Attributes to check if they have the skin wear attribute, probably.

That SDKHook works, but not that returning Plugin_Handled to block it won't be client predicted so it'll look glitchy to them.
__________________
Chdata is offline
Wliu
Veteran Member
Join Date: Apr 2013
Old 01-02-2016 , 13:53   Re: How to detect weapon switch
Reply With Quote #4

Great, thanks!

Chdata: That's a pretty good idea (and actually is directly related to what I want to do with them), so thanks.
__________________
~Wliu
Wliu is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 01-02-2016 , 20:48   Re: How to detect weapon switch
Reply With Quote #5

Another idea is to just check the item definition index, put all non-stock weapons in an empty switch case, and then default will cover all the sniper rifle reskins and any new ones that are added to the game.

However if something like the star shooter is added which is actually a Machina reskin, you'll have to update it. However it will still cover the majority of these new weapon skins for the future going forward.
__________________
Chdata is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 01-03-2016 , 05:13   Re: How to detect weapon switch
Reply With Quote #6

Quote:
Originally Posted by Chdata View Post
Another idea is to just check the item definition index, put all non-stock weapons in an empty switch case, and then default will cover all the sniper rifle reskins and any new ones that are added to the game.

However if something like the star shooter is added which is actually a Machina reskin, you'll have to update it. However it will still cover the majority of these new weapon skins for the future going forward.
This is similar to what I do.

You could make a secondary plugin that uses a native to get stock index, and have that do the switching so you don't have to edit all your plugins. Read it from a config or hard coded, you'll have to update by hand.

The sdkhooks weapon switch is not always accurate! Sometimes lunchbox items and such screw with it.
A more reliable method is to check on a timer, preferably comparing active weapon netprop of the client vs the sword. The timer will die out along with the item if you use an entref. Just pass a data timer with client serial and weapon entref.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 01-03-2016 , 08:28   Re: How to detect weapon switch
Reply With Quote #7

^ I really need to make some fockin natives more often.

Oh yeah, when I was working on taunt crits and making something that prevents keeping tauntcrit buff after a weapon switch I noticed the lunchbox items thing. I believe it also happens with custom taunts like high five and all that stuff.

Rather than a timer you can track whether or not a weapon switch occured because someone used a taunt item. Any taunt item that sets m_iTauntItemDefIndexWhateverYouCallIt to something other than -1 will cause a weaponswitch call.

PHP Code:
static g_iTauntItemDefIndex[TF_MAX_PLAYERS] = {-1,...};

public 
OnClientPostAdminCheck(iClient)
{
    
g_iTauntItemDefIndex[iClient] = -1;
    
SDKHook(iClientSDKHook_WeaponSwitchPostOnWeaponSwitch);
}

//static bool:g_bNoTauntCrits[TF_MAX_PLAYERS] = {false,...};
public Action:OnWeaponSwitch(iClientiWeapon)
{
    if (
g_iTauntItemDefIndex[iClient] == -1)
    {
        
g_iTauntStatus[iClient] = TStat_None;
        
RequestFrame(OnWeaponSwitchFrameGetClientUserId(iClient)); // We do it a frame later because... uh...?
        //SDKUnhook(iClient, SDKHook_WeaponSwitchPost, OnWeaponSwitch);
    
}
    else
    {
        
g_iTauntItemDefIndex[iClient] = -1// This will happen if someone is using a taunt item such as high five, which fires OnWeaponSwitch once after the taunt is done.
    
}
    
    return 
Plugin_Continue;
}

public 
OnWeaponSwitchFrame(any:UserId)
{
    new 
iClient GetClientOfUserId(UserId);
    if (
iClient && IsClientInGame(iClient))
    {
        
TF2_RemoveCondition(iClientTFCond_Buffed);
        
TF2_RemoveCondition(iClientTFCond_CritCanteen);
        
s_bTauntCritBuffed[iClient] = false;
        
g_iTauntStatus[iClient] = TStat_None;
    }
}

public 
TF2_OnConditionAdded(iClientTFCond:iCond)
{
    if (
iCond == TFCond_Taunting)
    {
        
g_iTauntItemDefIndex[iClient] = GetEntProp(iClientProp_Send"m_iTauntItemDefIndex");
    }

I've had no problems with it for a long time, though I recently stopped unhooking/hooking weaponswitch when I need it so whenever someone does their first tauntcrit after a reconnect, for some reason their taunt crit doesn't work. But every consecutive one will.

I believe it has something to do with the fact that WeaponSwitch is also called when you are equipped with a weapon after spawning and maybe at other times too.

Since soldier doesn't have lunchbox stuff you should be good with the taunt item fix tho.
__________________

Last edited by Chdata; 01-03-2016 at 08:31.
Chdata 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 05:46.


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