Raised This Month: $ Target: $400
 0% 

Detecting slot


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
asd13
Member
Join Date: Apr 2009
Old 09-11-2010 , 17:06   Detecting slot
Reply With Quote #1

Is there a way to detect if user has weapon in slot1 or slot2

if has then drop it? : ))
asd13 is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 09-11-2010 , 17:36   Re: Detecting slot
Reply With Quote #2

Code:
#include < amxmodx > #include < fakemeta > #include < hamsandwich > #define m_rpgPlayerItems_Slot0 367 #define m_pNext 42 #define m_iId 43 // get all weapons in slot stock GetWeaponsFromSlot( iPlayer, iSlot, Array:aWeaponEntities=Invalid_Array, Array:aWeaponIDs=Invalid_Array ) {     new iWeaponCount = 0;         if( 1 <= iSlot <= 5 )     {         new iEntity = get_pdata_cbase( iPlayer, m_rpgPlayerItems_Slot0 + iSlot, 5 );                 if( iEntity > 0 )         {             do             {                 if( aWeaponEntities != Invalid_Array )                 {                     ArrayPushCell( aWeaponEntities, iEntity );                 }                 if( aWeaponIDs != InvalidArray )                 {                     ArrayPushCell( aWeaponIDs, get_pdata_int( iEntity, m_iId, 4 ) );                 }                                 iWeaponCount++;             }             while( ( iEntity = get_pdata_cbase( iEntity, m_pNext, 4 ) ) > 0 );         }     }         return iWeaponCount; } // get only the first weapon stock GetWeaponFromSlot( iPlayer, iSlot ) {     return ( 1 <= iSlot <= 5 ) ? get_pdata_cbase( iPlayer, m_rpgPlayerItems_Slot0 + iSlot, 5 ) : -1; }

Code:
// example 1: new Array:aWeaponIDs = ArrayCreate( 1 ); new iCount = GetWeaponsFromSlot( iPlayer, 1, _, aWeaponIDs ); new iWeaponID, szWeaponName[ 32 ]; for( new i = 0; i < iCount; i++ ) {     iWeaponID = ArrayGetCell( aWeaponIDs, i );     get_weaponname( iWeaponID, szWeaponName, charsmax( szWeaponName ) );         engclient_cmd( iPlayer, "drop", szWeaponName ); } ArrayDestroy( aWeaponIDs ); // example 2: new iWeaponEntity = GetWeaponFromSlot( iPlayer, 1 ); if( iWeaponEntity > 0 ) {     new iWeaponID = get_pdata_cbase( iWeaponEntity, m_iId, 4 );         new szWeaponName[ 32 ];     get_weaponname( iWeaponID, szWeaponName, charsmax( szWeaponName ) );         engclient_cmd( iPlayer, "drop", szWeaponName ); }

If you know the player will only have 1 weapon in each slot (some servers have more than 1 primary weapon, for example), then use example #1.
Otherwise, use example #2.

These are the weapon slots:
1 - primary
2 - secondary
3 - knife
4 - grenades (he, flash, smoke)
5 - c4
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
asd13
Member
Join Date: Apr 2009
Old 09-11-2010 , 20:25   Re: Detecting slot
Reply With Quote #3

I dont get a hell. : D

Player has only one weapon in each slot exept he,flash and smoke,
Need to check only slot1 and slot2.
Can some one add? : ))

PHP Code:
#include < amxmodx >
#include < cstrike >
#include < fun >
#include < hamsandwich >

const VipFlags ADMIN_LEVEL_H;

new 
iRound;

public 
plugin_init( ) {
    
RegisterHamHam_Spawn "player" "PlayerSpawned" );
    
    
register_event(    "TextMsg",    "RoundRestart" ,    "a" ,    "2&#Game_C" );
    
register_event"TextMsg",    "RoundRestart" ,    "a" ,    "2&#Game_w" );
    
register_event(    "HLTV" ,    "NewRound" ,        "a" ,    "1=0" ,    "2=0" );
}

public 
RoundRestart( )
    
iRound 0;

public 
NewRound( )
    
iRound++;

public 
PlayerSpawnedid ) {
    if( 
is_user_aliveid ) && ( get_user_flagsid ) & VipFlags ) ) {
        
give_itemid "weapon_hegrenade" );
        
give_itemid "weapon_flashbang" );
        
give_itemid "weapon_smokegrenade" );
        
cs_set_user_bpammoid CSW_FLASHBANG );
        
cs_set_user_armorid 100CS_ARMOR_VESTHELM );
        
        if( 
cs_get_user_teamid ) == CS_TEAM_CT )
            
cs_set_user_defuseid );
        
        if( 
iRound == )
            
