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

[HELP] Launching Grenades From Weapon


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-20-2015 , 16:17   [HELP] Launching Grenades From Weapon
Reply With Quote #1

Is there a way i can throw a regular cs grenade while holding a weapon?
Depresie is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-20-2015 , 16:19   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #2

Yes, it should be. Get the grenade entity index and execute PrimaryAttack() on it.
__________________
HamletEagle is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-20-2015 , 16:25   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #3

can you show me how please?
something like this you mean?

Code:
public plugin_init() 
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_forward(FM_CmdStart,"fw_CmdStart");
    
    // Add your code here...
}

public fw_CmdStart(id)
{
    if((get_user_button(id) & IN_ATTACK2) && user_has_weapon(id, CSW_HEGRENADE))
    {
        ExecuteHam(Ham_Weapon_PrimaryAttack, ???????)
    }
}

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

When you want to throw a grenade ? How this will be triggered(a command, a button, etc) ?
__________________

Last edited by HamletEagle; 08-21-2015 at 03:49.
HamletEagle is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-21-2015 , 06:52   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #5

no, not by command, since commands requires binds, except if you hook the existing ones, which are already hooked for various stuff
im thinking of hooking secondary attack or right click via fw_CmdStart, but dont worry about them, i can find everything that i need in other plugins.

All i need is just the execute primary attack part, if you could please do, because i never seen ExecuteHam with PrimaryAttack =/ and i couldn't understand how to do it from the documentation.

I tried like this, but the server was crashing

Code:
ExecuteHam(Ham_Weapon_PrimaryAttack, id, CSW_HEGRENADE)
ExecuteHam(Ham_Weapon_PrimaryAttack, CSW_HEGRENADE, id)
ExecuteHam(Ham_Weapon_PrimaryAttack, id, "weapon_hegrenade")

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

I am sure that you have other alternatives for CmdStart, just tell me how you want to trigger this. Also, for any grenade or for he/fg/sg ? Give more details, because this depends on what you really want to do. Anyway, a short example is:

PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>

public plugin_init()
{
    
RegisterHam(Ham_Weapon_SecondaryAttack"weapon_hegrenade""CBaseEntity_SecondaryAttack")
}

public 
CBaseEntity_SecondaryAttack(Entity)
{
    if(
pev_valid(Entity))
    {
        
ExecuteHamB(Ham_Weapon_PrimaryAttackEntity)
    }

You need to use the weapon entity index, not the csw index. If you want to do it by right-click and the weapon has a SecondaryAttack you can hook it, but if not I guess you will have to use WeaponIdle which you should enable in Deploy and disable on Holster. This will be better than CmdStart. I don't want to say more until you provide more details.
__________________

Last edited by HamletEagle; 08-21-2015 at 10:19.
HamletEagle is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-21-2015 , 09:56   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #7

Im trying to do it for all the three grenades, and switching the grenade type via command

but from what i see in your example, i dont understand how to do it by holding an ak, since ham primary attack is registered on the hegrenade only o.O

for the record, im trying to create an extra item weapon based on ak, which can launch the player's grenades by right click ( to avoid the need of switching weapon to grenade, then back to ak )

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

You can hook the WeaponIdle of ak47(as I explained above), set some offsets(like m_flStartThrow for example) to make the game think you will throw the grenade and call PrimaryAttack on it. To get the grenade index it is enough to use new const m_rgpPlayerItems_CBasePlayer[6] = {367, 368, ...}(slot 4, get_pdata_cbase). Then work with the index you just retrieved. If you want all grenades make a loop and retrieve the next grenade from the previous one based on m_pNext = 42 offset. This should work, though I don't have time to make the code and test.
__________________

Last edited by HamletEagle; 08-21-2015 at 12:48.
HamletEagle is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-21-2015 , 14:12   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #9

i never worked with such things, so i have no ideea what are you talking about o.O
if you will have some spare time these days, please write the code here, i will take care of testing no problem
and i will also do some research and get it right if there are bugs etc
thanks
Depresie is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-21-2015 , 15:30   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #10

Try this(untested):
PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>

#define MAX_ITEM_TYPES 6

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

new HamHook:HandleCBaseEntity_AK47IdleHook

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)
            while(
pev_valid(WeaponEnt))
            {
                
set_pdata_cbase(idm_pActiveItemWeaponEntXoPlayer)
                
ExecuteHamB(Ham_Weapon_PrimaryAttackWeaponEnt)
                
                
WeaponEnt get_pdata_cbase(WeaponEntm_pNextXoCBasePlayerItem)
            }
        }
    }
}  

public 
CBasePlayer_ItemDeploy(Ent)
{
    
EnableHamForward(HandleCBaseEntity_AK47IdleHook)
}

public 
CBasePlayer_ItemHolster(Ent)
{
    
DisableHamForward(HandleCBaseEntity_AK47IdleHook)

Probably there are more things to handle, but I don't have time for more. Use this as a base and see what you can do.
__________________

Last edited by HamletEagle; 08-21-2015 at 15:32.
HamletEagle 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 21:48.


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