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

[STOCK] cs_drop_user_weapon


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 07-23-2016 , 01:21   [STOCK] cs_drop_user_weapon
Reply With Quote #1

cs_drop_user_weapon

This stock is specify for Counter-Strike, it's a little stock based on 'ham_strip_weapon' one, honestly being i just take that one and edit it for making something else and add some optimizations.

You need to note that this stock already contain some checks for safety ( Like if user is alive or if has already the weapon ) so you will need just to put directly the function without any checks.

* As Hamlet says, what's the difference betwen this and ham_strip_weapon, As i say not so much because ham_strip_weapon is the original, i take it, modifing and making something different, but let's see a few differences betwen that one and mine :
  • You can DROP the weapon or if you want you also can STRIP IT( Remove/destroy ).
  • Return properly the weapon Entity ID.
  • Comparing the Nades using the 'Bits' insteand of CSW_ weapons.

For my this list is useless, you have here the stock, just open and see the diferences, have fun.

Credits: Bugsy(helping me with previous stock) & Avalanche( The original author ).


The stock:
Doc & Code


Example
Code:
    // Striping USP from user inventory:     cs_drop_user_weapon(id, "weapon_usp", 1);     // Droping glock without striping it.     cs_drop_user_weapon( id, "weapon_glock18", 0 );     // Striping a nade( Note that you always need to put "1" for bStrip when you deals with Nades, because nades can't be just dropped, you really need to strip it.     cs_drop_user_weapon( id, "weapon_hegrenade", 1 )


Modules Required
- Amxmodx
- Hamsandwich
- Cstrike
- Fakemeta

A Plugin Way
- You may note with this 'stock' you can not drop nades or knife ( Only striping them by setting the 3rd parameter as 1 ) But i made a shourt plugin wich enable all the time droping nades/knife and include the native cs_drop_user_weapon + a little forward called when you drop a weapon, just go here.

- But you may prefer this plugin instead of my stock/plugin native because it's much better coded and stable to use, thanks.

Changelog
1.0 - Launched.
1.1 - Added Bugsy 'if' condition modified,
1.2 - Some optimizations.
Have fun!
Attached Files
File Type: sma Get Plugin or Get Source (EXAMPLE_cs_drop_user_weapon.sma - 479 views - 1.3 KB)

Last edited by Craxor; 07-27-2016 at 15:29.
Craxor is offline
Send a message via ICQ to Craxor
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-23-2016 , 21:41   Re: [STOCK] cs_drop_user_weapon
Reply With Quote #2

I would shift the conditions in this to make the natives get called last.

Code:
if( is_user_alive( id ) && user_has_weapon( id, WeaponId ) && WeaponId < 30 && WeaponId > 0  ) to if( ( 0 < WeaponId < 30 ) && is_user_alive( id ) && user_has_weapon( id, WeaponId ) )
__________________
Bugsy is offline
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 07-24-2016 , 04:32   Re: [STOCK] cs_drop_user_weapon
Reply With Quote #3

AFAIK when stripping primary weapon you need to set 'm_fHasPrimary' offset to 0. Otherwise player won't be able to pick other primary weapons up.
__________________

NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-24-2016 , 04:39   Re: [STOCK] cs_drop_user_weapon
Reply With Quote #4

Basically, what you did is take ham_strip_weapons and add engclient_cmd( id, "drop", szWeaponName );.

IMO this is useless. It would be better to just post in original thread, given modification is too small.
Also, what did you optimize?

@NiHiLaNTh, IIRC this was fixed already.
__________________

Last edited by HamletEagle; 07-24-2016 at 04:40.
HamletEagle is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 07-24-2016 , 05:21   Re: [STOCK] cs_drop_user_weapon
Reply With Quote #5

Quote:
Originally Posted by HamletEagle View Post
Basically, what you did is take ham_strip_weapons and add engclient_cmd( id, "drop", szWeaponName );.

IMO this is useless. It would be better to just post in original thread, given modification is too small.
Also, what did you optimize?