SecondaryMenuid );
        else 
            
PrimaryMenuid );
    }
}

public 
PrimaryMenuid ) {
    new 
menu menu_create"Select Weapon:" "PrimaryHandler" );
    
    
menu_additemmenu "M4A1" ,    "1" );
    
menu_additemmenu "AK47" ,    "2" );
    
    if( ( 
iRound ) == )
        
menu_additemmenu "AWP" ,    "3" );
    
    
menu_additemmenu "Secondary" ,    "4" );
    
    
menu_setpropmenu MPROP_EXIT MEXIT_ALL );
    
menu_displayid menu );
}

public 
PrimaryHandlerid menu item) {
    if( 
item == MENU_EXIT ) {
        
menu_destroymenu );
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[6] , iName[64];
    new 
access callback;
    
    
menu_item_getinfomenu item access data ,iName 63 callback );
    
    new 
key str_to_numdata );
    switch( 
key ) {
        case 
1: {
            
give_itemid "weapon_m4a1" );
            
cs_set_user_bpammoid CSW_M4A1 90 );
            
            
SecondaryMenuid );
        }
        case 
2: {
            
give_itemid "weapon_ak47" );
            
cs_set_user_bpammoid CSW_AK47 90 );
            
            
SecondaryMenuid );
        }
        case 
3: {
            
give_itemid "weapon_awp" );
            
cs_set_user_bpammoid CSW_AWP 30 );
            
            
SecondaryMenuid );
        }
        case 
4: {
            
SecondaryMenuid );
        }
    }
    
    
menu_destroymenu );
    return 
PLUGIN_HANDLED;
}

public 
SecondaryMenuid ) {
    new 
menu menu_create"Select Weapon:" "SecondaryHandler" );
    
    
menu_additemmenu "USP" ,    "1" );
    
menu_additemmenu "GLOCK" ,    "2" );
    
menu_additemmenu "DEAGLE" ,    "3" );
    
    
menu_setpropmenu MPROP_EXIT MEXIT_ALL );
    
menu_displayid menu );
}

public 
SecondaryHandlerid menu item) {
    if( 
item == MENU_EXIT ) {
        
menu_destroymenu );
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[6] , iName[64];
    new 
access callback;
    
    
menu_item_getinfomenu item access data ,iName 63 callback );
    
    new 
key str_to_numdata );
    switch( 
key ) {
        case 
1: {
            
give_itemid "weapon_usp" );
            
cs_set_user_bpammoid CSW_USP 100 );
        }
        case 
2: {
            
give_itemid "weapon_glock18" );
            
cs_set_user_bpammoid CSW_GLOCK18 120 );
        }
        case 
3: {
            
give_itemid "weapon_deagle" );
            
cs_set_user_bpammoid CSW_DEAGLE 35 );
        }
    }
    
    
menu_destroymenu );
    return 
PLUGIN_HANDLED;


Last edited by asd13; 09-11-2010 at 21:15.
asd13 is offline
asd13
Member
Join Date: Apr 2009
Old 09-11-2010 , 21:16   Re: Detecting slot
Reply With Quote #4

: ))
asd13 is offline
GXLZPGX
Veteran Member
Join Date: Sep 2009
Old 09-11-2010 , 23:08   Re: Detecting slot
Reply With Quote #5

Suggestions / Requests
__________________
Currently accepting payment US DOLLARS ONLY for custom plugins, contact me through PM.
GXLZPGX is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 09-11-2010 , 23:37   Re: Detecting slot
Reply With Quote #6

Moved to proper forum since OP won't code it him/her-self.

Here's the code you would need:

PHP Code:
#include < amxmodx >
#include < cstrike >
#include < fun >
#include < fakemeta >
#include < hamsandwich >

#define m_rpgPlayerItems_Slot0 367
#define m_iId 43

const VipFlags ADMIN_LEVEL_H;

new 
iRound;

public 
plugin_init( ) {
    
RegisterHamHam_Spawn "player" "PlayerSpawned" );
    
    
register_event(    "TextMsg",    "RoundRestart" ,    "a" ,    "2&#Game_C" );
    
register_event"TextMsg",    "RoundRestart" ,    "a" ,    "2&#Game_w" );
    
register_event(    "HLTV" ,    "NewRound" ,        "a" ,    "1=0" ,    "2=0" );
}

public 
RoundRestart( )
    
iRound 0;

public 
NewRound( )
    
iRound++;

public 
PlayerSpawnedid ) {
    if( 
is_user_aliveid ) && ( get_user_flagsid ) & VipFlags ) ) {
        
give_itemid "weapon_hegrenade" );
        
give_itemid "weapon_flashbang" );
        
