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

[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-28-2015 , 12:57   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #31

This is what I said....
You will need okapi module. I spend so much time on something that I won't ever need.

Note : I know this signatures are ridiculously long, but there are very similar functions, I was not able to get a shorter one. If someone knows a trick for making them shorter I am open to suggestions.

PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <fakemeta>
#include <engine>
#include <okapi>
#include <cstrike>
#include <xs>

#define MAX_ITEM_TYPES 6

new const m_rgpPlayerItems_CBasePlayer[MAX_ITEM_TYPES] = {367368, ...}
const 
XoPlayer 5

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

public plugin_precache()
{
    
m_usCreateSmoke     precache_event(1"events/createsmoke.sc")
    
m_usCreateExplosion precache_event(1"events/createexplo.sc")
}

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
    
    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)
    } 
    
}

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 
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 
className[32]
                
pev(weaponEntpev_classnameclassNamecharsmax(className))
                
                new 
grenadeEntity
                
switch(className[7])
                {
                    case 
's':
                    {
                        
grenadeEntity okapi_call(CGrenade_ShootSmokeGrenadeidvecSrcvecThrow1.5m_usCreateSmoke)
                        
ham_strip_weapon(id"weapon_smokegrenade")
                        
cs_set_user_bpammo(idCSW_SMOKEGRENADEcs_get_user_bpammo(idCSW_SMOKEGRENADE) - 1)
                    }
                    case 
'f':
                    {
                        
grenadeEntity okapi_call(CGrenade_ShootTimedidvecSrcvecThrow1.5)
                        
ham_strip_weapon(id"weapon_flashbang")
                        
cs_set_user_bpammo(idCSW_FLASHBANGcs_get_user_bpammo(idCSW_FLASHBANG) - 1)
                    }
                    case 
'h':
                    {
                        
grenadeEntity okapi_call(CGrenade_ShootTimed2idvecSrcvecThrow1.5get_user_team(id), m_usCreateExplosion)
                        
ham_strip_weapon(id"weapon_hegrenade")
                        
cs_set_user_bpammo(idCSW_HEGRENADEcs_get_user_bpammo(idCSW_HEGRENADE) - 1)
                    }
                }
                
                
set_pev(grenadeEntitypev_velocityvecThrow)
            }
        }
    }
}

stock ham_strip_weapon(id,weapon[])
{
    if(!
equal(weapon,"weapon_",7)) return 0;

    new 
wId get_weaponid(weapon);
    if(!
wId) return 0;

    new 
wEnt;
    while((
wEnt engfunc(EngFunc_FindEntityByString,wEnt,"classname",weapon)) && pev(wEnt,pev_owner) != id) {}
    if(!
wEnt) return 0;

    if(
get_user_weapon(id) == wIdExecuteHamB(Ham_Weapon_RetireWeapon,wEnt);

    if(!
ExecuteHamB(Ham_RemovePlayerItem,id,wEnt)) return 0;
    
ExecuteHamB(Ham_Item_Kill,wEnt);

    
set_pev(id,pev_weapons,pev(id,pev_weapons) & ~(1<<wId));

    
// this block should be used for Counter-Strike:
    /*if(wId == CSW_C4)
    {
        cs_set_user_plant(id,0,0);
        cs_set_user_bpammo(id,CSW_C4,0);
    }
    else if(wId == CSW_SMOKEGRENADE || wId == CSW_FLASHBANG || wId == CSW_HEGRENADE)
        cs_set_user_bpammo(id,wId,0);*/

    
return 1;
}

public 
CBasePlayer_ItemDeploy(Ent)
{
    
EnableHamForward(HandleCBaseEntity_AK47IdleHook)
}

public 
CBasePlayer_ItemHolster(Ent)
{
    
DisableHamForward(HandleCBaseEntity_AK47IdleHook)

This works exactly as you wanted. Edit it as you like.

A few technical notes:
1. I have not used orpheu because it does not support Vector class. It somehow works when calling, but crash when hooking. Even when calling, it does not pass the vectors correctly and you will have to manually set origin, also this fuck up the other params like m_usEvent. okapi does not have this problem.
2. Even with okapi, we need to set velocity manually, but this is not a big deal.

Here are the signatures in orpheu format, in case someone needs them, but you should not:
Spoiler
__________________

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

A signature can be started from where you want. Just matter to adjusted (displacement) if needed.

I'm not sure it's a good idea to use Okapi, it's still in beta, and there is likely some leaked memory.
__________________
Arkshine is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-28-2015 , 13:15   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #33

Quote:
Originally Posted by Arkshine View Post
A signature can be started from where you want. Just matter to adjusted (displacement) if needed.

I'm not sure it's a good idea to use Okapi, it's still in beta, and there is likely some leaked memory.
I was thinking at this too, but I don't think displacement will help. Functions are almost identical, but I will try to start them from there it sets think(different think function).

I know about the memory leak(I was the one who reported it), but I does not happen on normal function, it's related to virtual functions. My throwablec4 runs just fine in linux.
__________________

Last edited by HamletEagle; 08-28-2015 at 13:15.
HamletEagle is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-28-2015 , 15:23   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #34

thanks hamlet, i will give it a try tomorow in the morning i hope
btw, it should work for windows too right? im asking just for testing purposes
Depresie is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-28-2015 , 15:43   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #35

Sure, both linux and windows.
__________________
HamletEagle is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-28-2015 , 15:47   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #36

i have two questions

1.this will work only for smoke grenade right?
2. would it work if the smoke grenade is replaced by explosive flare grenade?
Depresie is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-28-2015 , 15:58   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #37

Will work for every grenade. It does not matter what attributes you set to the grenade as long as the classname is the same.
__________________

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

very nice, im impressed, is exactly what i was looking for, but i have the following issues now

1. If i have more grenades of the same type in the inventory, and i launch grenade by right click, a grenade is launched and the others dissapear from the inventory
2. If i have HE and SMOKE in the inventory and i right click, both of them are throwed one after the other
3. If i have more grenade types, for example HE and SMOKE, and i have more than one HE grenade, after the grenades are being launched, the HE grenade is deployed, but the model remains of the AK ( This doesn't happen if i have Flash and Smoke )

Also, how could i switch betwen grenade type ?

im sorry, i can't get these fixed by myself, right now im looking over your code, and it looks like alien technology for me hahaha

Anyway, you did a great job

Last edited by Depresie; 08-28-2015 at 16:27.
Depresie is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-28-2015 , 16:33   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #39

Do you have already a model with this custom animation? I might give a try.
__________________

Last edited by Arkshine; 08-28-2015 at 16:34.
Arkshine is offline
Depresie
Veteran Member
Join Date: Nov 2013
Old 08-28-2015 , 16:43   Re: [HELP] Launching Grenades From Weapon
Reply With Quote #40

i have a model, but i didnt start working on the custom animation yet..
i didn't have time, i've been pretty busy trying to reproduce a crash and get some error logs out of the snark infector plugin...
i will start working on the custom animation tomorow, and i will post it here

btw, if you have any cool weapon model in mind, let me know, im looking for days for something realy good, but i couldn't find anything that's badass

Last edited by Depresie; 08-28-2015 at 16:46.
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 13:16.


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