Raised This Month: $ Target: $400
 0% 

[HELP] Launching Grenades From Weapon


Post New Thread Reply   
 
Thread Tools Display Modes
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-21-2015 , 15:34   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #11

Thanks ! i appreciate it very much
I will try to figure it out this night, and i will come back with an edit

Later Edit:

It can't be done without weapon switch right ?
I want to do it like, right click, set animation grenade launcher animation, launch grenade, back to idle weapon animation ( no draw animations )

Also, i was thinking at another method, which may be more efficient, is it possible to create an entity and then turn it into a cs grenade?

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

Look for example in wpn_smokegrenade: https://github.com/Arkshine/CSSDK/bl...enade.cpp#L197

I did no weapon switch, see that game sets the animations, I have to think about this a bit, if there is a way to avoid this or not. Will see...
__________________
HamletEagle is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-21-2015 , 17:19   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #13

btw i edited my last post, take a look, if that would be possible, it would be nice..
also, since im using zombie plague, all grenades are modified ( fire, frost, flare )
maybe we could set that entity with a native to turn into the specified grenade

Spoiler
Depresie is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-23-2015 , 04:47   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #14

You can create weapon entities, but it will be a lot of work and it does not worth.

I was thinking how to deal properly with the animations. The first thing at what I thought was to block the animtions, which is just a matter of hooking CBasePlayerWeapon::SendAnimation or using UpdateClientData. I would choose the first because it is called only when an animation is send. But, there are at least two problems. SendWeaponAnim send strange animation index, let's say that animation index is 1 when game send it, and the function give you 91, I don't know why. However UpdateClientData pass the correct index. Moreover blocking the animation will remove the switch, but the weapon will be intrerrupted for a a second, it will sake a bit.
You would need to find the proper moment for unregistering the hook, otherwise another animations would be blocked. This can't be handled properly.

Another way at I was thinking was to patch the memory to remove the SendAnimation code, but this would be silly and inneficient, too many patching and unpatching will be needed.

Basically, what you need to do is to find a way to call CGrenade:ShootSmokeGrenade without triggering a weapon switch. I think that we may be able to manually call it with orpheu, will try later to see if this works properly.

So, I have to search myself more and find ideeas, you may try to think too.
__________________

Last edited by HamletEagle; 08-23-2015 at 05:59. Reason: Bad language.
HamletEagle is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-23-2015 , 05:26   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #15

Quote:
SendWeaponAnim send strange animation index, let's say that animation index is 1 when game send it, and the function return 91
Function returns nothing. I thought I told you to check before thinking returning is int everywhere.
__________________
Arkshine is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-23-2015 , 05:56   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #16

Quote:
Originally Posted by Arkshine View Post
Function returns nothing. I thought I told you to check before thinking returning is int everywhere.
Used the wrong word, I didn't mean that it return something, I was talking about the animation param. It should give the animation index.
__________________

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

Maybe you did not properly setup config, or did not put properly params, so you got the weapon index instead.
__________________

Last edited by Arkshine; 08-23-2015 at 06:48.
Arkshine is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-23-2015 , 07:19   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #18

i never heard about those offsets and functions in my life... i have no ideea how to do it that way... it is over my head...
a custom grenade launching animation would fix the first animation that is triggered, but about the second i dont know

Quote:
Originally Posted by HamletEagle View Post
Basically, what you need to do is to find a way to call CGrenade:ShootSmokeGrenade without triggering a weapon switch
when i posted this, i was thinking exactly about this, but i couldn't find anything about it

the easiest way i was thinking of is to fake the grenades, to create an entity, to launch it, and when it hits something, to execute the fire/frost native / execute ham in the area and decrease the number of the grenades the player has

but i would like to see it done with the method hamlet was thinking, if i would see a code like that, and learn it, it would open me many doors regarding the customization of the game

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

My mistake was that I forgot that the first param will be the weapon entity index(the object this). So yeah, you are right.

This is a working code, it will block the switch animation:
PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>
#include <cstrike>
#include <orpheu>
#define MAX_ITEM_TYPES 6

enum
{
    
SMOKEGRENADE_IDLE,
    
SMOKEGRENADE_PINPULL,
    
SMOKEGRENADE_THROW,
    
SMOKEGRENADE_DRAW
}

enum
{
    
AK47_IDLE1,
    
AK47_RELOAD,
    
AK47_DRAW,
    
AK47_SHOOT1,
    
AK47_SHOOT2,
    
AK47_SHOOT3
}

new const 
m_rgpPlayerItems_CBasePlayer[MAX_ITEM_TYPES] = {367368, ...}
const 
m_pNext           42
const m_iId             43
const m_pActiveItem     373 
const XoCBasePlayerItem 4
const XoPlayer          5

new HamHook:HandleCBaseEntity_AK47IdleHook
new OrpheuHook:HandleGSendWeaponAnimation
new OrpheuHook:HandleASendWeaponAnimation

