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

[HELP] Launching Grenades From Weapon


Post New Thread Reply   
 
Thread Tools Display Modes
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-29-2015 , 13:45   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #51

I would use +use (with some filtering to catch legal attempt of +use).
Or it could be like holding +attack2 and using +attack to select, then when you release it throws the grenade (could be right after selection or player will have to redo +attack2)
__________________
Arkshine is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-29-2015 , 15:29   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #52

about the +use button is not a so good ideea, since it is being used by the parachute
the second method you mentioned would be a little annoying for the players, because you will have to select it everytime before launching, in some cases it would require 4-5 clicks to launch a grenade

the best choice would be "impulse 201" aka "T" key, but im already using it in other plugins, so the next suitable choice would be "showbriefing", i tested it with chat prints, and it works well

btw arkshine, if you are here, could you look over the snark infector plugin request i made in this section please?
i have some issues with run time errors

Last edited by Depresie; 08-29-2015 at 15:32.
Depresie is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-29-2015 , 17:24   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #53

Quote:
because you will have to select it everytime before launching
Of course that if you select one it will be used by default until you decide to select another one. You know easily when you're holding +attack2 and when key is released. So while you're holding +attack2, you can either release it right away to throw the grenade or selecting first the grenade type by default with +attack1, then once your release it throws the new grenade.
__________________

Last edited by Arkshine; 08-29-2015 at 17:30.
Arkshine is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-29-2015 , 17:31   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #54

mhmm, actualy that's not a bad ideea but how can you detect the IN_ATTACK2 release?
Depresie is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-30-2015 , 04:56   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #55

I did it with the "showbriefing" cmd because you are not yet decided what to use. Later, if you want another way of triggering this let me know. It is easy to know when a button is released(oldbutton contain it, but button no).
PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>
#include <engine>
#include <okapi>
#include <fun>
#include <xs>

#define PluginName    "Throw Grenades"
#define PluginVersion "0.4"
#define PluginAuthor  "HamletEagle"

#define MAX_ITEM_TYPES 6
#define MAX_AMMO_TYPES 32

new const NadeNames[][] =
{
    
"Hegrenade",
    
"Flashbang",
    
"Smokegrenade"
}

new const 
m_rgpPlayerItems_CBasePlayer[MAX_ITEM_TYPES] = {367368, ...}
new const 
m_rgAmmo_CBasePlayer[MAX_AMMO_TYPES]         = {376377, ...}  

const 
m_iPrimaryAmmoType 49
const m_pNext            42
const m_iId              43
const XoPlayer           5
const XoCBasePlayerItem  4

new HamHook:HandleCBaseEntity_AK47IdleHook

new okapi_func:CGrenade_ShootSmokeGrenade
new okapi_func:CGrenade_ShootTimed
new okapi_func:CGrenade_ShootTimed2

new m_usCreateSmoke
new m_usCreateExplosion

new UserGrenadeSelection[33]
new 
Float:UserTimer[33]