@NiHiLaNTh, IIRC this was fixed already.
- Yeap was fixed, because is working pick-up, otherwise i wouldn't post it.

@Bugsy, thanks i will edit it.

- Yes hamlet as i say, i just take some codes from ham_strip_weapon & connor version + added engclient_ and i gave a sense, anyway, just leave it here because i wanne add more stuffs , i will write the differences in first post after i will "bring" more things.


@EDIT: Ok, i modified it have more ideas? Observations?
TO do: I will try to add a knife/nade drop option if is possibile, let me make some documentations.
__________________
Project: Among Us

Last edited by Craxor; 07-24-2016 at 06:00.
Craxor is offline
Send a message via ICQ to Craxor
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-24-2016 , 06:27   Re: [STOCK] cs_drop_user_weapon
Reply With Quote #6

Nade drop is not that easy, if you want to do it properly. The easy way is to hook Ham_CS_Item_CanDrop and altern return value(because there is a check inside CBasePlayer:: DropPlayerItem to see if item can be dropped), but in case you have more than one nade(for example flashbang) you'll drop all of them, not just one.

Game is not made to drop grenades and it gets pretty buggy when doing that. That's why I made this plugin: https://forums.alliedmods.net/showthread.php?p=2428743

For knife, same thing, hook Ham_CS_Item_CanDrop and altern return value. You may need to fix the model, which is just a matter of calling EngFunc_SetModel.
__________________

Last edited by HamletEagle; 07-24-2016 at 06:29.
HamletEagle is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 07-24-2016 , 07:08   Re: [STOCK] cs_drop_user_weapon
Reply With Quote #7

I have just only one problem, i don't know how to formating Ham_CS_Item_CanDrop in ExecuteHam, wich parameters i need to use, i do something like this but isn't working:

Code:
ExecuteHamB( Ham_CS_Item_CanDrop, id, szWeaponName );
Is just gives me bugs, how i need to format it to works?
__________________
Project: Among Us
Craxor is offline
Send a message via ICQ to Craxor
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 07-24-2016 , 08:41   Re: [STOCK] cs_drop_user_weapon
Reply With Quote #8

You don't need to execute it, you need to hook it and alter return value(SetHamReturnInteger). Also, look at function prototype, what you did there is wrong.

Quote:
/**
* Description: Whether or not the player can drop the specified item.
* Forward params: function(this)
* Return type: Integer.
* Execute params: ExecuteHam(Ham_CS_Item_CanDrop, this);
*/
Ham_CS_Item_CanDrop,
"this" is the entity index.

If you need help, ask in scripting help forum. We are getting off-topic.
__________________

Last edited by HamletEagle; 07-24-2016 at 08:43.
HamletEagle is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 07-24-2016 , 08:56   Re: [STOCK] cs_drop_user_weapon
Reply With Quote #9

Quote:
Originally Posted by HamletEagle View Post
You don't need to execute it, you need to hook it and alter return value(SetHamReturnInteger). Also, look at function prototype, what you did there is wrong.


"this" is the entity index.

If you need help, ask in scripting help forum. We are getting off-topic.
Ok thanks, i was looked long time at function prototype, but i was don't know what means "thys", anyway i wil go in scriptin help after make some more test and se if i can solve myself, thank you hamlet

EDit Sorry for this text', i mean how is formated in english ) - When i write it, i just wake up and my english knowledge haven't been up-to-dated ) ).
__________________
Project: Among Us

