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

[HELP] Launching Grenades From Weapon


Post New Thread Reply   
 
Thread Tools Display Modes
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-23-2015 , 08:20   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #21

This is why I requested more informations, I don't know how the grenade type will be selected, so the actual code throw them in their order that is in the inventory. He wants no animation, the weapon should stay there while the grenade is throwed. At least this is what I did, it really depends on what he want to do, but this is what I understand from what he said.
__________________
HamletEagle is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-23-2015 , 08:50   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #22

I'm sorry i didn't make myself understood...

Arkshine is right, that is exactly what i want

About the animation, i will create a custom animation for that weapon's model, and i want that animation to play when the player is launching a grenade

Last edited by Depresie; 08-23-2015 at 08:53.
Depresie is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-23-2015 , 09:09   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #23

Ok, so to set your custom animation just do:
Code:
CAK47_SendWeaponAnim = OrpheuGetFunctionFromClass("weapon_ak47", "SendWeaponAnim", "CBasePlayerWeapon")
OrpheuCall(CAK47_SendWeaponAnim, ak47_ent_index, your_animation_number_here, 0)
__________________
HamletEagle is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-23-2015 , 09:31   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #24

couldn't this be done without orpheu ?
i have a stock for playing animation on v model, but as i mentioned before, using your code triggers the draw animation twice so i still get a draw animation at the end

Last edited by Depresie; 08-23-2015 at 09:32.
Depresie is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-23-2015 , 10:33   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #25

If you mean to send a new animation without orpheu, sure, you can send a SVC_WEAPONANIM message, in fact, this is what the function do.
__________________

Last edited by HamletEagle; 08-23-2015 at 10:52.
HamletEagle is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-23-2015 , 11:07   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #26

As side-note, since weapons are client-side, SVC_WEAPONANIM is actually only needed if cl_lw (client-side weapon firing prediction) is not set (it is by default).
To know whether client has this cvar set, you can use EngFunc_CanSkipPlayer.

A right stock would be something like:

PHP Code:
stock SendWeaponAnim(animationweaponowner 0)
{
    if (!
owner)
    {
        const 
m_pPlayer 41;
        
owner get_pdata_cbase(weaponm_pPlayer, .linuxdiff 4, .macdiff 4);
    }
   
    
set_pev(ownerpev_weaponanimanimation);

    if (
ExecuteHam(Ham_Weapon_UseDecrementweapon) && engfunc(EngFunc_CanSkipPlayerowner))
    {
        return;
    }
    
    
message_begin(MSG_ONESVC_WEAPONANIM, .player owner);
    
write_byte(animation);
    
write_byte(pev(weaponpev_body));
    
message_end();

or if you don't know weapon index:

PHP Code:
stock SendWeaponAnim(animationownerweapon 0)
{
    if (!
weapon)
    {
        const 
m_pActiveItem 373;
        
weapon get_pdata_cbase(ownerm_pActiveItem, .linuxdiff 5, .macdiff 5);
    }
   
    
set_pev(ownerpev_weaponanimanimation);

    if (
ExecuteHam(Ham_Weapon_UseDecrementweapon) && engfunc(EngFunc_CanSkipPlayerowner))
    {
        return;
    }
    
    
message_begin(MSG_ONESVC_WEAPONANIM, .player owner);
    
write_byte(animation);
    
write_byte(pev(weaponpev_body));
    
message_end();

__________________

Last edited by Arkshine; 04-01-2016 at 17:46.
Arkshine is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-23-2015 , 11:12   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #27

Arkshine, you forgot the linux diff on get_pdata_cbase.
__________________

Last edited by Arkshine; 08-23-2015 at 11:17. Reason: Thanks fixed, though you forgot MAC, oh how dare you.
HamletEagle is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-28-2015 , 10:09   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #28

sorry for late reply, i was busy lately

by using hamlet's code i noticed the following

1. if the player is launching a grenade by right click, and he has more than one in his inventory, when he is pressing left click, another grenade is launched instead of shooting with the weapon
2. It takes the exact same time for the grenade to be launched, as if it is thrown by hand, i would like the grenade to be launched instantly
3. Player can't shoot with the weapon for couple seconds after the grenade is launched, it looks like Ham_Deploy is triggered after the grenade was launched

Isn't there a way to skip all these to the part where the grenade entity is created ( already in air )?

Like, press right click, grenade is launched instantly, player can shoot while grenade is launched

Last edited by Depresie; 08-28-2015 at 10:10.
Depresie is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-28-2015 , 10:34   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #29

I told you that there may be more things to handle, and if I remember well you said you could take care of them. Well, nvm. Also, my code only handle the smoke grenade case, you need to check for other grenades too.

Edit: Or, wait, maybe not. The only thing that is different on grenades is the animation in my code, but looking at the weapons code animations index are the same, and it should work ok.

To find a way, you must understand what CS do. Look at what I highlighted(will talk about sg, it should be mostly the same for all of them): https://github.com/Arkshine/CSSDK/bl...enade.cpp#L116

When you execute PrimaryAttack on the grenade, it sets m_flStartThrow offset to current game time. Then, in WeaponIdle this offset is checked, if bigger than 0 a grenade throw will be initialized(https://github.com/Arkshine/CSSDK/bl...enade.cpp#L151). My answer will be mostly the same as before, redo this:
PHP Code:
 if( angleThrow.)
            
angleThrow.= -10 angleThrow.* ( ( 90 10 ) / 90.0 );
        else
            
angleThrow.= -10 angleThrow.* ( ( 90 10 ) / 90.0 );

        
float flVel = ( 90 angleThrow.) * 6;

        if( 
flVel 750 )
            
flVel 750;

        
UTIL_MakeVectorsangleThrow );

        
Vector vecSrc   m_pPlayer->pev->origin m_pPlayer->pev->view_ofs gpGlobals->v_forward 16;
        
Vector vecThrow gpGlobals->v_forward flVel m_pPlayer->pev->velocity
Then, find and call CGrenade::ShootSmokeGrenade with orpheu. You may need to also alter the offsets like game do:
PHP Code:
  m_flStartThrow        0;
        
m_flNextPrimaryAttack GetNextAttackDelay0.5 );
        
m_flTimeWeaponIdle    UTIL_WeaponTimeBase() + 0.75;

        
m_pPlayer->m_rgAmmom_iPrimaryAmmoType ]--;

        if( !
m_pPlayer->m_rgAmmom_iPrimaryAmmoType ] )
        {
            
m_flTimeWeaponIdle m_flNextSecondaryAttack m_flNextPrimaryAttack GetNextAttackDelay0.5 );
        } 
Edit2: Hold on a minute, I'll try to get the signature for the needed functions.
__________________

Last edited by HamletEagle; 08-28-2015 at 10:44.
HamletEagle is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-28-2015 , 11:22   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #30

when i said i can handle the rest, i was meaning sending new animation, creating new animation for weapon, creating the weapon, setting cooldowns, setting p_data_float, balancing the weapon...
not anything related to the grenade launch part..

my question still remain, isn't there a way to skip grenade throwing part to the point where it is created ?
i mean to the point where the grenade left the player's hand, and we could decrease the number of grenades the player has manualy
this way we wouldn't need to mess with the offsets
Depresie 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 10:18.


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