Raised This Month: $32 Target: $400
 8% 

Snippet: CSDM Style Weapons Menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GHW_Chronic
SourceMod Donor
Join Date: Sep 2004
Location: Texas
Old 08-24-2008 , 04:36   Snippet: CSDM Style Weapons Menu
Reply With Quote #1

  • Had to make this for my CTF mod as well which is now successfully released. This portion creates the menus that allow a player to select their weapon from the list and choose to be given that weapon every time they respawn. Now includes a "Random" button and automatically gives infinite ammo.

You have to fill in the blanks:
  • WEAPON_CVAR
  • NADE_CVAR
  • hook weapon_method_menu(id) to when the player has fully spawned
  • AMXX commands amx_mod_addweap & amx_mod_removeweap are included in the code to allow your clients easy ability to remove weapons from the list.

Code:
#include <amxmodx> #include <amxmisc> #include <cstrike> #include <fun> //Remove the '//' on the next line for AMXX 1.76d compadability. //#define amxx176d //CVAR Names #define WEAPON_CVAR "myplugin_weapons" #define NADE_CVAR   "myplugin_nades" //New CS Weapon Constants #define MOD_SCOUT      1  //a #define MOD_XM1014    2 //b #define MOD_MAC10      4  //c #define MOD_AUG   8    //d #define MOD_UMP45      16 //e #define MOD_SG550      32 //f #define MOD_GALIL      64 //g #define MOD_FAMAS      128    //h #define MOD_AWP   256  //i #define MOD_MP5NAVY  512  //j #define MOD_M249        1024    //k #define MOD_M3      2048  //l #define MOD_M4A1        4096    //m #define MOD_TMP   8192 //n #define MOD_G3SG1      16384  //o #define MOD_SG552      32768  //p #define MOD_AK47        65536   //q #define MOD_P90   131072   //r #define MOD_P228        262144  //s #define MOD_ELITE      524288 //t #define MOD_FIVESEVEN      1048576    //u #define MOD_USP   2097152  //v #define MOD_GLOCK18  4194304  //w #define MOD_DEAGLE    8388608   //x #define MOD_VEST        16777216//y #define MOD_VESTHELM        33554432//z static const weapon_names[26][16] = {     "Scout",     "XM1014",     "Mac10",     "Aug",     "UMP",     "SG550",     "Galil",     "Famas",     "AWP",     "MP5Navy",     "M249",     "M3",     "M4A1",     "TMP",     "G3SG1",     "SG552",     "AK47",     "P90",     "P228",     "Elite",     "Fiveseven",     "USP",     "Glock18",     "Deagle",     "VEST",     "VESTHELM" } new allowableweapons, nades new bool:firsttime[33] new bool:ask[33] new weapon_picked[2][33] new cur_offset[33] new options_on_menu[8][33] public plugin_init() {     //     register_clcmd("say guns","cmd_guns")     register_clcmd("say_team guns","cmd_guns")     register_concmd("amx_mod_addweap","cmd_addweap",ADMIN_BAN,"<Weapon> Un-Restricts a weapon from the weapons menu.")     register_concmd("amx_mod_removeweap","cmd_delweap",ADMIN_BAN,"<Weapon> Restricts a weapon from the weapons menu.")     register_menucmd(register_menuid("WeaponMethodMenu"),(1<<0)|(1<<1)|(1<<2),"weapon_method_pushed")     register_menucmd(register_menuid("PrimaryWeaponSelect"),(1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9),"prim_weapons_pushed")     register_menucmd(register_menuid("SecWeaponSelect"),(1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7),"sec_weapons_pushed") #if defined amxx176d     register_cvar(WEAPON_CVAR,"abcdefghijklmnopqrstuvwxyz") #else     allowableweapons = register_cvar(WEAPON_CVAR,"abcdefghijklmnopqrstuvwxyz") #endif #if defined amxx176d     register_cvar(NADE_CVAR,"hhff") #else     nades = register_cvar(NADE_CVAR,"hhff") #endif } //Call this on player spawn public weapon_method_menu(id) {     if(is_user_bot(id))     {         weapon_picked[0][id] = 16         weapon_picked[1][id] = 23         give_weapons(id)     }     else if(firsttime[id])     {         firsttime[id] = false         prim_weapons_menu(id,0)     }     else     {         cur_offset[id] = 0         if(ask[id])         {             show_menu(id,(1<<0)|(1<<1)|(1<<2),"Weapon Selection Method^n^n1. Last Guns^n2. Last Guns + Save^n3. New Guns",-1,"WeaponMethodMenu")         }         else         {             give_weapons(id)         }     } } public weapon_method_pushed(id,key) {     switch(key)     {         case 0:         {             ask[id] = true             give_weapons(id)         }         case 1:         {             client_print(id,print_chat,"[AMXX] Type guns to re-activate the gun menu.")             ask[id] = false             give_weapons(id)         }         case 2:         {             ask[id] = true             prim_weapons_menu(id,0)         }     }     return ; } public prim_weapons_menu(id,offset) {     if(offset<0) offset = 0     new cvar_value[32] #if defined amxx176d     get_cvar_string(WEAPON_CVAR,cvar_value,31) #else     get_pcvar_string(allowableweapons,cvar_value,31) #endif     new flags = read_flags(cvar_value)     new keys, curnum, menu[2048]     for(new i=offset;i<19;i++)     {         if(i==18)         {             options_on_menu[curnum][id] = 24             keys += (1<<curnum)             curnum++             format(menu,2047,"%s^n%d. Random",menu,curnum)             break;         }         else if(flags & power(2,i))         {             options_on_menu[curnum][id] = i             keys += (1<<curnum)             curnum++             format(menu,2047,"%s^n%d. %s",menu,curnum,weapon_names[i])             if(curnum==8)                 break;         }     }     format(menu,2047,"\ySelect Primary Weapon:\w^n^n%s^n",menu)     if(curnum==8 && offset<12)     {         keys += (1<<8)         format(menu,2047,"%s^n9. Next",menu)     }     if(offset)     {         keys += (1<<9)         format(menu,2047,"%s^n0. Back",menu)     }     show_menu(id,keys,menu,-1,"PrimaryWeaponSelect") } public prim_weapons_pushed(id,key) {     if(key<8)     {         weapon_picked[0][id] = options_on_menu[key][id]         cur_offset[id] = 0         sec_weapons_menu(id,0)     }     else     {         if(key==8)             cur_offset[id] += 8         if(key==9)             cur_offset[id] -= 8         prim_weapons_menu(id,cur_offset[id])     }     return ; } public sec_weapons_menu(id,offset) {     if(offset<0) offset = 0     new cvar_value[32] #if defined amxx176d     get_cvar_string(WEAPON_CVAR,cvar_value,31) #else     get_pcvar_string(allowableweapons,cvar_value,31) #endif     new flags = read_flags(cvar_value)     new keys, curnum, menu[2048]     for(new i=18;i<24;i++)     {         if(flags & power(2,i))         {             options_on_menu[curnum][id] = i             keys += (1<<curnum)             curnum++             format(menu,2047,"%s^n%d. %s",menu,curnum,weapon_names[i])         }     }     options_on_menu[curnum][id] = 25     keys += (1<<curnum)     curnum++     format(menu,2047,"%s^n%d. Random",menu,curnum)     format(menu,2047,"\ySelect Secondary Weapon:\w^n^n%s",menu)     show_menu(id,keys,menu,-1,"SecWeaponSelect") } public sec_weapons_pushed(id,key) {     if(key<8)     {         weapon_picked[1][id] = options_on_menu[key][id]     }     give_weapons(id)     return ; } public give_weapons(id) {     strip_user_weapons(id)     give_item(id,"weapon_knife")     new weapon[32]     new csw = csw_contant(weapon_picked[0][id])     get_weaponname(csw,weapon,31)     give_item(id,weapon)     cs_set_user_bpammo(id,csw,999)     csw = csw_contant(weapon_picked[1][id])     get_weaponname(csw,weapon,31)     give_item(id,weapon)     cs_set_user_bpammo(id,csw,999) #if defined amxx176d     get_cvar_string(NADE_CVAR,weapon,31) #else     get_pcvar_string(nades,weapon,31) #endif     new he, flash, smoke     for(new i=0;i<strlen(weapon);i++)     {         switch(weapon[i])         {             case 'h': he++             case 'f': flash++             case 's': smoke++         }     }     if(he) give_item(id,"weapon_hegrenade"), cs_set_user_bpammo(id,CSW_HEGRENADE,he)     if(flash) give_item(id,"weapon_flashbang"), cs_set_user_bpammo(id,CSW_FLASHBANG,flash)     if(smoke) give_item(id,"weapon_smokegrenade"), cs_set_user_bpammo(id,CSW_SMOKEGRENADE,smoke) #if defined amxx176d     get_cvar_string(WEAPON_CVAR,weapon,31) #else     get_pcvar_string(allowableweapons,weapon,31) #endif     new flags = read_flags(weapon)     if(flags & MOD_VESTHELM) cs_set_user_armor(id,100,CS_ARMOR_VESTHELM)     else if(flags & MOD_VEST) cs_set_user_armor(id,100,CS_ARMOR_KEVLAR) } public csw_contant(weapon) {     new num = 29     switch(weapon)     {         case 0: num = 3         case 1: num = 5         case 2: num = 7         case 3: num = 8         case 4: num = 12         case 5: num = 13         case 6: num = 14         case 7: num = 15         case 8: num = 18         case 9: num = 19         case 10: num = 20         case 11: num = 21         case 12: num = 22         case 13: num = 23         case 14: num = 24         case 15: num = 27         case 16: num = 28         case 17: num = 30         case 18: num = 1         case 19: num = 10         case 20: num = 11         case 21: num = 16         case 22: num = 17         case 23: num = 26         case 24:         {             new s_weapon[32] #if defined amxx176d             get_cvar_string(WEAPON_CVAR,s_weapon,31) #else             get_pcvar_string(allowableweapons,s_weapon,31) #endif             new flags = read_flags(s_weapon)             do             {                 num = random_num(0,18)                 if(!(num & flags))                 {                     num = -1                 }             }             while(num==-1)             num = csw_contant(num)         }         case 25:         {             new s_weapon[32] #if defined amxx176d             get_cvar_string(WEAPON_CVAR,s_weapon,31) #else             get_pcvar_string(allowableweapons,s_weapon,31) #endif             new flags = read_flags(s_weapon)             do             {                 num = random_num(18,23)                 if(!(num & flags))                 {                     num = -1                 }             }             while(num==-1)             num = csw_contant(num)         }     }     return num; } public cmd_guns(id) {     ask[id] = true     weapon_method_menu(id) } public cmd_delweap(id,level,cid) {     if(!cmd_access(id,level,cid,2))     {         return PLUGIN_HANDLED     }     new arg[32]     read_argv(1,arg,31)     new cvar_value[32] #if defined amxx176d     get_cvar_string(WEAPON_CVAR,cvar_value,31) #else     get_pcvar_string(allowableweapons,cvar_value,31) #endif     new flags = read_flags(cvar_value)     for(new i=0;i<26;i++)     {         if(equali(arg,weapon_names[i]))         {             new remove_flag = power(2,i)             if(flags & remove_flag)             {                 console_print(id,"[AMXX] Removing weapon %s from the choice list.",weapon_names[i])                 flags -= remove_flag                 get_flags(flags,cvar_value,31)                 set_cvar_string(WEAPON_CVAR,cvar_value)             }             else             {                 console_print(id,"[AMXX] Weapon %s is already off choice list.",weapon_names[i])                             }             break;         }     }     return PLUGIN_HANDLED } public cmd_addweap(id,level,cid) {     if(!cmd_access(id,level,cid,2))     {         return PLUGIN_HANDLED     }     new arg[32]     read_argv(1,arg,31)     new cvar_value[32] #if defined amxx176d     get_cvar_string(WEAPON_CVAR,cvar_value,31) #else     get_pcvar_string(allowableweapons,cvar_value,31) #endif     for(new i=0;i<26;i++)     {         if(equali(arg,weapon_names[i]))         {             new flags = read_flags(cvar_value)             new add_flag = power(2,i)             if(!(flags & add_flag))             {                 console_print(id,"[AMXX] Adding weapon %s to the choice list.",weapon_names[i])                 flags += add_flag                 get_flags(flags,cvar_value,31)                 set_cvar_string(WEAPON_CVAR,cvar_value)             }             else             {                 console_print(id,"[AMXX] Weapon %s is already on choice list.",weapon_names[i])                             }             break;         }     }     return PLUGIN_HANDLED }
GHW_Chronic is offline
Send a message via AIM to GHW_Chronic
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 10-02-2008 , 08:38   Re: Snippet: CSDM Style Weapons Menu
Reply With Quote #2

