Raised This Month: $32 Target: $400
 8% 

M79 Grenade Launcher


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   Counter-Strike        Category:   Fun Stuff       
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 08-15-2009 , 03:44   M79 Grenade Launcher
Reply With Quote #1

--- Intro ---
This plugin adds new weapon - M79 Grenade Launcher.You'll have 10 grenades.To launch grenade press attack1 button.To buy grenade launcher say /m79.

--- Credits ---
NiHiLaNTh - Plugin
Cheap_Suit - Adding new weapon
meTaLiCroSS - Weapon touch
joaquimandrade - helped to optimize

--- Changelog ---
v1.0 - First release
v1.1 - Little code optimization

--- Screenshots ---

--- Have Fun ---


Attached Files
File Type: sma Get Plugin or Get Source (weapon_m79.sma - 11664 views - 17.9 KB)
File Type: zip resources.zip (1,020.2 KB, 3058 views)
__________________


Last edited by NiHiLaNTh; 08-21-2009 at 15:35.
NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
KadiR
Unnecessary Member
Join Date: Aug 2008
Location: Zürich / Switzerland
Old 08-15-2009 , 03:51   Re: M79 Grenade Launcher
Reply With Quote #2

looks cool
KadiR is offline
Jon
Veteran Member
Join Date: Dec 2007
Old 08-15-2009 , 05:42   Re: M79 Grenade Launcher
Reply With Quote #3

Looks good, although from the picture it looks like you should add an offset to the Z-axis before setting the origin of the grenade (correct me if I'm wrong, could be the model animation).
Jon is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-15-2009 , 05:56   Re: M79 Grenade Launcher
Reply With Quote #4

There are severals things you could change/improve :


- You should write directly the weapon in register_event(), it will avoid the callback to be called for all weapons, each shots, thus avoiding unnecessary check.
Code:
register_event("CurWeapon", "Event_CurrentWeapon", "be", "1=1", "2=5") // 5 = CSW_XM1014
But I would prefer to use Ham_Item_Deploy from Hamsandwich since it's more appropriate and readable to change the model and play the animation at this time.
- Where are the weapon animations ? Reload, deploy, throw and pullpin ? To play an animation, you should use something (I use fakemeta but feel free to use engine) :
Code:
UTIL_SendWeaponAnimation ( const Player, const Animation ) {     set_pev( id, pev_weaponanim, i_Animation );     message_begin( MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, .player = Player );     write_byte( Animation );     write_byte( pev( Player, pev_body ) );     message_end(); }
You could use an enum to list the animation :
Code:
enum {     m79_idle,     m79_pullpin,     m79_throw,     m79_deploy }; // [...] // For example : UTIL_SendWeaponAnimation( Player, m79_throw );
- To block efficiently the original weapon animation and sounds, you should use m_flNextPrimaryAttack (46) offset instead of using the forward FM_UpdateClientData. The ideal is to use this offset in Ham_Item_Deploy one time. This offset is reset automatically when you switch on another weapon, so no need to reset manually.
Code:
const m_flNextPrimaryAttack = 46; [...] set_pdata_float( Player, m_flNextPrimaryAttack, 9999.0, 4 );
- Why do you use FM_PlayerPostThink when you use already FM_CmdStart ? Just use your code in this one and remove FM_PlayerPostThink.
- Why do you an ugly task and StatusText instead of using the original HUD ammo ?? You should use CurWeapon and AmmoX here. It will be far more efficient and readable. Plus the position of StatusText depends of a client cvar either in left bottom either in the center of your screen which is a pain.
-Instead of using FM_Touch/pfn_touch(), use register_touch() which allow you to register directly the toucher and touched classname. Classname which can be customs. So you can avoid a lot of unnecessary calls.
- For TE_EXPLOSION, use MSG_PAS. No need to show something to players who don't hear the explosion.
- For TE_SMOKE, use MSG_PVS, no need to show something to players who don't see the provided origin.
- get_maxplayers() ; save in a global var the value, because each time in the for(), this native is called.
- ScreenShake ; use MSG_ONE_UNRELIABLE. Also I think it's a bad idea to shake always whatever the distance. You should shake considering the distance and damage done by the explosion.
- To make damage, you should use Ham_TakeDamage and/or Ham_TraceAttack to show some blood.I see you calculate the distance but damage is still the same whatever the distance, it's wrong. And to killed someone use Ham_Killed with the last param 'ShouldGib' set to 2 ( It's GIB_ALWAYS in the HLSDK ). This way you don't need to emulate the explosion gib and blood, it will be done automatically and it's a lot better to let the engine doing its job.
- You should add more cvars to customize the plugin.
That's all for the moment. If you have questions, tell me.

[edit] By the way, since it's for Cs only, you should modify the "Modification".
__________________

Last edited by Arkshine; 08-15-2009 at 06:01.
Arkshine is offline
crazyeffect
Veteran Member
Join Date: Jul 2008
Location: Belgium
Old 08-15-2009 , 06:06   Re: M79 Grenade Launcher
Reply With Quote #5

Do what Arkshine sais

I think it's a cool idea
__________________
crazyeffect is offline
Send a message via MSN to crazyeffect
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 08-15-2009 , 06:29   Re: M79 Grenade Launcher
Reply With Quote #6

Quote:
Originally Posted by Arkshine View Post
- Why do you an ugly task and StatusText instead of using the original HUD ammo ?? You should use CurWeapon and AmmoX here. It will be far more efficient and readable. Plus the position of StatusText depends of a client cvar either in left bottom either in the center of your screen which is a pain.
Can you explain more about this(with example)
About other: I'm working on all you've said above
__________________

NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
eforie
BANNED
Join Date: Dec 2008
Location: Romania
Old 08-15-2009 , 06:36   Re: M79 Grenade Launcher
Reply With Quote #7