public 
plugin_init()
{
    
register_plugin
    
(
        .
plugin_name PluginName,
        .
version     PluginVersion,
        .
author      PluginAuthor
    
)
    
    
m_usCreateSmoke     precache_event(1"events/createsmoke.sc")
    
m_usCreateExplosion precache_event(1"events/createexplo.sc")
    
    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
    
    new 
CGrenade_FunctionAddress
    
    
new const ShootSmokeGrenadeSignature[] = 
    {
        
0x56,0x57,0xFF,0xDEF,0xDEF,0xDEF,0xDEF,0xDEF,0x85,0xDEF,0x75,0xDEF,0x33,0xDEF,0xEB,
        
0xDEF,0x8D,0xDEF,0xDEF,0xDEF,0xDEF,0xDEF,0x8B,0xDEF,0xDEF,0xDEF,0xDEF,0xDEF,0x85,
        
0xDEF,0x74,0xDEF,0x8B,0xDEF,0xDEF,0x85,0xDEF,0x75,0xDEF,0x68,0xDEF,0xDEF,0xDEF,
        
0xDEF,0x50,0xFF,0xDEF,0xDEF,0xDEF,0xDEF,0xDEF,0x8B,0xDEF,0x83,0xDEF,0xDEF,0x85,
        
0xDEF,0x74,0xDEF,0x8B,0xDEF,0xE8,0xDEF,0xDEF,0xDEF,0xDEF,0xC7,0xDEF,0xDEF,0xDEF,
        
0xDEF,0xDEF,0xEB,0xDEF,0x33,0xDEF,0x89,0xDEF,0xDEF,0x8B,0xDEF,0x8B,0xDEF,0xFF,0xDEF,
        
0x8B,0xDEF,0xDEF,0x8D,0xDEF,0xDEF,0xDEF,0x51,0x52,0xE8,0xDEF,0xDEF,0xDEF,0xDEF,0x8B,
        
0xDEF,0xDEF,0x8B,0xDEF,0xDEF,0xDEF,0x8B,0xDEF,0xDEF,0xDEF,0x83,0xDEF,0xDEF,0xD9,0xDEF,0xDEF,0xDEF,0x89,
        
0xDEF,0x8B,0xDEF,0xDEF,0xDEF,0x83,0xDEF,0xDEF,0x89,0xDEF,0xDEF,0x89,0xDEF,0xDEF,0x8B,0xDEF,0xDEF,0xDEF,
        
0x8B,0xDEF,0xDEF,0x8D,0xDEF,0xDEF,0x83,0xDEF,0xDEF,0x8B,0xDEF,0x89,0xDEF,0x8B,0xDEF,0xDEF,0x89,0xDEF,
        
0xDEF,0x8B,0xDEF,0xDEF,0x89,0xDEF,0xDEF,0x8B,0xDEF,0xDEF,0x8B,0xDEF,0xDEF,0xDEF,0xDEF,0xDEF,0x66
    
}
    
    new const 
ShootSmokeGrenadeSymbol[] = "_ZN8CGrenade17ShootSmokeGrenadeEP9entvars_s6VectorS2_ft"
    
    
if
    ( 
        (
CGrenade_FunctionAddress okapi_mod_get_symbol_ptr(ShootSmokeGrenadeSymbol)) || 
        (
CGrenade_FunctionAddress okapi_mod_find_sig(ShootSmokeGrenadeSignaturesizeof ShootSmokeGrenadeSignature)) 
    ) 
    { 
        
CGrenade_ShootSmokeGrenade okapi_build_function(CGrenade_FunctionAddressarg_cbasearg_entvarsarg_vecarg_vecarg_floatarg_int)
    } 

    new const 
ShootTimed2Signature[] = 
    {
        
0x83,0xDEF,0xDEF,0x56,0x57,0xFF,0xDEF,0xDEF,0xDEF,0xDEF,0xDEF,0x85,0xDEF,0x75,
        
0xDEF,0x33,0xDEF,0xEB,0xDEF,0x8D,0xDEF,0xDEF,0xDEF,0xDEF,0xDEF,0x8B,0xDEF,0xDEF,0xDEF,
        
0xDEF,0xDEF,0x85,0xDEF,0x74,0xDEF,0x8B,0xDEF,0xDEF,0x85,0xDEF,0x75,0xDEF,0x68,0xDEF,0xDEF,0xDEF,
        
0xDEF,0x50,0xFF,0xDEF,0xDEF,0xDEF,0xDEF,0xDEF,0x8B
    
}
    
    new const 
ShootTimed2Symbol[] = "_ZN8CGrenade11ShootTimed2EP9entvars_s6VectorS2_fit"
    
    
if
    ( 
        (
CGrenade_FunctionAddress okapi_mod_get_symbol_ptr(ShootTimed2Symbol)) || 
        (
CGrenade_FunctionAddress okapi_mod_find_sig(ShootTimed2Signaturesizeof ShootTimed2Signature)) 
    ) 
    { 
        
CGrenade_ShootTimed2 okapi_build_function(CGrenade_FunctionAddressarg_cbasearg_entvarsarg_vecarg_vecarg_floatarg_intarg_int)
    } 
    
    new const 
ShootTimedSignature[] = 
    {
        
0x56,0xDEF,0xFF,0xDEF,0xDEF,0xDEF,0xDEF,0xDEF,0x85,0xDEF,0x75,0xDEF,0x33,0xDEF,
        
0xEB,0xDEF,0x8D,0xDEF,0xDEF,0xDEF,0xDEF,0xDEF,0x8B,0xDEF,0xDEF,0xDEF,0xDEF,0xDEF,
        
0x85,0xDEF,0x74,0xDEF,0x8B,0xDEF,0xDEF,0x85,0xDEF,0x75,0xDEF,0x68,0xDEF,0xDEF,0xDEF,
        
0xDEF,0x50,0xFF,0xDEF,0xDEF,0xDEF,0xDEF,0xDEF,0x8B,0xDEF,0x83,0xDEF,0xDEF,0x85,0xDEF,
        
0x74,0xDEF,0x8B,0xDEF,0xE8,0xDEF,0xDEF,0xDEF,0xDEF,0xC7,0xDEF,0xDEF,0xDEF,0xDEF,0xDEF,
        
0xEB,0xDEF,0x33,0xDEF,0x89,0xDEF,0xDEF,0x8B,0xDEF,0x8B,0xDEF,0xFF,0xDEF,0x8B,0xDEF,0xDEF,
        
0x8D,0xDEF,0xDEF,0xDEF,0x51,0x52,0xE8,0xDEF,0xDEF,0xDEF,0xDEF,0x8B,0xDEF,0xDEF,0x8B,0xDEF,
        
0xDEF,0xDEF,0x8B,0xDEF,0xDEF,0xDEF,0x83,0xDEF,0xDEF,0xD9,0xDEF,0xDEF,0xDEF,0x89,0xDEF,0x8B,
        
0xDEF,0xDEF,0xDEF,0x83,0xDEF,0xDEF,0x89,0xDEF,0xDEF,0x89,0xDEF,0xDEF,0x8B,0xDEF,0xDEF,0xDEF,
        
0x8B,0xDEF,0xDEF,0x8D,0xDEF,0xDEF,0x83,0xDEF,0xDEF,0x8B,0xDEF,0x89,0xDEF,0x8B,0xDEF,0xDEF,0x89,
        
0xDEF,0xDEF,0x8B,0xDEF,0xDEF,0x89,0xDEF,0xDEF,0x8B,0xDEF,0xDEF,0x8B,0xDEF,0xDEF,0xDEF,0xDEF,0xDEF,
        
0x89,0xDEF,0xDEF,0xDEF,0xDEF,0xDEF,0x8B
    
}
    
    new const 
ShootTimedSymbol[] = "_ZN8CGrenade10ShootTimedEP9entvars_s6VectorS2_f"
    
    
if
    ( 
        (
CGrenade_FunctionAddress okapi_mod_get_symbol_ptr(ShootTimedSymbol)) || 
        (
CGrenade_FunctionAddress okapi_mod_find_sig(ShootTimedSignaturesizeof ShootTimedSignature)) 
    ) 
    { 
        
CGrenade_ShootTimed okapi_build_function(CGrenade_FunctionAddressarg_cbasearg_entvarsarg_vecarg_vecarg_float)
    } 
    
    
register_clcmd("showbriefing""ClientCommand_ShowBriefing")
}