maybe better do
PHP Code:
#if defined amxx176d
    
register_cvar(WEAPON_CVAR,"abcdefghijklmnopqrstuvwxyz")
#else
    
allowableweapons register_cvar(WEAPON_CVAR,"abcdefghijklmnopqrstuvwxyz")
#endif
#if defined amxx176d
    
register_cvar(NADE_CVAR,"hhff")
#else
    
nades register_cvar(NADE_CVAR,"hhff")
#endif 
->
PHP Code:
#if defined amxx176d
    
register_cvar(WEAPON_CVAR,"abcdefghijklmnopqrstuvwxyz")
    
register_cvar(NADE_CVAR,"hhff")
#else
    
allowableweapons register_cvar(WEAPON_CVAR,"abcdefghijklmnopqrstuvwxyz")
    
nades register_cvar(NADE_CVAR,"hhff")
#endif 
__________________
xPaw is offline
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 10-02-2008 , 12:58   Re: Snippet: CSDM Style Weapons Menu
Reply With Quote #3

oh this is exelent
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
Orangutanz
Veteran Member
Join Date: Apr 2006
Old 10-04-2008 , 03:44   Re: Snippet: CSDM Style Weapons Menu
Reply With Quote #4

CVAR pointers were introduced from 1.7.0, so why is there a restriction against 1.7.6d
__________________
|<-- Retired from everything Small/Pawn related -->|
You know when you've been Rango'd
Orangutanz is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 10-04-2008 , 03:52   Re: Snippet: CSDM Style Weapons Menu
Reply With Quote #5