nice job.
But how can i modify *.sma to work with only CT buying ?
Only CT could buy this weapon.
Thank`s
eforie is offline
Send a message via Yahoo to eforie Send a message via Skype™ to eforie
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 08-15-2009 , 06:43   Re: M79 Grenade Launcher
Reply With Quote #8

Quote:
Originally Posted by eforie View Post
nice job.
But how can i modify *.sma to work with only CT buying ?
Only CT could buy this weapon.
Thank`s
open SMA and find following lines
Code:
// Buy attempt
public CmdBuyIt(id)
{
    // Plugin not enabled
    if (get_pcvar_num(pOn) == 0)
        return PLUGIN_CONTINUE
    
    // Ignore dead
    if (!is_user_alive(id))
        return PLUGIN_CONTINUE
        
    // Not in buyzone
    if (!cs_get_user_buyzone(id))
    {
        client_print(id, print_center, "You are not in buyzone")
        return PLUGIN_CONTINUE
    }
and after that add lines
Code:
if (cs_get_user_team(id) != CS_TEAM_CT)
      return PLUGIN_CONTINUE
__________________

NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-15-2009 , 06:54   Re: M79 Grenade Launcher
Reply With Quote #9

Quote:
Originally Posted by NiHiLaNTh View Post
Can you explain more about this(with example)
About other: I'm working on all you've said above
I mean, if you weapon has 10 grenades, it should work and show in the Ammo HUD like :

1 | 9
I shoot.
0 | 8
I reload.
1 | 7
I shoot.
0 | 6
I reload.
1 | 5
etc..

And to update in the HUD, Clip (Ammo1) use CurWeapon message and for BpAmmo (Ammo2) use AmmoX message.

Code:
message_begin( MSG_ONE_UNRELIABLE, gMsgCurWeapon, .player = Player ); write_byte( true ); write_byte( CSW_XM1014 ); write_byte( Ammo1 ) message_end(); message_begin ( MSG_ONE_UNRELIABLE, gMsgAmmoX, .player = Player ); write_byte( CSW_XM1014 ); write_byte( Ammo2 ); message_end();
__________________

Last edited by Arkshine; 08-15-2009 at 09:12.
Arkshine is offline
tuty
Veteran Member
Join Date: Jul 2008
Location: UK
Old 08-15-2009 , 07:12   Re: M79 Grenade Launcher
Reply With Quote #10

Quote:
Originally Posted by Arkshine View Post
There are severals things you could change/improve :


- You should write directly the weapon in register_event(), it will avoid the callback to be called for all weapons, each shots, thus avoiding unnecessary check.
Code:
register_event("CurWeapon", "Event_CurrentWeapon", "be", "1=1", "2=5") // 5 = CSW_XM1014

But I would prefer to use Ham_Item_Deploy from Hamsandwich since it's more appropriate and readable to change the model and play the animation at this time.
- Where are the weapon animations ? Reload, deploy, throw and pullpin ? To play an animation, you should use something (I use fakemeta but feel free to use engine) :
Code:
UTIL_SendWeaponAnimation ( const Player, const Animation ) { set_pev( id, pev_weaponanim, i_Animation );

message_begin( MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, .player = Player );
write_byte( Animation );
write_byte( pev( Player, pev_body ) );
message_end();
}


You could use an enum to list the animation : Code:
enum { m79_idle, m79_pullpin, m79_throw, m79_deploy };

// [...] // For example : UTIL_SendWeaponAnimation( Player, m79_throw );


- To block efficiently the original weapon animation and sounds, you should use m_flNextPrimaryAttack (46) offset instead of using the forward FM_UpdateClientData. The ideal is to use this offset in Ham_Item_Deploy one time. This offset is reset automatically when you switch on another weapon, so no need to reset manually.
Code:
const m_flNextPrimaryAttack = 46;
[...] set_pdata_float( Player, m_flNextPrimaryAttack, 9999.0, 4 );


- Why do you use FM_PlayerPostThink when you use already FM_CmdStart ? Just use your code in this one and remove FM_PlayerPostThink.
- Why do you an ugly task and StatusText instead of using the original HUD ammo ?? You should use CurWeapon and AmmoX here. It will be far more efficient and readable. Plus the position of StatusText depends of a client cvar either in left bottom either in the center of your screen which is a pain.
-Instead of using FM_Touch/pfn_touch(), use register_touch() which allow you to register directly the toucher and touched classname. Classname which can be customs. So you can avoid a lot of unnecessary calls.
- For TE_EXPLOSION, use MSG_PAS. No need to show something to players who don't hear the explosion.
- For TE_SMOKE, use MSG_PVS, no need to show something to players who don't see the provided origin.
- get_maxplayers() ; save in a global var the value, because each time in the for(), this native is called.
- ScreenShake ; use MSG_ONE_UNRELIABLE. Also I think it's a bad idea to shake always whatever the distance. You should shake considering the distance and damage done by the explosion.
- To make damage, you should use Ham_TakeDamage and/or Ham_TraceAttack to show some blood.I see you calculate the distance but damage is still the same whatever the distance, it's wrong. And to killed someone use Ham_Killed with the last param 'ShouldGib' set to 2 ( It's GIB_ALWAYS in the HLSDK ). This way you don't need to emulate the explosion gib and blood, it will be done automatically and it's a lot better to let the engine doing its job.
- You should add more cvars to customize the plugin.
That's all for the moment. If you have questions, tell me.

[edit] By the way, since it's for Cs only, you should modify the "Modification".

it takes 10 mins for me to read this =]
__________________
tuty is offline
Send a message via ICQ to tuty Send a message via AIM to tuty
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:36.


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