Last edited by Craxor; 07-24-2016 at 10:16.
Craxor is offline
Send a message via ICQ to Craxor
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 07-24-2016 , 13:34   Re: [STOCK] cs_drop_user_weapon
Reply With Quote #10

  1. Quote:
    Originally Posted by Craxor View Post
    Code:
     because nades can be just dropped, you really need to strip it.
        cs_drop_user_weapon( id, "weapon_hegrenade", 1 )
    -->
    Code:
     because nades cannot be just dropped, you really need to strip it.
        cs_drop_user_weapon( id, "weapon_hegrenade", 1 )
    Looks like the @HamletEagle's Grenade Manager plugin can drop them, so it will works for someone using it.

    Code:
        // Striping a nade. If the server is not using HamletEagle's Grenade Manager plugin, you always need to put "1"     // for bStrip when you deals with Nades, because nades cannot be just dropped, you really need to strip it.     cs_drop_user_weapon( id, "weapon_hegrenade", 1 )
  2. You declare this outside the if:
    Code:
        const NadeBits = ( ( 1 << CSW_HEGRENADE ) | ( 1 << CSW_FLASHBANG ) | ( 1 << CSW_SMOKEGRENADE ) );     if( ( 0 < WeaponId < 30 ) && is_user_alive( id ) && user_has_weapon( id, WeaponId ) )
    But only use/call 'NadeBits' inside it. I would prefer to declare it only inside the conditional when it will be required.
    Code:
        if( ( 0 < WeaponId < 30 ) && is_user_alive( id ) && user_has_weapon( id, WeaponId ) )     {         const NadeBits = ( ( 1 << CSW_HEGRENADE ) | ( 1 << CSW_FLASHBANG ) | ( 1 << CSW_SMOKEGRENADE ) );
  3. Those parameters documentation are missing:
    Code:
    stock cs_drop_user_weapon( id, szWeaponName[]="", bStrip=0, szWeaponNameNoPrefix[]="", maxchars=0 )
  4. Why this parameters have default value? It can be omitted? I don't think so.
    Code:
    stock cs_drop_user_weapon( id, szWeaponName[]="", bStrip=0, szWeaponNameNoPrefix[]="", maxchars=0 )
  5. This parameter have a default value, but you are not specifing it on its documentation.
    Code:
    /**
     * ...
     * @param bStrip: if "1" will strip that weapon not only drop, if "0" will just drop it. If omitted, the default value is 0.
     * ...
     */
    stock cs_drop_user_weapon( id, szWeaponName[]="", bStrip=0, szWeaponNameNoPrefix[]="", maxchars=0 )
    Also, for it I would prefer explicity delaclare its as bool and states it as true and false.
    Code:
    /**
     * ...
     * @param bool:bStrip       if true, will strip that weapon not only drop, if false will just drop it.
     *                          If omitted, the default value is false.
     * ...
     */
    stock cs_drop_user_weapon( id, szWeaponName[]="", bool:bStrip=false, szWeaponNameNoPrefix[]="", maxchars=0 )
  6. If you are not planning to change these parameters inside the function, would be good to declare they are const.
    Code:
    stock cs_drop_user_weapon( const id, const szWeaponName[]="", const bStrip=false, szWeaponNameNoPrefix[]="", const maxchars=0 )
  7. For a documentation tool parser as doxygen, you may consider use its standard pattern and a more elaborated initial description.
    Code:
    /**     * Drops a user weapon.  *  * @param id                The Player Index  * @param szWeaponName[]    The Weapon Name you wanna drop/strip( See Weapon list on <https://wiki.alliedmods.net/Cs_weapons_information>).  * @param bool:bStrip       If true, will strip that weapon not only drop, if false will just drop it. If omitted,  *                          the default value is false.  * @return The weapon entity id.  * @note For Nades drops, you need the HamletEagle's Grenade Manager plugin enabled on the server, otherwise  *       you always need to put true for bStrip when you deals with Nades, because nades cannot be just dropped,  *       you really need to strip it.  */
    For example, the AMXX documentation page: 'https://www.amxmodx.org/api/' uses this standart on its coding files,
    then later running their 'pawn-docgen written by xPaw', the documentation site is automatically genereated parsing
    the source code files. Example file for the AMXX project https://www.amxmodx.org/api/core/__raw
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective

Last edited by addons_zz; 07-24-2016 at 13:59. Reason: misspellings
addons_zz 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 11:39.


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