Raised This Month: $51 Target: $400
 12% 

Changing prediction of animation and sounds after forcing weapon switch


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
HAJohnny
New Member
Join Date: Jul 2012
Old 08-15-2016 , 02:37   Changing prediction of animation and sounds after forcing weapon switch
Reply With Quote #1

Edit: So I probably won't be fixing these issues for my project, I've decided to use a sniper rifle as a base. Sorry to those looking for similar answers. Flamethrower and minigun sounds aren't even detected in AddNormalSoundHook.

I'm making a TF2 attribute plugin for a certain project of mine. The attributes are functional, and are as follows:
  1. No Damage Past Range: Nullifies damage after a range
  2. Jump While Spun Up: Allows one to jump with +attack2 while spinning or firing a minigun
  3. Switch Weapons While Spun Up: Allows one to instantly switch weapons while spinning or firing a minigun

I'm mostly concerned about the final attribute. The problems I'm having are that switching while firing the minigun causes the client to fail its predictions. The minigun sound continues to fire and the player tends to enter a "civilian" pose.

I'm using smlib's Client_SetActiveWeapon(client, slot) in order to force a quick switch from the minigun. In particular, I'm using SetActiveWeapon to switch to a "free" weapon. If the client switches to slot2, I use SetActiveWeapon to switch to slot3. After, the server automagically switches the client to slot2. I do this to have the normal delay with weapon-switching, as opposed to the instant change that SetActiveWeapon has.

I read in another thread that to stop weapon sounds, one would probably have to use the SendProxy extension to fake a delayed attack from the weapon while still allowing it to fire. I'm having trouble using this extension and would appreciate help with that.

I've tried hooking PreThink and PostThink to modify both the client buttons, and m_flNextAttackPrimary, but the client still predicts the minigun sound to continue firing. Perhaps I did that incorrectly.

As for fixing the civilian pose, I'm not really sure where to start. Is there code in another plugin somewhere I could take a look at? I've been searching through plugins but have hit a bit of a wall.

Here's what I have so far. There is apparently a tag mismatch in the line fValue = GetGameTime() + 33. But overall, I have no idea what I'm doing with the SendProxy extension and haven't been able to see what I should be doing from the snippets of it I've seen:

PHP Code:
public void OnPluginStart()
{    
    for (new 
1<= MaxClientsi++)
    {
        if (!
IsClientInGame(i)) continue;
        
OnClientPutInServer(i);
    }
}

//Hooking into damage/weapon switch
public OnClientPutInServer(client)
{

    
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamage);
    
    
SDKHook(clientSDKHook_WeaponCanSwitchToOnWeaponSwitch);
    
    
SDKHook(clientSDKHook_PreThinkPostOnPreThinkPost);
    
    
SDKHook(clientSDKHook_PostThinkPostOnPostThinkPost);
    
    
SendProxy_Hook(client"m_flNextPrimaryAttack"Prop_Float,ProxyCallback);

}

