Raised This Month: $114 Target: $400
 28% 

[STOCK] give_user_weapon


Post New Thread Reply   
 
Thread Tools Display Modes
Syncron.
Member
Join Date: Dec 2014
Location: Iasi,Romania
Old 02-09-2017 , 03:22   Re: [STOCK] give_user_weapon
Reply With Quote #21

Didn't work with CSW_KNIFE,why?
i'm write:
give_user_weapon(id, CSW_KNIFE )
and after this i'm thinking maybe must to set clip so => give_user_weapon(id, CSW_KNIFE, 1 )
Syncron. is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: ro
Old 02-09-2017 , 04:55   Re: [STOCK] give_user_weapon
Reply With Quote #22

what? you don't need this stock for knives, just do give_item( id, "weapon_knife" );
__________________
amxx for fun
Craxor is offline
Send a message via ICQ to Craxor
Natsheh
Veteran Member
Join Date: Sep 2012
Old 04-26-2017 , 10:25   Re: [STOCK] give_user_weapon
Reply With Quote #23

here's my stock that im using

Includes :- amxmodx & Fakemeta & cstrike

PHP Code:

#if !defined CSW_SHIELD
    #define CSW_SHIELD 2
#endif

stock give_player_weapon(const id, const wIdiClip=0iBPammo=0wpnname[], wLen)
{
    if(!
is_user_alive(id) || !(CSW_P228 <= wId <= CSW_VESTHELM) || iClip || iBPammo 0) return -1;
    
    new 
Float:fOrigin[3], wpnent;
    
pev(idpev_originfOrigin)
    
    switch( 
wId )
    {
        case 
CSW_VESTCSW_VESTHELM:
        {
            
wpnent fm_create_entity("armoury_entity"fOrigin)
            if(!
wpnent) return 0;
            
set_pev(wpnent,pev_spawnflags,SF_NORESPAWN);
            
cs_set_armoury_type(wpnentwId);
            
dllfunc(DLLFunc_Spawnwpnent);
            
copy(wpnnamewLen"Armour")
        }
        case 
CSW_SHIELD:
        {
            
wpnent fm_create_entity("weapon_shield"fOrigin);
            if(!
wpnent) return 0;
            
set_pev(wpnent,pev_spawnflags,SF_NORESPAWN);
            
dllfunc(DLLFunc_Spawnwpnent);
            
copy(wpnnamewLen"Shield");
        }
        default :
        {
            new 
sWpnname[24];
            
get_weaponname(wIdsWpnnamecharsmax(sWpnname))
            
            new 
sWpns[32], wnums;
            new 
bitwpns get_user_weapons(idsWpnswnums);
            
            if(
bitwpns & (1<<wId))
            {
                while ( ((
wpnent engfunc(EngFunc_FindEntityByStringwpnent"classname"sWpnname))) > && pev(wpnent,pev_owner) != id ) { }
                
wpnent = (pev_valid(wpnent) && pev(wpnentpev_owner) == id) ? wpnent:0;
            }
            
            if(!
wpnent)
            {
                
wpnent fm_create_entity(sWpnnamefOrigin);
                if(!
wpnent) return 0;
                
set_pev(wpnent,pev_spawnflags,SF_NORESPAWN);
                
dllfunc(DLLFunc_Spawnwpnent);
            }
            
            
copy(wpnnamewLensWpnname[7]);
            
ucfirst(wpnname);
            
            if(
wId != CSW_HEGRENADE && wId != CSW_SMOKEGRENADE && wId != CSW_FLASHBANG)
                
cs_set_weapon_ammo(wpnentiClip);
            else if(
wId == CSW_C4cs_set_user_plant(id);
            
            
cs_set_user_bpammo(idwIdiBPammo);
        }
    }
    
    return 
1;
}

stock fm_create_entity(const Entname[], Float:fOrigin[3])
{
    new 
wEnt engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocStringEntname));
    
    if(!
pev_valid(wEnt)) return -1;
    
    
engfunc(EngFunc_SetOriginwEntfOrigin);
    
    return 
wEnt

__________________
@Jailbreak Main Mod v2.6.5 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Last edited by Natsheh; 04-26-2017 at 10:26.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Depresie
Veteran Member
Join Date: Nov 2013
Old 05-02-2017 , 15:08   Re: [STOCK] give_user_weapon
Reply With Quote #24

Quote:
Originally Posted by Craxor View Post
what? you don't need this stock for knives, just do give_item( id, "weapon_knife" );
You should also add the knife into this, regardless..
__________________
Depresie is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: ro
Old 05-02-2017 , 23:04   Re: [STOCK] give_user_weapon
Reply With Quote #25

