Raised This Month: $ Target: $400
 0% 

[USEFUL/SNIPPET] CSS Weapon Index's & How to Give/Remove Players Weapons


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mysticssjgoku4
Veteran Member
Join Date: Jan 2005
Location: Chicago Heights, IL
Old 04-12-2008 , 21:50   [USEFUL/SNIPPET] CSS Weapon Index's & How to Give/Remove Players Weapons
Reply With Quote #1

Posting this for reference, because I did not see anyone else do it yet.

If you already have a primary/secondary item, it overwrites whatever was in that slot, with the new weapon specified. So be careful.

Quote:
0-USP
1-Glock
2-Deagle
3-228 Compact
4-Elites
5-Five Seven
6-M4
7-AK47
8-Steyr-Aug
9-Krieg 552
10-IDF Defender
11-Famas
12-Scout
13-SG-550
14-M249 PARA
15-SG-1 Precision Sniper
16-UMP
17-MP5 Navy
18-Benelli M3 (Pump)
19-Benelli M4 (Auto)
20-TMP
21-Mac10
22-P90
23-AWP
24-Grenade (Gas)
25-Grenade (Explosive)
26-Grenade (Flash)
27-C4 BOMB (LOL...)
Code:
new String:g_CS_WClasses[28][13] = {     "usp", //USP     "glock", //Glock     "deagle", //Desert Eagle (deagle)     "p228", //228 Compact     "elite", //Dualies (elite)     "fiveseven", //Five-Seven (fiveseven)     "m4a1", //Maverick M4A1 Colt (m4a1)     "ak47", //AK-47/CV-47 (ak47)     "aug"//Bullpup (aug)     "sg552",    //Krieg 552 (sg552)     "galil",    //Defender (galil)     "famas",    //Clarion (famas)     "scout",    //Scout (scout)     "sg550",    //Krieg Commando (sg550)     "m249", //M249 (m249)     "g3sg1",    //D3/AU1 (g3sg1)     "ump45", //UMP (ump45)     "mp5navy", //MP5 (mp5navy)     "m3", //Pump Shotgun (m3)     "xm1014", //Auto Shotgun (xm1014)     "tmp", //TMP (tmp)     "mac10", //Mac-10 (mac10)     "p90"//P90 (p90)     "awp"//AWP (awp)     "smokegrenade", //Smoke Grenade (smokegrenade)     "hegrenade",    //HE Grenade (hegrenade)     "flashbang",    //Flashbang Granade (flashbang)     "c4"            //rofl? dont know if this is the real classname }; public Action:_giveweapon(id,args) {     if (args < 1)     {         ReplyToCommand(id, "[SM] Usage: sm_giveweapon <weaponid>");         return Plugin_Handled;     }         new String:wid_str[32];     GetCmdArg(1,wid_str,31);         new wid = StringToInt(wid_str);     if(wid > 27)     {         PrintToConsole(id,"[SM] WARNING: Don't be a newb. Weapon Indexes range from 0-27.");         return Plugin_Handled;     }         new String:WClass[32] = "weapon_";     StrCat(WClass,31,g_CS_WClasses[wid]);         GivePlayerItem(id,WClass);     return Plugin_Handled; } public Action:OnPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast) {       new id      = GetClientOfUserId(GetEventInt(event, "userid"));     new Team    = GetClientTeam(id);             if(Team == CS_TEAM_SPECTATOR || Team == CS_TEAM_NONE)         return Plugin_Continue;         if(!IsPlayerAlive(id))         return Plugin_Continue;             for(new i=0;i < 28;i++)     {         RemoveWeaponFromSlot(id, i);     }     return Plugin_Continue; } public bool:RemoveWeaponFromSlot(client, slot) {     //get the entity id of the weapon in the client's slot specified     new bool:isRemoved;     new weapon_entid = GetPlayerWeaponSlot(client,slot);     //attempt to retrieve the weapon's entity id from the slot..     if(weapon_entid >= 0)     {         //get the classname of the weapon         new String:weapon_classname[32];         GetEdictClassname(weapon_entid, weapon_classname, 32);                 if(strcmp(weapon_classname,"weapon_knife") == 0) return true;                 //attempt to remove the weapon         isRemoved = RemovePlayerItem(client,weapon_entid);         RemoveEdict(weapon_entid);         if(isRemoved)         {             PrintToConsole(client,"Removed %s (entid:%d) from slot %d",weapon_classname,weapon_entid,slot);         }         else         {             PrintToConsole(client,"Could NOT remove %s (entid:%d) from slot %d",weapon_classname,weapon_entid,slot);         }     }     else     {         isRemoved = false;         //PrintToConsole(client,"No weapon to remove from slot %d",slot);     }     return isRemoved; }

The "RemoveWeaponFromSlot()" function was taken from somewhere else on this forum, I would post a link to its source, but I could not find it. So just letting you know, it was not my function.


(NOTE: If you are using the spawn function above, remember to hook it in the PluginStart function using "HookEvent("player_spawn", OnPlayerSpawn);")
(SIDENOTE: The function above removes ALL weapons for all slots, if you wish to only remove a weapon by its index, use the opposite command of GivePlayerItem(), RemovePlayerItem() )


Tested and fully functional. C4 is a little weird tho, if you are CT, it gives it to you, and drops it.
__________________


Last edited by mysticssjgoku4; 04-12-2008 at 22:02.
mysticssjgoku4 is offline
Send a message via AIM to mysticssjgoku4 Send a message via MSN to mysticssjgoku4
Davethegreat
Senior Member
Join Date: Nov 2007
Old 04-14-2008 , 07:48   Re: [USEFUL/SNIPPET] CSS Weapon Index's & How to Give/Remove Players Weapons
Reply With Quote #2

Well, I though i'ld edit the above to do HL2DM
Code:
0 -  Gravity Gun
1 - Pistol
2 - 357 Magnum
3 - smg1
4 - ar2
5 - shotgun
6 - crossbow
7 - Grenade
8 - Slam (trip mine)
9 - RPG
10 - Impact Grenades (alt ammo on the smg1)
11 - Orbs (alt ammo on the ar2)
PHP Code:
new String:g_HL_WClasses[11][13] = {
    
"physcannon"//Gravity Gun 
    
"pistol"//Pistol
    
"smg1"// Sub machine gun
    
"ar2"// Combine Assault Rifle
    
"shotgun"//Shotgun
    
"crossbow" //crossbow
    
"fraggrenade"//Grenade
    
"slam"//slam
    
"rpg",  //rpg
    
"smg1_altfire",   //impact grenade
    
"ar2_altfire",  //orb
};

public 
Action:_giveweapon(id,args)
{
    if (
args 1)
    {
        
ReplyToCommand(id"[SM] Usage: sm_giveweapon <weaponid>");
        return 
Plugin_Handled;
    }
    
    new 
String:wid_str[32];
    
GetCmdArg(1,wid_str,31);
    
    new 
wid StringToInt(wid_str);
    if(
wid 11)
    {
        
PrintToConsole(id,"[SM] WARNING: Don't be a newb. Weapon Indexes range from 0-11.");
        return 
Plugin_Handled;
    }
    
    new 
String:WClass[32] = "weapon_";
    
StrCat(WClass,31,g_CS_WClasses[wid]);
    
    
GivePlayerItem(id,WClass);
    return 
Plugin_Handled;


Last edited by Davethegreat; 04-14-2008 at 18:12.
Davethegreat is offline
Send a message via AIM to Davethegreat
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 04-14-2008 , 17:52   Re: [USEFUL/SNIPPET] CSS Weapon Index's & How to Give/Remove Players Weapons
Reply With Quote #3

Davethegreat, why did leave the "OnPlayerSpawn" function if nothing happens in there?
__________________
http://www.nican132.com
I require reputation!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
Davethegreat
Senior Member
Join Date: Nov 2007
Old 04-14-2008 , 18:12   Re: [USEFUL/SNIPPET] CSS Weapon Index's & How to Give/Remove Players Weapons
Reply With Quote #4

Thanks, I meant to remove that.
Davethegreat is offline
Send a message via AIM to Davethegreat
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 18:46.


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