//Proxy Callback to change client variable
public Action:ProxyCallback(entity, const String:propname[], &fValueelement)
{
    
PrintToChatAll("In ProxyCallBack");
    if(
swapThink[entity]) {
        
fValue GetGameTime() + 33;
        
swapThink[entity] = false;
        return 
Plugin_Changed;
    }
    else { 
        return 
Plugin_Continue;
    }

Any help is appreciated!

Last edited by HAJohnny; 08-17-2016 at 17:02. Reason: No longer need an answer for my questions.
HAJohnny is offline
Benoist3012
Veteran Member
Join Date: Mar 2014
Location: CWave::ForceFinish()
Old 08-15-2016 , 20:34   Re: Changing prediction of animation and sounds after forcing weapon switch
Reply With Quote #2

You do GetGameTime() + 33 but 33 isn't a float value, it has to be 33.0
__________________
Benoist3012 is offline
HAJohnny
New Member
Join Date: Jul 2012
Old 08-16-2016 , 00:35   Re: Changing prediction of animation and sounds after forcing weapon switch
Reply With Quote #3

I used 33.0 originally. It was only 33 here since I was trying it to see if the tag mismatch would be fixed with an int, but yeah it should be 33.0.
HAJohnny is offline
Benoist3012
Veteran Member
Join Date: Mar 2014
Location: CWave::ForceFinish()
Old 08-16-2016 , 09:04   Re: Changing prediction of animation and sounds after forcing weapon switch
Reply With Quote #4

Anyway you aren't making your hook correctly, look:
Code:
SendProxy_Hook(client, "m_flNextPrimaryAttack", Prop_Float,ProxyCallback);

m_flPrimaryAttack doesn't control it, use m_flNextAttack instead.
You also don't need
Code:
if(swapThink[entity]) {
in your hook, just return GetGameTime() + 33.0 everytime.

Once this is fixed one last problem, the server-side weapon sound.

This will block the client-side weapon sound, but you still need to block the other (server-side).
__________________

Last edited by Benoist3012; 08-16-2016 at 09:10.
Benoist3012 is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 08-16-2016 , 14:43   Re: Changing prediction of animation and sounds after forcing weapon switch
Reply With Quote #5

May I ask how you achieved this:

Jump While Spun Up: Allows one to jump with +attack2 while spinning or firing a minigun

I tried doing it, and IN_JUMP was flat-out blocked in OnPlayerRunCmd while spun up.
__________________
Chdata is offline
HAJohnny
New Member
Join Date: Jul 2012
Old 08-16-2016 , 16:12   Re: Changing prediction of animation and sounds after forcing weapon switch
Reply With Quote #6

Quote:
Originally Posted by Chdata View Post
May I ask how you achieved this:

Jump While Spun Up: Allows one to jump with +attack2 while spinning or firing a minigun

I tried doing it, and IN_JUMP was flat-out blocked in OnPlayerRunCmd while spun up.
Yeah, IN_JUMP doesn't appear to be sent to the server when spinning a minigun. Note that I used IN_ATTACK2 directly to add the jump vector. You could use attack3 or reload or somethin' more appropriate.

In other news:

So I've discovered that delaying the minigun attack doesn't stop the sound, which makes sense since miniguns with different fire-rates still sound the same. It stops once the player releases +attack when holding out the minigun. My goal is to stop it on command, without having the player stop attacking.

So the question is, how does one stop a minigun fire sound from playing without the player releasing attack1?
And how does one prevent player models from glitching out when forcing these switches, while the player is holding down M1?

Here's the snippet where I force the weapon switch. It's not appropriate for all cases, but it works for my purposes 99 percent of the time.

PHP Code:
//SetEntPropFloat(activeweapon, Prop_Send, "m_flNextPrimaryAttack", GetGameTime() + 3.0);
           //SetEntPropFloat(activeweapon, Prop_Send, "m_flNextSecondaryAttack", GetGameTime() + 3.0);
        
        
if (weapon == slot2weapon){
            if (
activeweapon == slot1weaponunusedslot slot3weapon;
            else if (
activeweapon == slot3weapon)unusedslot slot1weapon;
            
Client_SetActiveWeapon(clientunusedslot); //force switch to free slot, client then autoswitches to their desired weapon
            //swapThink[client] = true;
            
action Plugin_Changed;
        }
        else if (
weapon == slot3weapon) {
            if (
activeweapon == slot1weaponunusedslot slot2weapon;
            else if (
activeweapon == slot2weapon)unusedslot slot1weapon;
            
Client_SetActiveWeapon(clientunusedslot);
            
//swapThink[client] = true;
            
action Plugin_Changed;
        }
        else if (
weapon == slot1weapon) {
            if (
activeweapon == slot2weaponunusedslot slot3weapon;
            else if (
activeweapon == slot3weapon)unusedslot slot2weapon;
            
Client_SetActiveWeapon(clientunusedslot);
            
//swapThink[client] = true;
            
action Plugin_Changed;
        } 
I suppose I'll have to take another look at the custom weapons 3 plugin to see if that's already been done.
HAJohnny is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 08-20-2016 , 05:51   Re: Changing prediction of animation and sounds after forcing weapon switch
Reply With Quote #7

Only way I know to get rid of minigun sounds is to use tomislv and the silent killer attribute.
__________________
Chdata is offline
pheadxdll
AlliedModders Donor
Join Date: Jun 2008
Old 08-20-2016 , 08:48   Re: Changing prediction of animation and sounds after forcing weapon switch
Reply With Quote #8

I believe I've dealt with the problems from instantly switching away from the minigun in my melee plugin. Should be linked below. Give it a shot if you are still having problems.
__________________
pheadxdll is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 08-21-2016 , 14:24   Re: Changing prediction of animation and sounds after forcing weapon switch
Reply With Quote #9

deployed weapons have a state netprop, minigun... huntsman, etc.
you can set the netprop, or force the weapon to reset with a fakeclient command, or sdkcall.

most weapons have client side sounds and graphics... some can not be hidden.
minigun is a special case, where it is always transmitted. Not sure why this is.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram 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 19:44.


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