Quote:
Originally Posted by Orangutanz View Post
CVAR pointers were introduced from 1.7.0, so why is there a restriction against 1.7.6d
Not for (setting ?) strings.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Orangutanz
Veteran Member
Join Date: Apr 2006
Old 10-04-2008 , 04:03   Re: Snippet: CSDM Style Weapons Menu
Reply With Quote #6

set_pcvar_string was added to AMXX 1.8.0 but this isn't used in the above code/example!
__________________
|<-- Retired from everything Small/Pawn related -->|
You know when you've been Rango'd
Orangutanz is offline
xbatista
Veteran Member
Join Date: Mar 2008
Location: Lithuania
Old 11-03-2008 , 14:15   Re: Snippet: CSDM Style Weapons Menu
Reply With Quote #7

Hey please can you add this: you can type guns once per round!!!!!!!!
xbatista is offline
Send a message via Skype™ to xbatista
craigy09
Senior Member
Join Date: Mar 2010
Old 03-30-2010 , 01:55   Re: Snippet: CSDM Style Weapons Menu
Reply With Quote #8

any1 got a compiled version of this cause when i try copy/paste it it goes to 1 line so i cant really edit it? thanks!
craigy09 is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-30-2010 , 14:53   Re: Snippet: CSDM Style Weapons Menu
Reply With Quote #9

Click "quote" on top of the post, then copy it from the new post (do not actually submit the post).
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 03-30-2010 , 16:25   Re: Snippet: CSDM Style Weapons Menu
Reply With Quote #10

Quote:
Originally Posted by craigy09 View Post
any1 got a compiled version of this cause when i try copy/paste it it goes to 1 line so i cant really edit it? thanks!
Don't copy the whole text. Copy it from the beginning to the last but one char, then write it manually.
Seta00 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 18:58.


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