give_itemid "weapon_smokegrenade" );
        
cs_set_user_bpammoid CSW_FLASHBANG );
        
cs_set_user_armorid 100CS_ARMOR_VESTHELM );
        
        if( 
cs_get_user_teamid ) == CS_TEAM_CT )
            
cs_set_user_defuseid );
        
        if( 
iRound == )
            
SecondaryMenuid );
        else 
            
PrimaryMenuid );
    }
}

public 
PrimaryMenuid ) {
    new 
menu menu_create"Select Weapon:" "PrimaryHandler" );
    
    
menu_additemmenu "M4A1" ,    "1" );
    
menu_additemmenu "AK47" ,    "2" );
    
    if( ( 
iRound ) == )
        
menu_additemmenu "AWP" ,    "3" );
    
    
menu_additemmenu "Secondary" ,    "4" );
    
    
menu_setpropmenu MPROP_EXIT MEXIT_ALL );
    
menu_displayid menu );
}

public 
PrimaryHandlerid menu item) {
    if( 
item == MENU_EXIT ) {
        
menu_destroymenu );
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[6] , iName[64];
    new 
access callback;
    
    
menu_item_getinfomenu item access data ,iName 63 callback );
    
    new 
key str_to_numdata );
    switch( 
key ) {
        case 
1: {
            
DropWeaponSlotid );
            
give_itemid "weapon_m4a1" );
            
cs_set_user_bpammoid CSW_M4A1 90 );
            
            
SecondaryMenuid );
        }
        case 
2: {
            
DropWeaponSlotid );
            
give_itemid "weapon_ak47" );
            
cs_set_user_bpammoid CSW_AK47 90 );
            
            
SecondaryMenuid );
        }
        case 
3: {
            
DropWeaponSlotid );
            
give_itemid "weapon_awp" );
            
cs_set_user_bpammoid CSW_AWP 30 );
            
            
SecondaryMenuid );
        }
        case 
4: {
            
SecondaryMenuid );
        }
    }
    
    
menu_destroymenu );
    return 
PLUGIN_HANDLED;
}

public 
SecondaryMenuid ) {
    new 
menu menu_create"Select Weapon:" "SecondaryHandler" );
    
    
menu_additemmenu "USP" ,    "1" );
    
menu_additemmenu "GLOCK" ,    "2" );
    
menu_additemmenu "DEAGLE" ,    "3" );
    
    
menu_setpropmenu MPROP_EXIT MEXIT_ALL );
    
menu_displayid menu );
}

public 
SecondaryHandlerid menu item) {
    if( 
item == MENU_EXIT ) {
        
menu_destroymenu );
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[6] , iName[64];
    new 
access callback;
    
    
menu_item_getinfomenu item access data ,iName 63 callback );
    
    new 
key str_to_numdata );
    switch( 
key ) {
        case 
1: {
            
DropWeaponSlotid );
            
give_itemid "weapon_usp" );
            
cs_set_user_bpammoid CSW_USP 100 );
        }
        case 
2: {
            
DropWeaponSlotid );
            
give_itemid "weapon_glock18" );
            
cs_set_user_bpammoid CSW_GLOCK18 120 );
        }
        case 
3: {
            
DropWeaponSlotid );
            
give_itemid "weapon_deagle" );
            
cs_set_user_bpammoid CSW_DEAGLE 35 );
        }
    }
    
    
menu_destroymenu );
    return 
PLUGIN_HANDLED;
}

stock DropWeaponSlotiPlayeriSlot )
{
    new 
iWeaponEntity GetWeaponFromSlotiPlayeriSlot );
    if( 
iWeaponEntity )
    {
        new 
iWeaponID get_pdata_cbaseiWeaponEntitym_iId);
        
        new 
szWeaponName32 ];
        
get_weaponnameiWeaponIDszWeaponNamecharsmaxszWeaponName ) );
        
        
engclient_cmdiPlayer"drop"szWeaponName );
    }
}

stock GetWeaponFromSlotiPlayeriSlot )
{
    return ( 
<= iSlot <= ) ? get_pdata_cbaseiPlayerm_rpgPlayerItems_Slot0 iSlot) : -1;

__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
asd13
Member
Join Date: Apr 2009
Old 09-12-2010 , 04:30   Re: Detecting slot
Reply With Quote #7

Thank you, but the problem is that if select weapon and slot isint free server crashes. : D
Tested on my hlds what runs on my pc. : ))
Tested with bots and without

Last edited by asd13; 09-12-2010 at 04:48.
asd13 is offline
Old 09-13-2010, 11:29
asd13
This message has been deleted by Exolent[jNr]. Reason: Don't bump until 2 weeks have passed since last post.
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 19:47.


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