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

Grenade Drop


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   ALL        Category:   Admin Commands       
Eriurias
Junior Member
Join Date: Sep 2015
Location: Japan, Kawasaki
Old 09-09-2015 , 11:24   Grenade Drop
Reply With Quote #1

Authors: Eriurias & PRoSToTeM@
Version: 2.0

Description: The plugin allows you to drop grenades, like other weapons.

Advantage: The plugin does not create any objects. Everything happens through the original function of GameDLL. The plugin only allows you to drop grenades + corrects drop flashbang grenades.

Used modules:
Fun
Cstrike
Fakemeta
Hamsandwich

My GitHub Repository.
Attached Files
File Type: sma Get Plugin or Get Source (grenade_drop.sma - 485 views - 2.5 KB)

Last edited by Eriurias; 09-10-2015 at 04:40. Reason: Update
Eriurias is offline
Send a message via ICQ to Eriurias Send a message via Skype™ to Eriurias
DeathOrAlive
Member
Join Date: Sep 2015
Location: Sofia, Bulgaria
Old 09-09-2015 , 12:19   Re: Grenade Drop
Reply With Quote #2

Nice job! Can be very useful for some servers!
__________________
Mess with the best, die like the rest!

Quote:
Originally Posted by aron9forever View Post
You're trying to run 11 servers on each core?
You're bringing the word retard to a new level.
DeathOrAlive is offline
Send a message via Skype™ to DeathOrAlive
Eriurias
Junior Member
Join Date: Sep 2015
Location: Japan, Kawasaki
Old 09-09-2015 , 15:25   Re: Grenade Drop
Reply With Quote #3

Quote:
Originally Posted by DeathOrAlive View Post
Nice job! Can be very useful for some servers!
Thank you. : )
Eriurias is offline
Send a message via ICQ to Eriurias Send a message via Skype™ to Eriurias
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-09-2015 , 16:20   Re: Grenade Drop
Reply With Quote #4

Some fast thoughts:
1.Use real offset names, for readability. Instead OFFSET_ACTIVE_ITEM it should be m_pActiveItem.
2.Don't use fakemeta_util. This library is nice for learning but it's horrible slower comparing with fun/cstrike/fakemeta/engine. You should not use it in plugins. For example, instead of fm_give_item use give_item from fun.
3.In ClCmdDrop static is not needed, use new.
4.
PHP Code:
  if (cs_get_user_bpammo(nClientIndexCSW_FLASHBANG) == -1)
            
cs_set_user_bpammo(nClientIndexCSW_FLASHBANG1);
        else if (
cs_get_user_bpammo(nClientIndexCSW_FLASHBANG) == -2)
            
cs_set_user_bpammo(nClientIndexCSW_FLASHBANG2); 
You can do it like that: cs_set_user_bpammo(nClientIndex, CSW_FLASHBANG, abs(cs_get_user_bpammo(nClientIndex, CSW_FLASHBANG)))
That way you will have also a better compatibility with other plugins that allow you to buy more grenades or even give them to players(and this is a common scenario).
5.In fwHamItemCanDrop_Pre make sure the entity is valid.
6.In FM_ClientCommand g_fIsFlashbangActive = false; should be inside the if check. Also the hook should be registered in drop command and unregistered right after it's succesfully executed.

Another thing is that you consider max grenades as being 1/1/2, which can be broken very easy, you should assume that max grenades ammount is unknown and make code a bit more dynamic. Probably not hard, just a matter of changing checks like == 2 to >= 2.
That's at a quick glance, later I will check more.
__________________

Last edited by HamletEagle; 09-10-2015 at 02:40. Reason: Oops, thanks Arkshine, missed that.
HamletEagle is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 09-09-2015 , 16:58   Re: Grenade Drop
Reply With Quote #5

6. No, sizeof is an operator which generates size at compile time.
__________________
Arkshine is offline
Eriurias
Junior Member
Join Date: Sep 2015
Location: Japan, Kawasaki
Old 09-10-2015 , 02:47   Re: Grenade Drop
Reply With Quote #6

Quote:
Originally Posted by HamletEagle View Post
Some fast thoughts:
1.Use real offset names, for readability. Instead OFFSET_ACTIVE_ITEM it should be m_pActiveItem.
2.Don't use fakemeta_util. This library is nice for learning but it's horrible slower comparing with fun/cstrike/fakemeta/engine. You should not use it in plugins. For example, instead of fm_give_item use give_item from fun.
3.In ClCmdDrop static is not needed, use new.
4.
PHP Code:
  if (cs_get_user_bpammo(nClientIndexCSW_FLASHBANG) == -1)
            
cs_set_user_bpammo(nClientIndexCSW_FLASHBANG1);
        else if (
cs_get_user_bpammo(nClientIndexCSW_FLASHBANG) == -2)
            
cs_set_user_bpammo(nClientIndexCSW_FLASHBANG2); 
You can do it like that: cs_set_user_bpammo(nClientIndex, CSW_FLASHBANG, abs(cs_get_user_bpammo(nClientIndex, CSW_FLASHBANG)))
That way you will have also a better compatibility with other plugins that allow you to buy more grenades or even give them to players(and this is a common scenario).
5.In fwHamItemCanDrop_Pre make sure the entity is valid.
6.sizeof(szItemList) should be cached before loop. Trivial, but let's keep good practices.
7.In FM_ClientCommand g_fIsFlashbangActive = false; should be inside the if check. Also the hook should be registered in drop command and unregistered right after it's succesfully executed.