why? The goal of this is scop is to sett ammo/bpammo without problems/errors, knives can't have ammo.
__________________
amxx for fun
Craxor is offline
Send a message via ICQ to Craxor
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-06-2017 , 10:59   Re: [STOCK] give_user_weapon
Reply With Quote #26

I agree with them, Craxor. This way it covers everything. The end user may attempt to use it with knife not knowing it was not built to handle knives. The function name is not indicative of this.
__________________
Bugsy is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: ro
Old 05-11-2017 , 07:28   Re: [STOCK] give_user_weapon
Reply With Quote #27

I will update it, btw, how can i give an error at compilation if user use CSW_KNIFE? assert wilt work ?
__________________
amxx for fun
Craxor is offline
Send a message via ICQ to Craxor
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-11-2017 , 19:01   Re: [STOCK] give_user_weapon
Reply With Quote #28

Just make it give knife... and no

Edit: It works with knife, I just tested it with this: give_user_weapon( id , CSW_KNIFE );

However, you should prevent the give ammo natives from being called:
Code:
give_user_weapon( index , iWeaponTypeID , iClip=0 , iBPAmmo=0 , szWeapon[]="" , maxchars=0 ) {     if ( !( CSW_P228 <= iWeaponTypeID <= CSW_P90 ) || ( iClip < 0 ) || ( iBPAmmo < 0 ) || !is_user_alive( index ) )         return -1;         new szWeaponName[ 20 ] , iWeaponEntity , bool:bIsGrenade;         const GrenadeBits = ( ( 1 << CSW_HEGRENADE ) | ( 1 << CSW_FLASHBANG ) | ( 1 << CSW_SMOKEGRENADE ) | ( 1 << CSW_C4 ) );         if ( ( bIsGrenade = bool:!!( GrenadeBits & ( 1 << iWeaponTypeID ) ) ) )         iClip = clamp( iClip ? iClip : iBPAmmo , 1 );         get_weaponname( iWeaponTypeID , szWeaponName , charsmax( szWeaponName ) );         if ( ( iWeaponEntity = user_has_weapon( index , iWeaponTypeID ) ? find_ent_by_owner( -1 , szWeaponName , index ) : give_item( index , szWeaponName ) ) > 0 )     {
        if ( iWeaponTypeID != CSW_KNIFE )
        {
            if ( iClip && !bIsGrenade )                 cs_set_weapon_ammo( iWeaponEntity , iClip );                     if ( iWeaponTypeID == CSW_C4 )                 cs_set_user_plant( index , 1 , 1 );             else                 cs_set_user_bpammo( index , iWeaponTypeID , bIsGrenade ? iClip : iBPAmmo );
        }
                if ( maxchars )             copy( szWeapon , maxchars , szWeaponName[7] );     }         return iWeaponEntity; }
__________________

Last edited by Bugsy; 05-11-2017 at 21:43.
Bugsy is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: ro
Old 05-12-2017 , 04:29   Re: [STOCK] give_user_weapon
Reply With Quote #29

Doneeeeeeeee
__________________
amxx for fun
Craxor is offline
Send a message via ICQ to Craxor
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-12-2017 , 19:24   Re: [STOCK] give_user_weapon
Reply With Quote #30

While I agree that give_item() is more proper and efficient for giving a knife, the function does handle knives so I don't think your big red blurb is appropriate. Also, it does cover the alive check which is a convenience to the scripter.

I would also give the code a heading of 'Function' instead of 'Stock'. Basically you should only ever use a 'stock' defined function or variable in an include file. What many people refer to as 'stocks' on these forums are actually functions. Stock simply makes the function/variable not get compiled into the binary (.amxx) if it is never used in the code--hence it is appropriate in include files since include files have a ton of code that scripters may only use 1 or 2 functions from.

From the Pawn language guide:
Code:
Stock declarations

A global variable may be declared as “stock”. A stock declaration is one 
that the parser may remove or ignore if the variable turns out not to be 
used in the program.

Stock variables are useful in combination with stock functions.  A public 
variable may be declared as “stock” as well —declaring public variables 
as “public stock” enables you to declare all public variables that a host 
application provides in an include file, with only those variables that the 
script actually uses winding up in the P-code file.
__________________

Last edited by Bugsy; 05-12-2017 at 19:42.
Bugsy is offline
Reply


Thread Tools
Display Modes

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 22:51.


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