public plugin_init()
{
    new const 
AK47ClassName[] = "weapon_ak47"
    
    
RegisterHam(Ham_Item_DeployAK47ClassName"CBasePlayer_ItemDeploy"false)
    
RegisterHam(Ham_Item_HolsterAK47ClassName"CBasePlayer_ItemHolster"false
    
HandleCBaseEntity_AK47IdleHook RegisterHam(Ham_Weapon_WeaponIdleAK47ClassName"CBaseEntity_AK47Idle"true)
    
    
DisableHamForward(HandleCBaseEntity_AK47IdleHook
}

public 
CBaseEntity_AK47Idle(Entity)
{
    if(
pev_valid(Entity))
    {
        new 
id pev(Entitypev_owner)
        if(
pev(idpev_button) & IN_ATTACK2)
        {
            new 
WeaponEnt get_pdata_cbase(idm_rgpPlayerItems_CBasePlayer[4], XoPlayer)
            
            if(
pev_valid(WeaponEnt))
            {
                new 
WeaponCSWIndex get_pdata_int(WeaponEntm_iIdXoCBasePlayerItem)
                new 
WeaponName[32]; get_weaponname(WeaponCSWIndexWeaponNamecharsmax(WeaponName))
                
                
HandleGSendWeaponAnimation OrpheuRegisterHook(OrpheuGetFunctionFromClass(WeaponName"SendWeaponAnim""CBasePlayerWeapon"), "OnSendWeaponAnim_Grenade"OrpheuHookPre)
                
HandleASendWeaponAnimation OrpheuRegisterHook(OrpheuGetFunctionFromClass("weapon_ak47""SendWeaponAnim""CBasePlayerWeapon"), "OnSendWeaponAnim_AK47"OrpheuHookPre)
                
                
set_pdata_cbase(idm_pActiveItemWeaponEntXoPlayer)
                
ExecuteHamB(Ham_Weapon_PrimaryAttackWeaponEnt)     
            }
        }
    }
}

public 
OrpheuHookReturn:OnSendWeaponAnim_Grenade(WeaponAnimationSkipLocal)
{
    static 
Blocked
    
if(Blocked 2)
    {
        if(
Animation == SMOKEGRENADE_PINPULL || Animation == SMOKEGRENADE_THROW || Animation == SMOKEGRENADE_IDLE || Animation == SMOKEGRENADE_DRAW)
        { 
            
Blocked Blocked 1
            
return OrpheuSupercede
        
}    
    }
    else 
    {
        
Blocked 0
        OrpheuUnregisterHook
(HandleGSendWeaponAnimation)
    }
    return 
OrpheuIgnored
}

public 
OrpheuHookReturn:OnSendWeaponAnim_AK47(WeaponAnimationSkipLocal)
{
    static 
Blocked
    
if(Blocked 2)
    {
        if(
Animation == AK47_RELOAD || Animation == AK47_DRAW)
        {
            
Blocked Blocked 1
            
return OrpheuSupercede
        
}
    }
    else 
    {
        
Blocked 0
        OrpheuUnregisterHook
(HandleASendWeaponAnimation)
    }
    return 
OrpheuIgnored
}

public 
CBasePlayer_ItemDeploy(Ent)
{
    
EnableHamForward(HandleCBaseEntity_AK47IdleHook)
}

public 
CBasePlayer_ItemHolster(Ent)
{
    
DisableHamForward(HandleCBaseEntity_AK47IdleHook)

I don't know when we should unregister the forward, so I counted how many animations are blocked(game send two, so...). If this is still not enough I will try to call ShootSmokeGrenade manually and see how well it works.

The signature:
Code:
{
    "name"    : "SendWeaponAnim",
    "class"   : "CBasePlayerWeapon",
    "library" : "mod",
    "arguments" :
    [
        {
            "type" : "int"
        },
        {
            "type" : "int"
        }
    ],
    "indexes" : 
    [
        {
            "os"    : "windows",
            "mod"   : "cstrike",
            "value" : 85
        },
        {
            "os"    : "linux",
            "mod"   : "cstrike",
            "value" : 87
        }
    ]
}
The enums are from CSSDK, you find them in the weapon code.
Faking the grenade is too much work and will be inneficient, but what you have to do is to create a grenade, redo the vectors calculations from the wpn_smokegrenade/hegrende/flashbang code and give it a velocity(see a nice example in my ThrowableC4 plugin).
__________________

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

I did not read all, but If I understand, OP wants: You have grenades (he, flash, smoke) in your inventory, and while you're holding a weapon, once you +attack2, it should throw a grenade from your inventory, and the grenade type can be selected through a command, right?

If so, how animation should be handled? Is the weapn should disappear to run the throwing animation and then next the weapon deploy animation is played?
__________________

Last edited by Arkshine; 08-23-2015 at 08:08.
Arkshine 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 16:41.


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