Another thing is that you consider max grenades as being 1/1/2, which can be broken very easy, you should assume that max grenades ammount is unknown and make code a bit more dynamic. Probably not hard, just a matter of changing checks like == 2 to >= 2.
That's at a quick glance, later I will check more.
1. was laziness remember names. However, what a difference.
2. Thanks for the advice. The next time I will consider.
3. Static is faster in Pawn. Examine the AMX Mod X Source code if you do not believe.
4. Thank you for your good advice. =)
5. It is always valid. It same hamsandwich. Or I'm wrong?

7. Yes, you're right, it should be within the conditions. This inattention, sorry.

Last edited by Eriurias; 09-10-2015 at 02:47.
Eriurias is offline
Send a message via ICQ to Eriurias Send a message via Skype™ to Eriurias
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-10-2015 , 03:14   Re: Grenade Drop
Reply With Quote #7

1.I told you, it's about readability. Think that you don't know what this offset does. A way to find out is to search in the sdk(HLSDK/CSSDK if cs related) and to see where it's used. But, I won't find anything with OFFSET_ACTIVE_ITEM, in game it's named m_pActiveItem. For readability and for consistency you should name them correctly(as in game). It helps the others that look into your code.
3.static means that the variable will be initialized only one time, this is usefull in per frame forwards(like AddToFullPack/PreThink etc) or on big arrays when you need to allocate memory only one time, to do not go over stack size. In a case of a command like "drop" that is called only few times per round static is misused. What you gain by using static likely doesn't matter. Don't try to micro-optimize.
5.You can't know what happens with this entity, it's good practice to put proper checks. "It same hamsandwich" not sure to get what you mean, ham only hook and call game virtual functions.

A plugin should work as intended, to be user friendly, to be originall and to have a sane code.

Moreover:
You likely don't need to register the "drop" cmd, just do what you do in ClCmdDrop into fwHamItemCanDrop_Pre. When someone send drop game calls CBasePlayer:: DropPlayerItem, which calls CanDrop() in order to know if it's a dropable item and your fwHamItemCanDrop_Pre hook gets triggered. So CanDrop is fired right after "drop" command. To get the player index use pev_owner.
__________________

Last edited by HamletEagle; 09-10-2015 at 04:34.
HamletEagle is offline
Eriurias
Junior Member
Join Date: Sep 2015
Location: Japan, Kawasaki
Old 09-10-2015 , 04:45   Re: Grenade Drop
Reply With Quote #8

Quote:
UPDATE version 2.0

- Cosmetic changes;
- Small optimization.
Thank to user HamletEagle.
Eriurias is offline
Send a message via ICQ to Eriurias Send a message via Skype™ to Eriurias
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 09-10-2015 , 05:26   Re: Grenade Drop
Reply With Quote #9

I have more suggestions

1.As I said, static is misused in fwHamItemCanDrop_Pre.
2.Name your vars correctly. g_fIsFlashbangActive f stands from float, but the var is a bool, so it should be b.
3.Do you think you can add support for all nades ? Just change g_nRestoreFlashbangCount and g_fIsFlashbangActive into array like g_nRestoreNadeCount[3], g_fIsNadeActive[3], then you can index by the enum you already created. Check entity CSW_* index and decide if you index by HEGRENADE/FLASHBANG/SMOKEGRENADE. That way your code will be more dynamic. If you are not sure how to design this tell me.
4.FM_ClientCommand is called for other commands than "drop". Register it in fwHamItemCanDrop_Pre(instead of init) and unregister the hook right after you do your checks and set bpammo. You could also make sure it's called for drop command(read_argv(0, cmd, charsmax(cmd)) and see if it's "drop").

If you don't understand something ask, don't forget that everything I said can be discussed.
__________________

Last edited by HamletEagle; 09-10-2015 at 05:26.
HamletEagle is offline
Eriurias
Junior Member
Join Date: Sep 2015
Location: Japan, Kawasaki
Old 09-10-2015 , 05:49   Re: Grenade Drop
Reply With Quote #10

Quote:
Originally Posted by HamletEagle View Post
I have more suggestions

1.As I said, static is misused in fwHamItemCanDrop_Pre.
2.Name your vars correctly. g_fIsFlashbangActive f stands from float, but the var is a bool, so it should be b.
3.Do you think you can add support for all nades ? Just change g_nRestoreFlashbangCount and g_fIsFlashbangActive into array like g_nRestoreNadeCount[3], g_fIsNadeActive[3], then you can index by the enum you already created. Check entity CSW_* index and decide if you index by HEGRENADE/FLASHBANG/SMOKEGRENADE. That way your code will be more dynamic. If you are not sure how to design this tell me.
4.FM_ClientCommand is called for other commands than "drop". Register it in fwHamItemCanDrop_Pre(instead of init) and unregister the hook right after you do your checks and set bpammo. You could also make sure it's called for drop command(read_argv(0, cmd, charsmax(cmd)) and see if it's "drop").

If you don't understand something ask, don't forget that everything I said can be discussed.
1. I forgot about it.
2. This is similar to the carping !
3. Because of my poor understanding of English, do not understand you..
4. It is easier to register Post event CanDrop. Again, because of the language barrier, I do not quite understand you..
Eriurias is offline
Send a message via ICQ to Eriurias Send a message via Skype™ to Eriurias
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 20:10.


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