public 
ClientCommand_ShowBriefing(id)
{
    if(
<= UserGrenadeSelection[id] < 2)
    {
        
UserGrenadeSelection[id] = UserGrenadeSelection[id] + 1
    
}
    else 
    {
        
UserGrenadeSelection[id] = 0
    
}
    
    
client_print(idprint_center"You have selected %s"NadeNames[UserGrenadeSelection[id]])
    return 
PLUGIN_HANDLED
}

public 
CBaseEntity_AK47Idle(Entity)
{
    if(
pev_valid(Entity))
    {
        new 
id pev(Entitypev_owner)
        new 
Float:CurrentGameTime get_gametime()
        
        if((
pev(idpev_button) & IN_ATTACK2) && (CurrentGameTime UserTimer[id]))
        {
            new 
NeededCSWId
            
            
switch(UserGrenadeSelection[id])
            {
                case 
0:
                {
                    
NeededCSWId CSW_HEGRENADE
                
}
                case 
1:
                {
                    
NeededCSWId CSW_FLASHBANG
                
}
                case 
2:
                {
                    
NeededCSWId CSW_SMOKEGRENADE
                
}
            }
            
            new 
weaponEnt get_pdata_cbase(idm_rgpPlayerItems_CBasePlayer[4], XoPlayer)
            while(
pev_valid(weaponEnt))
            {
                if(
get_pdata_int(weaponEntm_iIdXoCBasePlayerItem) == NeededCSWId)
                {
                    break
                }
                
weaponEnt get_pdata_cbase(weaponEntm_pNextXoCBasePlayerItem)
            }
            
            if(
pev_valid(weaponEnt))
            {
                new 
Float:angleThrow[3]
                new 
Float:viewAngle[3]; pev(idpev_v_angleviewAngle)
                new 
Float:punchAngle[3]; pev(idpev_punchanglepunchAngle)
                
xs_vec_add(viewAnglepunchAngleangleThrow)

                if(
angleThrow[0] < 0)
                {
                    
angleThrow[0] = -10 angleThrow[0] * ((90 10) / 90.0)
                }
                else
                {
                    
angleThrow[0] = -10 angleThrow[0] * ((90 10) / 90.0)
                }

                new 
Float:velocityMulty = (90 angleThrow[0]) * 6

                
if(velocityMulty 750.0)
                {
                    
velocityMulty 750.0
                
}
                
                new 
Float:Direction[3]
                
engfunc(EngFunc_MakeVectorsangleThrow)
                
global_get(glb_v_forwardDirection)
                
                new 
Float:vecSrc[3]
                new 
Float:playerOrigin[3]; pev(idpev_originplayerOrigin)
                new 
Float:playerViewOfs[3]; pev(idpev_view_ofsplayerViewOfs)
                
                
xs_vec_add(playerOriginplayerViewOfsvecSrc)
                
xs_vec_mul_scalar(Direction16.0Direction)
                
xs_vec_add(vecSrcDirectionvecSrc)
                
                new 
Float:vecThrow[3]
                new 
Float:playerVelocity[3]; pev(idpev_velocityplayerVelocity)
                
                
xs_vec_div_scalar(Direction16.0Direction)
                
xs_vec_mul_scalar(DirectionvelocityMultyDirection)
                
xs_vec_add(DirectionplayerVelocityvecThrow)
                
                new 
grenadeEntity
                
switch(UserGrenadeSelection[id])
                {
                    case 
0:
                    {
                        
grenadeEntity okapi_call(CGrenade_ShootTimed2idvecSrcvecThrow1.5get_user_team(id), m_usCreateExplosion)
                    }
                    case 
1:
                    {
                        
grenadeEntity okapi_call(CGrenade_ShootTimedidvecSrcvecThrow1.5)
                    }
                    case 
2:
                    {
                        
grenadeEntity okapi_call(CGrenade_ShootSmokeGrenadeidvecSrcvecThrow1.5m_usCreateSmoke)
                    }
                }
                
                new 
ammoIndex get_pdata_int(weaponEntm_iPrimaryAmmoTypeXoCBasePlayerItem
                
                if(
ExecuteHamB(Ham_RemovePlayerItemidweaponEnt))
                {
                    
ExecuteHamB(Ham_Item_KillweaponEnt)
                }
                
                
set_pev(idpev_weaponspev(idpev_weapons) & ~(1<< NeededCSWId))
                
set_pev(grenadeEntitypev_velocityvecThrow)
                
                new 
setAmmo get_pdata_int(idm_rgAmmo_CBasePlayer[ammoIndex], XoPlayer) - 1
                set_pdata_int
(idm_rgAmmo_CBasePlayer[ammoIndex], setAmmoXoPlayer)
            
                if(
setAmmo 0)
                {
                    new 
weaponName[32]
                    
get_weaponname(NeededCSWIdweaponNamecharsmax(weaponName))    
                    
                    
give_item(idweaponName)
                    
set_pdata_int(idm_rgAmmo_CBasePlayer[ammoIndex], setAmmoXoPlayer)
                }
            }
            
UserTimer[id] = CurrentGameTime 0.1
        
}
    }
}

public 
CBasePlayer_ItemDeploy(Ent)
{
    
EnableHamForward(HandleCBaseEntity_AK47IdleHook)
}

public 
CBasePlayer_ItemHolster(Ent)
{
    
DisableHamForward(HandleCBaseEntity_AK47IdleHook)

The bind is on l, by default HE is choosed. Push "l" one time and it will select flashbang, one more time smoke. After that it will choose He. So the cycle is he -> flash -> smoke. Also the previous bugs should be fixed.
__________________

Last edited by HamletEagle; 08-30-2015 at 04:59.
HamletEagle is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-30-2015 , 07:57   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #56

Still having the following issues

1. Two grenades are launched at the same time ( not of the same type )
2. If the player has more grenades and more grenade types, sometimes one grenade remains deployed in his hand after launching
Depresie is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-30-2015 , 08:05   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #57

1. It's impossible to be different types. I was able to reproduce only with grenades of the same type. Find this line UserTimer[id] = CurrentGameTime + 0.1 and replace 0.1 by 0.3. Tell me if this fix it.
2. Give me some steps to reproduce the issue. I had all grenade types: 2 fl, 1 he(also tried with 2 he) and 1 sg. Everything seems to be ok. You may be running other plugins that do something weird. Try without any custom plugin.
__________________

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

I did, still happens

Here you have more details

1. Two grenades are launched at the same time

- Buy one grenade of each or more then press right click ( doesn't happen if smoke is selected )
- Buy more grenades of the same type then right click ( except for flashbangs and smoke )

2. Grenades remain deployed after launching

- Buy more grenades of the same type ( 3 for HE / 2 for smoke )
Depresie is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-30-2015 , 08:47   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #59

1.
-What I did was: get 1 he, 1 fl, 1 sg. Select he and throw it/select fl and throw it. Everything is ok.
-I got two he grenades. Everything is ok.

2.I made a plugin and got 3 he and 2 smoke. Nothing wrong happen.

Sorry, but I can't reproduce the bugs that you are claiming. Can you test without any custom plugin ?

This is my current source code. Try to recompile, maybe you did something wrong, idk.
Spoiler


Can you be more precise ? Get x y and z grenades. Throw grenade a and b will happen.
__________________

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

I had the older version in the plugins.ini aswell, that was the cause...
Sorry, things are getting a little messy when you have 6 test servers and you work on 10 things at the same time...

Everythings works fine now but i have a suggestion

If player has for example He Grenade type selected, after he runs out of He Grenades, the weapon should automaticaly switch to the next grenade type
Also when he runs out of grenades instead of grenade type it shouw display "No Grenades Available"

I have done the V model of the weapon, i've made the custom animation, reduced textures, configurated the frames of the animations, etc

I've managed to reduce the size of the ressources of the weapon to 400 KB the v model ( the largest ) without affecting the good aspect of the weapon
I have also added sound for the grenade launcher

If you could complete my suggestion above, it would be great, i think i could get the weapon done this night


Last edited by Depresie; 08-30-2015 at 12:15.
Depresie 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 03:40.


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