Guest User

Untitled

a guest
Oct 13th, 2013
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 54.78 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <nvault>
  4. #include <fakemeta>
  5. #include <zombieplague>
  6. #include <hamsandwich>
  7. #include <fun>
  8. #include <cstrike>
  9.  
  10. /*================================================================================
  11. Info
  12. ==================================================================================
  13.  
  14. Zombie XP Mode by redomin8
  15. MeRcyLeZZ coded a huuuuge portion of the code, and I learned
  16. from his genius and maybe made some changes (some was perfect)
  17.  
  18. Also, I'd very much like to thank G-Dog for all the help with creating
  19. ZP Bank, I used his code to learn nvault. Good job guys!
  20.  
  21. Thanks to AssKicR and xeroblood for making ExplodeString.
  22.  
  23. Enjoy it, take it apart, make a better one. Have fun!
  24.  
  25. ================================================================================
  26. Editable Section follows
  27. ================================================================================*/
  28.  
  29. // Uncomment to have an item added to zp's extra menu
  30. #define TRIGGER_ZP_ITEM
  31.  
  32. // Uncomment to use say commands like "xp", "levels", "class", etc
  33. #define TRIGGER_SAYMENU
  34.  
  35. // Uncomment if you have redomin8's [ZP] Bank - With Autosave installed (fixes spending spree bug)
  36. //#define ZP_BANK_AUTOSAVE
  37.  
  38. // Uncomment to allow experimental menu alignment
  39. //#define ZP_ALIGN_TEXT
  40.  
  41. //Uncomment to give levels to people
  42. //#define ZP_GAMERUINER
  43.  
  44. //Uncomment to automatically bind a letter to show our menu
  45. #define ZP_BINDMENU "j"
  46.  
  47. /*================================================================================
  48. End Editable Section
  49. ================================================================================*/
  50.  
  51. #if defined TRIGGER_ZP_ITEM
  52. new g_TriggerItem
  53. #endif
  54. #if defined ZP_BANK_AUTOSAVE
  55. //compatibility with zp_banks spending spree mode
  56. native zp_bank_get_packs(id)
  57. native zp_bank_set_packs(id, value)
  58. #endif
  59.  
  60. // Plugin info
  61. static const PLUGIN_NAME[] = "ZP XP by redomin8"
  62. static const PLUGIN_VERSION[] = ""
  63.  
  64. // Forwards for our zombie plugins
  65. new g_fwRoundStart, g_fwDummyResult
  66.  
  67. // nVault parameters
  68. new gvault;
  69. #define VAULT_LEVEL 0
  70. #define VAULT_HCLASS 1
  71. #define VAULT_ZCLASS 2
  72.  
  73. // Internal variables
  74. enum pcvar
  75. {
  76. enable = 0,
  77. packslevelup //(current level) * packslevelup = price to level up
  78. }
  79. new pcvars[pcvar];
  80. new userLevel[33], userNameID[33][32], userNeededPacks[33]
  81. new g_modname[32] // for formating the mod name
  82. new g_maxplayers // max players counter
  83.  
  84.  
  85. /*================================================================================
  86. Required Code from zombie_plague (modified to suite the plugin)
  87. ================================================================================*/
  88.  
  89. const MAX_CLASSSES = 200
  90.  
  91. // Note: keep g_zclass_name and g_hclass_name the same array size!
  92. // Zombie Classes vars
  93. new g_zclass_name[MAX_CLASSSES][32] // name
  94. new g_zclass_info[MAX_CLASSSES][32] // description
  95. new g_zclass_model[MAX_CLASSSES][32] // player model
  96. new g_zclass_clawmodel[MAX_CLASSSES][32] // claw model
  97. new g_zclass_hp[MAX_CLASSSES] // health
  98. new g_zclass_spd[MAX_CLASSSES] // speed
  99. new g_zclass_lvl[MAX_CLASSSES] // level
  100. new Float:g_zclass_grav[MAX_CLASSSES] // gravity
  101. new Float:g_zclass_kb[MAX_CLASSSES] // knockback
  102. new g_zclass_load[MAX_CLASSSES][40] // loading identifier
  103. new g_zclass_i // loaded zombie classes counter
  104.  
  105. // Human Classes vars
  106. new g_hclass_name[MAX_CLASSSES][32] // name
  107. new g_hclass_info[MAX_CLASSSES][32] // description
  108. new g_hclass_model[MAX_CLASSSES][32] // player model
  109. new g_hclass_weapons[MAX_CLASSSES][32] // claw model
  110. new g_hclass_hp[MAX_CLASSSES] // health
  111. new g_hclass_spd[MAX_CLASSSES] // speed
  112. new g_hclass_lvl[MAX_CLASSSES] // level
  113. new Float:g_hclass_grav[MAX_CLASSSES] // gravity
  114. new g_hclass_load[MAX_CLASSSES][40] // loading identifier
  115. new g_hclass_i // loaded zombie classes counter
  116.  
  117. // For menu handlers
  118. #define ZCLASSES_STARTID g_menu_data[id][0]
  119. #define ZCLASSES_SELECTION (g_menu_data[id][0]+key)
  120. #define HCLASSES_STARTID g_menu_data[id][1]
  121. #define HCLASSES_SELECTION (g_menu_data[id][1]+key)
  122. new g_menu_data[33][8] // data for various menus
  123. const MENU_KEY_BACK = 7
  124. const MENU_KEY_NEXT = 8
  125. const MENU_KEY_EXIT = 9
  126. const KEYSMENU = (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9)
  127.  
  128. // Cvars
  129. new cvar_welcomemsg, cvar_removeweapons, cvar_removexp, cvar_removezombie;
  130.  
  131. // Vars
  132. new g_zombieclassnext[33] // zombie class for next infection
  133. new g_humanclassnext[33] // zombie class for next infection
  134. new g_zombieclass[33] // zombie class
  135. new g_humanclass[33] // zombie class
  136. new g_resetparams[33] // reset params?
  137. new bool:g_hclass_showmenu[33]
  138. new bool:g_zclass_showmenu[33]
  139.  
  140. const OFFSET_CSTEAMS = 114
  141. const OFFSET_LINUX = 5 // offsets 5 higher in Linux builds
  142. enum
  143. {
  144. CS_TEAM_UNASSIGNED = 0,
  145. CS_TEAM_T,
  146. CS_TEAM_CT,
  147. CS_TEAM_SPECTATOR
  148. }
  149. new g_freezetime; // whether it's freeze time
  150. new bool:g_human[33]; // is zombie
  151. new bool:loadedZombies //bugfix for cvar_removezombies being enabled after it was disabled first (and no zombies loaded)
  152. /* --- FOR OUR HUD --- */
  153. // Tasks for events
  154. enum (+= 100)
  155. {
  156. TASK_SHOWHUD
  157. }
  158.  
  159. // IDs inside tasks
  160. #define ID_SHOWHUD (taskid - TASK_SHOWHUD)
  161.  
  162. // Message sync object
  163. new g_MsgSync2
  164.  
  165. // Message IDs vars
  166. new g_msgSayText
  167.  
  168. // Constants
  169. const PEV_SPEC_TARGET = pev_iuser2
  170. new const textHeader[] = "[ZPXP]"
  171. new const textHeaderOrig[] = "[ZP]" //imitate Zombie Plague alerts
  172.  
  173. // HUD messages
  174. const Float:HUD_EVENT_X = -1.0
  175. const Float:HUD_EVENT_Y = 0.17
  176. const Float:HUD_INFECT_X = 0.05
  177. const Float:HUD_INFECT_Y = 0.45
  178. const Float:HUD_SPECT_X = 0.6
  179. const Float:HUD_SPECT_Y = 0.85
  180. const Float:HUD_STATS_X = 1.005 //changed to right align
  181. const Float:HUD_STATS_Y = 0.9
  182.  
  183. /*================================================================================
  184. Constants JUST for giving guns
  185. ================================================================================*/
  186.  
  187. // CS Offsets
  188. #if cellbits == 32
  189. const OFFSET_CSTEAMS = 114
  190. const OFFSET_CSMONEY = 115
  191. const OFFSET_NVGOGGLES = 129
  192. const OFFSET_ZOOMTYPE = 363
  193. const OFFSET_CSDEATHS = 444
  194. const OFFSET_AWM_AMMO = 377
  195. const OFFSET_SCOUT_AMMO = 378
  196. const OFFSET_PARA_AMMO = 379
  197. const OFFSET_FAMAS_AMMO = 380
  198. const OFFSET_M3_AMMO = 381
  199. const OFFSET_USP_AMMO = 382
  200. const OFFSET_FIVESEVEN_AMMO = 383
  201. const OFFSET_DEAGLE_AMMO = 384
  202. const OFFSET_P228_AMMO = 385
  203. const OFFSET_GLOCK_AMMO = 386
  204. const OFFSET_FLASH_AMMO = 387
  205. const OFFSET_HE_AMMO = 388
  206. const OFFSET_SMOKE_AMMO = 389
  207. const OFFSET_C4_AMMO = 390
  208. const OFFSET_CLIPAMMO = 51
  209. #else
  210. const OFFSET_CSTEAMS = 139
  211. const OFFSET_CSMONEY = 140
  212. const OFFSET_NVGOGGLES = 155
  213. const OFFSET_ZOOMTYPE = 402
  214. const OFFSET_CSDEATHS = 493
  215. const OFFSET_AWM_AMMO = 426
  216. const OFFSET_SCOUT_AMMO = 427
  217. const OFFSET_PARA_AMMO = 428
  218. const OFFSET_FAMAS_AMMO = 429
  219. const OFFSET_M3_AMMO = 430
  220. const OFFSET_USP_AMMO = 431
  221. const OFFSET_FIVESEVEN_AMMO = 432
  222. const OFFSET_DEAGLE_AMMO = 433
  223. const OFFSET_P228_AMMO = 434
  224. const OFFSET_GLOCK_AMMO = 435
  225. const OFFSET_FLASH_AMMO = 46
  226. const OFFSET_HE_AMMO = 437
  227. const OFFSET_SMOKE_AMMO = 438
  228. const OFFSET_C4_AMMO = 439
  229. const OFFSET_CLIPAMMO = 65
  230. #endif
  231.  
  232. // Buy Menu: Primary and Secondary Weapons
  233. new const g_primary_items[][] = { "weapon_galil", "weapon_famas", "weapon_m4a1", "weapon_ak47", "weapon_sg552", "weapon_aug", "weapon_scout",
  234. "weapon_m3", "weapon_xm1014", "weapon_tmp", "weapon_mac10", "weapon_ump45", "weapon_mp5navy", "weapon_p90" }
  235. new const g_secondary_items[][] = { "weapon_glock18", "weapon_usp", "weapon_p228", "weapon_deagle", "weapon_fiveseven", "weapon_elite" }
  236.  
  237.  
  238. // Max BP ammo for weapons
  239. new const MAXBPAMMO[] = { -1, 52, -1, 90, 1, 32, 32, 100, 90, 1, 120, 100, 100, 90, 90, 90, 100, 120,
  240. 30, 120, 200, 32, 90, 120, 90, 2, 35, 90, 90, -1, 100 }
  241.  
  242. // Additional Items to give after buying all weapons (e.g. grenades)
  243. new const g_additional_items[][] = { "weapon_hegrenade", "weapon_flashbang", "weapon_smokegrenade" }
  244.  
  245. // Weapon bitsums
  246. const PRIMARY_WEAPONS_BIT_SUM = (1<<CSW_SCOUT)|(1<<CSW_XM1014)|(1<<CSW_MAC10)|(1<<CSW_AUG)|(1<<CSW_UMP45)|(1<<CSW_SG550)|(1<<CSW_GALIL)|(1<<CSW_FAMAS)|(1<<CSW_AWP)|(1<<CSW_MP5NAVY)|(1<<CSW_M249)|(1<<CSW_M3)|(1<<CSW_M4A1)|(1<<CSW_TMP)|(1<<CSW_G3SG1)|(1<<CSW_SG552)|(1<<CSW_AK47)|(1<<CSW_P90)
  247. const SECONDARY_WEAPONS_BIT_SUM = (1<<CSW_P228)|(1<<CSW_ELITE)|(1<<CSW_FIVESEVEN)|(1<<CSW_USP)|(1<<CSW_GLOCK18)|(1<<CSW_DEAGLE)
  248.  
  249. const PEV_ADDITIONAL_AMMO = pev_iuser1
  250.  
  251. /*================================================================================
  252. The code starts here
  253. ================================================================================*/
  254.  
  255. public plugin_precache()
  256. {
  257. // Register all our cvars
  258. cvar_welcomemsg = register_cvar("zp_xp_welcomemsg", "1");
  259. cvar_removeweapons = register_cvar("zp_xp_removeweapons", "0");
  260. cvar_removexp = register_cvar("zp_xp_removexp", "0");
  261. cvar_removezombie = register_cvar("zp_xp_removezombie", "0");
  262. }
  263.  
  264. public plugin_init()
  265. {
  266.  
  267.  
  268. // Register the plugin
  269. register_plugin(PLUGIN_NAME, PLUGIN_VERSION, "Huh?")
  270.  
  271. // Language files
  272. register_dictionary("zombie_xp.txt")
  273.  
  274. // Register the menus
  275. register_menu("Game Menu", KEYSMENU, "menu_game")
  276. register_menu("Zombie Class Menu", KEYSMENU, "menu_zclass")
  277. register_menu("Human Class Menu", KEYSMENU, "menu_hclass")
  278.  
  279. // For setting human's skills
  280. register_forward(FM_PlayerPreThink, "fw_PlayerPreThink")
  281.  
  282. // For setting the user human on connecting
  283. RegisterHam(Ham_Spawn, "player", "fw_PlayerSpawn_Post", 1)
  284.  
  285. // For setting humans speed also
  286. register_logevent("logevent_round_start",2, "1=Round_Start")
  287.  
  288. // Register event round start for humans
  289. register_event("HLTV", "event_round_start", "a", "1=0", "2=0");
  290.  
  291. // Register forward for our plugins
  292. g_fwRoundStart = CreateMultiForward("zp_round_started_human", ET_IGNORE, FP_CELL)
  293.  
  294. // Set our vars to disable zombie plague functions
  295. set_task(1.0, "set_cvars")
  296.  
  297. // Register variables
  298. pcvars[enable] = register_cvar("zp_xp_enable", "1")
  299. pcvars[packslevelup] = 15
  300.  
  301. // Register client commands
  302. register_clcmd("zp_xp_costscale", "SetPacksLevelUp")
  303. register_clcmd("zp_xp_set_level", "SetLevel")
  304. register_clcmd("zp_xp_removexp", "RemoveXP")
  305. register_clcmd("zp_xp_removezombies", "RemoveZombies")
  306. register_clcmd("zp_xp_removeweapons", "RemoveWeapons")
  307.  
  308. //trigger for handling the menu
  309. #if defined TRIGGER_ZP_ITEM
  310.  
  311. #endif
  312. #if defined TRIGGER_SAYMENU
  313. register_clcmd("say xp", "handle_say_xp")
  314. register_clcmd("say level", "handle_say_level")
  315. register_clcmd("say nivel", "handle_say_level")
  316. register_clcmd("say xpmenu", "handle_say_xpmenu")
  317. #endif
  318.  
  319. //Settings variables
  320. g_msgSayText = get_user_msgid("SayText")
  321.  
  322. // Format mod name
  323. formatex(g_modname, sizeof g_modname - 1, "Zombie XP %s", PLUGIN_VERSION)
  324.  
  325. // Get Max Players
  326. g_maxplayers = get_maxplayers()
  327.  
  328. //nVault
  329. gvault = nvault_open(PLUGIN_NAME);
  330.  
  331. //for our HUD (shows level on screen)
  332. g_MsgSync2 = CreateHudSyncObj()
  333. }
  334.  
  335. public set_cvars()
  336. {
  337. // Disable zombie_plague's zombie auto menu
  338. if( get_pcvar_num(cvar_removezombie) == 0) set_cvar_num("zp_zombie_classes", 0);
  339. if( get_pcvar_num(cvar_removeweapons) == 0) set_cvar_num("zp_buy_custom", 0);
  340. }
  341.  
  342. public plugin_natives()
  343. {
  344. //natives
  345. register_native("zpxp_register_extra_item", "native_register_extra_item", 1)
  346. register_native("zpxp_register_human_class", "native_register_human_class", 1)
  347. register_native("zpxp_register_zombie_class", "native_register_zombie_class", 1)
  348. register_native("zp_get_user_human_class", "native_get_user_human_class", 1)
  349. }
  350.  
  351. public plugin_end()
  352. {
  353. if( get_pcvar_num(cvar_removexp) == 0)
  354. {
  355. // Save everyone's data first
  356. server_print("%s Saving your clients XP.", textHeader);
  357.  
  358. for( new o = 1; o < 33; o++)
  359. {
  360. //if ( !is_user_connected(o) || is_user_bot(o) ) continue;
  361. if ( !is_user_connected(o) ) continue;
  362. if ( is_user_bot(o) ) continue;
  363.  
  364. save_data(o);
  365. }
  366. }
  367.  
  368. nvault_close(gvault)
  369.  
  370. //Bugfix:
  371. if( (loadedZombies == false) && ( get_pcvar_num(cvar_removezombie) == 0 ))
  372. {
  373. set_pcvar_num(cvar_removezombie, 0);
  374. set_cvar_num("zp_zombie_classes", 0)
  375. }
  376. }
  377.  
  378. #if defined TRIGGER_SAYMENU
  379. public handle_say_xp(id)
  380. {
  381.  
  382. #if defined ZP_BINDMENU
  383. new strLetter[2];
  384. copy(strLetter, sizeof strLetter - 1, ZP_BINDMENU);
  385. strtoupper(strLetter);
  386. strtoupper(ZP_BINDMENU);
  387.  
  388. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "SAY_INFO_KEY", strLetter)
  389. #else
  390. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "SAY_INFO")
  391. #endif
  392. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "SAY_XP", pcvars[packslevelup] * userLevel[id], userLevel[id])
  393. return PLUGIN_HANDLED
  394. }
  395. public handle_say_level(id)
  396. {
  397. //return level
  398. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "SAY_LEVEL", userLevel[id])
  399. return PLUGIN_HANDLED
  400.  
  401. zp_colored_print(id, "[Clan nK]^x03 %s^x01 tiene^x04 %s^x01 niveles ", userNameID[id], userLevel[id])
  402. return PLUGIN_HANDLED
  403.  
  404. }
  405. public handle_say_class(id)
  406. {
  407. //return class
  408. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "SAY_CLASS", g_hclass_name[g_humanclass[id]], g_zclass_name[g_zombieclass[id]])
  409. return PLUGIN_HANDLED
  410. }
  411. public handle_say_xpmenu(id)
  412. {
  413. show_menu_game(id);
  414. return PLUGIN_HANDLED
  415. }
  416. #endif
  417.  
  418. #if defined TRIGGER_ZP_ITEM
  419. public zp_extra_item_selected(player, itemid)
  420. {
  421. if(itemid == g_TriggerItem)
  422. {
  423. //show the menu
  424. show_menu_game(player);
  425. }
  426. }
  427. #endif
  428.  
  429. #if defined ZP_BANK_AUTOSAVE
  430. public getAmmoPacks(id)
  431. {
  432. return zp_bank_get_packs(id);
  433. }
  434. public setAmmoPacks(id, value)
  435. {
  436. return zp_bank_set_packs(id, value);
  437. }
  438. #else
  439. public getAmmoPacks(id)
  440. {
  441. return zp_get_user_ammo_packs(id);
  442. }
  443. public setAmmoPacks(id, value)
  444. {
  445. return zp_set_user_ammo_packs(id, value);
  446. }
  447. #endif
  448.  
  449.  
  450. public SetLevel(id)
  451. {
  452. //Multilang is not enabled here since I plan to remove this funtionality once this leaves BETA
  453. #if defined ZP_GAMERUINER
  454. if ( read_argc() > 3 ) return PLUGIN_HANDLED;
  455.  
  456. new arg1[32], arg2[10], amount;
  457. read_argv(1, arg1, sizeof(arg1) - 1);
  458. read_argv(2, arg2, sizeof(arg2) - 1);
  459.  
  460. amount = str_to_num(arg2);
  461. if( amount <= 0) amount = 1;
  462. new target = cmd_target(0, arg1, 2);
  463.  
  464. if ( target == 0 )
  465. {
  466. //couldnt find them
  467. zp_colored_print(id, "^x04%s^x01 Could not find the requested user.", textHeader);
  468.  
  469. return PLUGIN_HANDLED;
  470.  
  471. } else {
  472.  
  473. //we found them!
  474. userLevel[id] = amount
  475. ShowHUD(id)
  476.  
  477. if(id == target)
  478. {
  479. zp_colored_print(id, "^x04%s^x01 You have set yourself to level %d!", textHeader, amount );
  480. } else {
  481. new targetName[64];
  482. get_user_name(target, targetName, 63);
  483.  
  484. zp_colored_print(id, "^x04%s^x01 You have set %s to level %d!", textHeader , targetName, amount );
  485. zp_colored_print(target, "^x04%s^x01 You have been set to level %d!", textHeader , amount );
  486. }
  487. return PLUGIN_HANDLED;
  488. }
  489. #else
  490. zp_colored_print(id, "^x04%s^x01 This functionality has been disabled.", textHeader);
  491. client_print(id, print_console, "^x04%s^x01 This functionality has been disabled.", textHeader);
  492. #endif
  493. return PLUGIN_HANDLED;
  494.  
  495. }
  496.  
  497. public getNeededPacks(id)
  498. {
  499. //return the packs needed for leveling up
  500. return pcvars[packslevelup] * userLevel[id]
  501. }
  502.  
  503. public SetPacksLevelUp(id, value)
  504. {
  505. //this allows the user to change the multiplier for ammo cost
  506. new arg[10], arg2
  507. read_argv(1, arg, sizeof arg - 1)
  508.  
  509. arg2 = str_to_num(arg)
  510. if(arg2 > 0)
  511. {
  512. client_print(id, print_console, "%s %L", textHeader, id, "ADMIN_CONFIRM")
  513. pcvars[packslevelup] = arg2;
  514.  
  515. //go through each player and change the amount required to level up
  516. for( new o = 1; o < 33; o++)
  517. {
  518. if ( !is_user_connected(o) ) continue;
  519. userNeededPacks[id] = getNeededPacks(id)
  520. }
  521. } else {
  522. //must be a positive number - PRINTS TO CONSOLE, LEAVE ALONE!
  523. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "ERR_NEGATIVE");
  524. client_print(id, print_console, "%s %L", textHeader, id, "ERR_NEGATIVE")
  525. }
  526.  
  527. return PLUGIN_HANDLED;
  528. }
  529.  
  530.  
  531. //-----------------------CVAR Handlers--------------------------
  532.  
  533. public RemoveXP(id)
  534. {
  535. //this allows the user to enable or disable XP
  536. new arg[10], arg2
  537. read_argv(1, arg, sizeof arg - 1)
  538.  
  539. arg2 = str_to_num(arg)
  540. if(arg2 >= 0)
  541. {
  542. if(arg2 == 1) {
  543. // Disable the XP
  544. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "ADMIN_CONFIRM");
  545. client_print(id, print_console, "%s %L", textHeader, id, "ADMIN_CONFIRM")
  546. set_pcvar_num(cvar_removexp, arg2);
  547.  
  548. } else if (arg2 == 0) {
  549. // Enable the XP
  550. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "ADMIN_CONFIRM");
  551. client_print(id, print_console, "%s %L", textHeader, id, "ADMIN_CONFIRM")
  552. set_pcvar_num(cvar_removexp, arg2);
  553.  
  554. } else {
  555. // They typed something wrong
  556. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "ERR_INVALIDENTRY");
  557. client_print(id, print_console, "%s %L", textHeader, id, "ERR_INVALIDENTRY");
  558. return PLUGIN_HANDLED;
  559. }
  560. } else {
  561. //must be a positive number - PRINTS TO CONSOLE, LEAVE ALONE!
  562. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "ERR_NEGATIVE");
  563. client_print(id, print_console, "%s %L", textHeader, id, "ERR_NEGATIVE")
  564. }
  565.  
  566. return PLUGIN_HANDLED;
  567.  
  568. }
  569.  
  570. public RemoveZombies(id)
  571. {
  572. //this allows the user to enable or disable zombie classes
  573. new arg[10], arg2
  574. read_argv(1, arg, sizeof arg - 1)
  575.  
  576. arg2 = str_to_num(arg)
  577. if(arg2 >= 0)
  578. {
  579. if (arg2 == 0) {
  580. // Enable the zombie classes
  581.  
  582. if( loadedZombies == true )
  583. {
  584. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "ADMIN_CONFIRM");
  585. client_print(id, print_console, "%s %L", textHeader, id, "ADMIN_CONFIRM")
  586. set_pcvar_num(cvar_removezombie, 0);
  587. set_cvar_num("zp_zombie_classes", 0)
  588. } else {
  589. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "ADMIN_CONFIRM_NEXTROUND");
  590. client_print(id, print_console, "%s %L", textHeader, id, "ADMIN_CONFIRM_NEXTROUND")
  591. //set_pcvar_num(cvar_removezombie, 0);
  592. //set_cvar_num("zp_zombie_classes", 0)
  593. }
  594. } else if (arg2 == 1) {
  595. // Disable the zombie classes
  596. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "ADMIN_CONFIRM");
  597. client_print(id, print_console, "%s %L", textHeader, id, "ADMIN_CONFIRM")
  598. set_pcvar_num(cvar_removezombie, 1);
  599. set_cvar_num("zp_zombie_classes", 1)
  600.  
  601. } else if (arg2 == 2) {
  602. // Disable, and dont add zombies to zombie plague
  603. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "ADMIN_CONFIRM_NEXTROUND");
  604. client_print(id, print_console, "%s %L", textHeader, id, "ADMIN_CONFIRM_NEXTROUND")
  605. set_pcvar_num(cvar_removezombie, 1);
  606. set_cvar_num("zp_zombie_classes", 2)
  607.  
  608. } else {
  609. // They typed something wrong
  610. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "ERR_INVALIDENTRY");
  611. client_print(id, print_console, "%s %L", textHeader, id, "ERR_INVALIDENTRY");
  612. return PLUGIN_HANDLED;
  613.  
  614. }
  615. } else {
  616. //must be a positive number - PRINTS TO CONSOLE, LEAVE ALONE!
  617. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "ERR_NEGATIVE");
  618. client_print(id, print_console, "%s %L", textHeader, id, "ERR_NEGATIVE")
  619. }
  620.  
  621. return PLUGIN_HANDLED;
  622.  
  623. }
  624.  
  625. public RemoveWeapons(id)
  626. {
  627. //this allows the user to enable or disable zombie classes
  628. new arg[10], arg2
  629. read_argv(1, arg, sizeof arg - 1)
  630.  
  631. arg2 = str_to_num(arg)
  632. if(arg2 >= 0)
  633. {
  634. if(arg2 == 1) {
  635. // Disable the custom human weapons
  636. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "ADMIN_CONFIRM");
  637. client_print(id, print_console, "%s %L", textHeader, id, "ADMIN_CONFIRM")
  638. set_pcvar_num(cvar_removeweapons, 1);
  639. set_cvar_num("zp_buy_custom", 1);
  640.  
  641. } else if (arg2 == 0) {
  642. // Enable the custom human weapons
  643. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "ADMIN_CONFIRM");
  644. client_print(id, print_console, "%s %L", textHeader, id, "ADMIN_CONFIRM")
  645. set_pcvar_num(cvar_removeweapons, 0);
  646. set_cvar_num("zp_buy_custom", 0);
  647.  
  648. } else {
  649. // They typed something wrong
  650. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "ERR_INVALIDENTRY");
  651. client_print(id, print_console, "%s %L", textHeader, id, "ERR_INVALIDENTRY");
  652. return PLUGIN_HANDLED;
  653. }
  654. } else {
  655. //must be a positive number - PRINTS TO CONSOLE, LEAVE ALONE!
  656. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "ERR_NEGATIVE");
  657. client_print(id, print_console, "%s %L", textHeader, id, "ERR_NEGATIVE")
  658. }
  659.  
  660. return PLUGIN_HANDLED;
  661.  
  662. }
  663.  
  664. public show_menu_game(id)
  665. {
  666. // Show our menu
  667. static menu[250], len, index;
  668. len = 0
  669. index = 1;
  670.  
  671. // Title
  672. len += formatex(menu[len], sizeof menu - 1 - len, "\y%s^n^n", g_modname)
  673.  
  674. if( get_pcvar_num(cvar_removexp) == 0 )
  675. {
  676. // 1. Buy a level up
  677. if(getAmmoPacks(id) >= getNeededPacks(id))
  678. {
  679. len += formatex(menu[len], sizeof menu - 1 - len, "\r%d.\w %L", index, id, "MENU_BUY_XP")
  680. len += formatex(menu[len], sizeof menu - 1 - len, " \y%d %L^n", getNeededPacks(id), id, "AMMO_PACKS_XP")
  681. } else {
  682. len += formatex(menu[len], sizeof menu - 1 - len, "\d%d. %L", index, id, "MENU_BUY_XP")
  683. len += formatex(menu[len], sizeof menu - 1 - len, " \d%d %L^n", getNeededPacks(id), id, "AMMO_PACKS_XP")
  684. }
  685.  
  686. index++;
  687. }
  688.  
  689. //Human class
  690. len += formatex(menu[len], sizeof menu - 1 - len, "\r%d.\w %L^n", index, id,"MENU_HCLASS")
  691.  
  692. if (get_pcvar_num(cvar_removezombie) == 0)
  693. {
  694. //Zombie class
  695. index++;
  696. len += formatex(menu[len], sizeof menu - 1 - len, "\r%d.\w %L^n", index, id,"MENU_ZCLASS")
  697. }
  698.  
  699. // 0. Exit
  700. len += formatex(menu[len], sizeof menu - 1 - len, "^n^n\r0.\w %L", id, "MENU_EXIT")
  701.  
  702. show_menu(id, KEYSMENU, menu, -1, "Game Menu")
  703. }
  704.  
  705. public save_data(id)
  706. {
  707. new vaultkey[40],vaultData[256];
  708.  
  709. new g_selected_zclass[sizeof g_zclass_load[]] , g_selected_hclass[sizeof g_hclass_load[]] //bug fix for not showing menu if the user hasnt picked a zombie
  710. if( g_hclass_showmenu[id] == true) { g_selected_hclass = "-1"; } else { formatex(g_selected_hclass, sizeof g_selected_hclass - 1, g_hclass_load[g_humanclassnext[id]]); }
  711. if( g_zclass_showmenu[id] == true) { g_selected_zclass = "-1"; } else { formatex(g_selected_zclass, sizeof g_selected_zclass -1, g_zclass_load[g_zombieclassnext[id]]); }
  712.  
  713. formatex( vaultkey, sizeof vaultkey - 1, "%s_stats", userNameID[id]);
  714. formatex( vaultData, sizeof vaultData - 1, "0=%i;1=%s;2=%s;", userLevel[id], g_selected_hclass, g_selected_zclass);
  715.  
  716. nvault_set(gvault, vaultkey, vaultData);
  717. }
  718.  
  719. public load_data(id)
  720. {
  721. if( get_pcvar_num(cvar_removexp) != 0)
  722. {
  723. // Do not load or save data
  724. g_hclass_showmenu[id] = true;
  725. g_zclass_showmenu[id] = true;
  726. return;
  727. }
  728.  
  729. new vaultkey[40], vaultReturn[256];
  730. new vaultData[4][40], vaultResults[3][40];
  731.  
  732. // Get the Level
  733. format(vaultkey, sizeof vaultkey - 1, "%s_stats", userNameID[id]);
  734. nvault_get(gvault, vaultkey, vaultReturn, sizeof vaultReturn - 1);
  735.  
  736. new Count = ExplodeString(vaultData, sizeof vaultData - 1, sizeof vaultData[] - 1, vaultReturn, ';')
  737.  
  738. if(Count == sizeof vaultResults - 1)
  739. {
  740. new ivaultLevel, i_hclass_id = -1, i_zclass_id = -1;
  741.  
  742. for( new i = 0; i < sizeof vaultData - 1; i++)
  743. {
  744. ExplodeString(vaultResults, sizeof vaultResults - 1, sizeof vaultResults[] - 1, vaultData[i], '=');
  745.  
  746. // We now have our items
  747. switch (str_to_num(vaultResults[0]))
  748. {
  749. case VAULT_LEVEL:
  750. {
  751. ivaultLevel = str_to_num(vaultResults[1]);
  752.  
  753. if (ivaultLevel == 0) ivaultLevel = 1;
  754. userLevel[id] = ivaultLevel
  755. }
  756.  
  757. case VAULT_HCLASS:
  758. {
  759. // Look for our human class
  760. if( !equali(vaultResults[1], "-1") )
  761. {
  762. for (new i2 = 0; i2 < g_hclass_i; i2++)
  763. {
  764. if( equali(vaultResults[1], g_hclass_load[i2]) )
  765. {
  766. i_hclass_id = i2;
  767. break;
  768. }
  769. }
  770. }
  771.  
  772. if ( i_hclass_id == -1)
  773. {
  774. // Couldnt find them
  775. g_hclass_showmenu[id] = true;
  776. } else {
  777. // We found their zombie class
  778. g_humanclassnext[id] = i_hclass_id;
  779. g_hclass_showmenu[id] = false;
  780. }
  781. }
  782.  
  783. case VAULT_ZCLASS:
  784. {
  785. if( !equali(vaultResults[1], "-1") )
  786. {
  787. for (new i2 = 0; i2 < g_zclass_i; i2++)
  788. {
  789. if( equali(vaultResults[1], g_zclass_load[i2]) )
  790. {
  791. i_zclass_id = i2;
  792. break;
  793. }
  794. }
  795. }
  796.  
  797. if ( i_zclass_id == -1)
  798. {
  799. g_zclass_showmenu[id] = true;
  800. } else {
  801. g_zombieclassnext[id] = i_zclass_id;
  802. g_zclass_showmenu[id] = false;
  803. zp_set_user_zombie_class(id, i_zclass_id);
  804. }
  805. }
  806. }
  807. }
  808. } else {
  809. g_hclass_showmenu[id] = true;
  810. g_zclass_showmenu[id] = true;
  811.  
  812. }
  813. }
  814.  
  815. public client_connect(id)
  816. {
  817. // Do we bind a key
  818. #if defined ZP_BINDMENU
  819. client_cmd(id,"bind %s ^"say xpmenu^"", ZP_BINDMENU);
  820. #endif
  821. }
  822. public client_putinserver(id)
  823. {
  824. // Reset vars
  825. resetvars(id)
  826.  
  827. // Make sure zombieplague doesnt load the last plugin as the default zombie
  828. zp_set_user_zombie_class(id, 0)
  829.  
  830. // Load their data
  831. load_data(id);
  832.  
  833. // Set amount of levels to level up (called after load_data)
  834. userNeededPacks[id] = getNeededPacks(id)
  835.  
  836. // Set the custom HUD display task
  837. set_task(1.0, "ShowHUD", id+TASK_SHOWHUD, _, _, "b")
  838. }
  839.  
  840. public client_disconnect(id)
  841. {
  842. // Save the data
  843. save_data(id);
  844.  
  845. // Remove tasks
  846. remove_task(id+TASK_SHOWHUD)
  847. }
  848.  
  849. public fw_PlayerSpawn_Post(id)
  850. {
  851. // Both humans and zombies spawn and call this
  852. // Zombies can respawn if deathmatch is enabled
  853.  
  854. //TODO: Check if this works
  855. if (zp_get_user_zombie(id))
  856. return FMRES_IGNORED;
  857.  
  858. if (!is_user_alive(id)) // you could also use is_user_connected()
  859. return FMRES_IGNORED;
  860.  
  861. // Set selected human and zombie class
  862. g_humanclass[id] = g_humanclassnext[id]
  863. g_zombieclass[id] = g_zombieclassnext[id]
  864.  
  865. // Change the default human variables
  866. humanme(id)
  867.  
  868. // We know for sure they are a human, only give guns+speed+grav if they've picked a class
  869. if (( g_hclass_showmenu[id] == false ) && (get_pcvar_num(cvar_removeweapons) == 0))
  870. {
  871. setHumanParameters(id)
  872. giveWeapons(id) //give weapons
  873. }
  874.  
  875. return FMRES_IGNORED;
  876. }
  877.  
  878. public event_round_start()
  879. {
  880. static team;
  881.  
  882. // Set our humans hp, speed, etc
  883. for( new o = 1; o < 33; o++)
  884. {
  885. // Not connected
  886. if ( !is_user_connected(o) ) continue;
  887.  
  888. // Not playing
  889. team = fm_get_user_team(o)
  890. if (team == CS_TEAM_SPECTATOR || team == CS_TEAM_UNASSIGNED) continue;
  891.  
  892. // Set our human vars
  893. //humanme(o)
  894.  
  895. // Our next vars are now current
  896. //g_humanclass[o] = g_humanclassnext[o]
  897. //g_zombieclass[o] = g_zombieclassnext[o]
  898.  
  899. // The round has started
  900. ExecuteForward(g_fwRoundStart, g_fwDummyResult, o);
  901. }
  902.  
  903. // Set our vars
  904. g_freezetime = true
  905.  
  906. // Do we show a welcome message?
  907. if( get_pcvar_num(cvar_welcomemsg) )
  908. set_task(2.0, "welcome_msg")
  909. }
  910.  
  911. public zp_user_infected_pre(id, infector)
  912. {
  913. // Make sure he is not a human
  914. g_human[id] = false
  915.  
  916. // Strip his guns (so they dont fall on the floor)
  917. strip_weapons(id);
  918. }
  919.  
  920. public zp_user_infected_post(id, infector)
  921. {
  922. // Do we show the menu?
  923. if ((g_zclass_showmenu[id] == true) && get_pcvar_num(cvar_removezombie) ==0) show_menu_zclass(id);
  924.  
  925. }
  926.  
  927. public zp_user_humanized_pre(id)
  928. {
  929. // Set selected human class, incase he buys antidote
  930. g_humanclass[id] = g_humanclassnext[id];
  931. g_zombieclass[id] = g_zombieclassnext[id];
  932. }
  933.  
  934. public zp_user_humanized_post(id)
  935. {
  936. // Hes become human again, set our vars
  937. if( !zp_get_user_survivor(id) )
  938. {
  939. humanme(id)
  940. setHumanParameters(id)
  941. if( get_pcvar_num(cvar_removeweapons) == 0) giveWeapons(id) //give weapons
  942. } else {
  943. // He has become a survivor
  944. g_human[id] = false
  945. }
  946.  
  947. ShowHUD(id)
  948. }
  949.  
  950.  
  951.  
  952.  
  953. enum
  954. {
  955. WEAPON_GALIL = 0,
  956. WEAPON_FAMAS,
  957. WEAPON_M4A1,
  958. }
  959.  
  960. public humanme(id)
  961. {
  962. // Set our human's height, jump, etc
  963.  
  964. if( g_hclass_showmenu[id] == true)
  965. {
  966. // They just entered, and no data was loaded for them
  967. // Show the menu (despite the fact that they are automatically lvl. 1)
  968. if (get_pcvar_num(cvar_removezombie) == 0)
  969. { set_task(0.1, "show_menu_hclass", id); } else { set_task(0.5, "show_menu_hclass", id); }
  970. }
  971.  
  972. // They are human
  973. g_human[id] = true;
  974. }
  975.  
  976. public giveWeapons(id)
  977. {
  978. // Strip weapons first
  979. strip_weapons(id);
  980.  
  981. // Give all weapons (everything is in g_hclass_weapons)
  982. static i, weaponid;
  983. for (i = 0; i < sizeof g_hclass_weapons; i++)
  984. {
  985. weaponid = g_hclass_weapons[g_humanclass[id]][i];
  986.  
  987. if (weaponid >= 1 && weaponid <= 14) {
  988. // Give main weapon
  989. give_primary_weapon(id, weaponid - 1);
  990.  
  991. } else if ( weaponid >= 15 && weaponid <= 20) {
  992. // Give secondary gun
  993. give_secondary_weapon(id, weaponid - 15);
  994.  
  995. } else if ( weaponid >= 21 && weaponid <=23) {
  996. // Give grenades
  997. fm_give_item(id, g_additional_items[weaponid - 21]);
  998.  
  999. } else {
  1000. // We have given them all their item, or they dont have any
  1001. return;
  1002. }
  1003. }
  1004. }
  1005.  
  1006. public setHumanParameters(id)
  1007. {
  1008. set_pev(id, pev_gravity, g_hclass_grav[g_humanclass[id]])
  1009. fm_set_user_health(id, g_hclass_hp[g_humanclass[id]])
  1010. }
  1011.  
  1012. public resetvars(id)
  1013. {
  1014. // This should only be called whenever a person connects!
  1015. // Otherwise it erases a persons choices
  1016. // Reset our human's variables
  1017. g_zombieclassnext[id] = 0;
  1018. g_humanclassnext[id] = 0;
  1019. g_zombieclass[id] = 0;
  1020. g_humanclass[id] = 0;
  1021.  
  1022. g_hclass_showmenu[id] = false;
  1023. g_zclass_showmenu[id] = false;
  1024.  
  1025. userLevel[id] = 1;
  1026.  
  1027. get_user_name(id, userNameID[id], 31)
  1028. g_resetparams[id] = false
  1029. }
  1030.  
  1031. /*================================================================================
  1032. Begin Functions from the internet
  1033. ================================================================================*/
  1034.  
  1035. //http://forums.alliedmods.net/showthread.php?p=67207#post67207
  1036. stock ExplodeString( Output[][], Max, Size, Input[], Delimiter )
  1037. {
  1038. new Idx, l = strlen(Input), Len;
  1039. do Len += (1 + copyc( Output[Idx], Size, Input[Len], Delimiter ));
  1040. while( (Len < l) && (++Idx < Max) )
  1041. return Idx;
  1042. }
  1043.  
  1044.  
  1045. /*================================================================================
  1046. Begin Code from zombie_plague (modified to suit the plugin)
  1047. ================================================================================*/
  1048.  
  1049. // Set player's health (from fakemeta_util)
  1050. stock fm_set_user_health(id, health)
  1051. {
  1052. (health > 0) ? set_pev(id, pev_health, float(health)) : dllfunc(DLLFunc_ClientKill, id);
  1053. }
  1054.  
  1055.  
  1056. // Forward Player PreThink
  1057. public fw_PlayerPreThink(id)
  1058. {
  1059. // Not alive
  1060. if (!is_user_alive(id)) return;
  1061.  
  1062. // Not human, survivor will count as not a human
  1063. if(!g_human[id]) return;
  1064.  
  1065. // Set Player MaxSpeed
  1066. if (!g_freezetime)
  1067. {
  1068. if (g_human[id])
  1069. {
  1070. set_pev(id, pev_maxspeed, float(g_hclass_spd[g_humanclass[id]]))
  1071. return
  1072. }
  1073. }
  1074. }
  1075.  
  1076. public show_menu_zclass(id)
  1077. {
  1078. // Player disconnected
  1079. if (!is_user_connected(id))
  1080. return;
  1081.  
  1082. // Bots pick default classes
  1083. if (is_user_bot(id))
  1084. {
  1085. g_zombieclassnext[id] = 0 //basic zombie
  1086. return;
  1087. }
  1088.  
  1089. static menu[800], len, class, removexp;
  1090. new curClassIcon[2];
  1091.  
  1092. len = 0
  1093. removexp = get_pcvar_num(cvar_removexp);
  1094.  
  1095. // Title
  1096. len += formatex(menu[len], sizeof menu - 1 - len, "\y%L \r [%d-%d]^n^n", id, "MENU_ZCLASS_TITLE", ZCLASSES_STARTID+1, min(ZCLASSES_STARTID+7, g_zclass_i))
  1097.  
  1098. #if defined ZP_ALIGN_TEXT
  1099. // Align text
  1100. new spacers[400], g_zclass_spacers1, g_zclass_spacers2
  1101. new maxSpace1, maxSpace2, curSpace1[32], curSpace2[32]
  1102.  
  1103. // Get max width first
  1104. for (class = ZCLASSES_STARTID; class < min(ZCLASSES_STARTID+7, g_zclass_i); class++)
  1105. {
  1106. formatex(spacers, sizeof spacers - 1, "%d. %s", class-ZCLASSES_STARTID+1, g_zclass_name[class])
  1107.  
  1108. g_zclass_spacers1 = strlen(spacers)
  1109. g_zclass_spacers2 = strlen(g_zclass_info[class])
  1110.  
  1111. if(g_zclass_spacers1 > maxSpace1) maxSpace1 = g_zclass_spacers1
  1112. if(g_zclass_spacers2 > maxSpace2) maxSpace2 = g_zclass_spacers2
  1113. }
  1114.  
  1115. // 1-7. Class List
  1116. for (class = ZCLASSES_STARTID; class < min(ZCLASSES_STARTID+7, g_zclass_i); class++)
  1117. {
  1118.  
  1119. if (g_zclass_lvl[id] >= g_zclass_lvl[class])
  1120. {
  1121. if (class == g_zombieclassnext[id])
  1122. len += formatex(menu[len], sizeof menu - 1 - len, "\d%d. %s %s^n", class-ZCLASSES_STARTID+1, g_zclass_name[class], g_zclass_info[class])
  1123. else
  1124. len += formatex(menu[len], sizeof menu - 1 - len, "\r%d.\w %s\y %s^n", class-ZCLASSES_STARTID+1, g_zclass_name[class], g_zclass_info[class])
  1125. }
  1126. else
  1127. len += formatex(menu[len], sizeof menu - 1 - len, "\r%d.\d %s %s\r (Nivel Requerido: %d)^n", class-ZCLASSES_STARTID+1, g_zclass_name[class], g_zclass_info[class], g_zclass_lvl[class])
  1128. }
  1129. #else
  1130. for (class = ZCLASSES_STARTID; class < min(ZCLASSES_STARTID+7, g_zclass_i); class++)
  1131. {
  1132. if (((class == g_zombieclassnext[id] && g_zclass_showmenu[id] == false) || (userLevel[id] < g_zclass_lvl[class])) && (removexp == 0))
  1133. {
  1134. if (class == g_zombieclassnext[id]) { curClassIcon = "*"; } else { curClassIcon = ""; }
  1135.  
  1136. len += formatex(menu[len], sizeof menu - 1 - len, "\d%s%d. %s - %s - %L %d^n", curClassIcon, class-ZCLASSES_STARTID+1, g_zclass_name[class], g_zclass_info[class], id, "BOTH_ATTRIB_LEVEL", g_zclass_lvl[class])
  1137. } else if (removexp == 1) {
  1138. len += formatex(menu[len], sizeof menu - 1 - len, "\r%d.\w %s -\y %s^n", class-ZCLASSES_STARTID+1, g_zclass_name[class], g_zclass_info[class]);
  1139. } else {
  1140. len += formatex(menu[len], sizeof menu - 1 - len, "\r%d.\w %s -\y %s\w - %L %d^n", class-ZCLASSES_STARTID+1, g_zclass_name[class], g_zclass_info[class], id, "BOTH_ATTRIB_LEVEL", g_zclass_lvl[class]);
  1141. }
  1142. }
  1143. #endif
  1144.  
  1145. // 8. Back - 9. Next - 0. Exit
  1146. len += formatex(menu[len], sizeof menu - 1 - len, "^n\r8.\w %L^n\r9.\w %L^n^n\r0.\w %L", id, "MENU_BACK", id, "MENU_NEXT", id, "MENU_EXIT")
  1147.  
  1148. show_menu(id, KEYSMENU, menu, -1, "Zombie Class Menu")
  1149. }
  1150.  
  1151.  
  1152. public show_menu_hclass(id)
  1153. {
  1154. // Player disconnected
  1155. if (!is_user_connected(id))
  1156. return;
  1157.  
  1158. // Bots pick default classes
  1159. if (is_user_bot(id))
  1160. {
  1161. g_humanclassnext[id] = 0
  1162. return;
  1163. }
  1164.  
  1165. static menu[800], len, class, removexp
  1166. new curClassIcon[2]
  1167. len = 0
  1168. removexp = get_pcvar_num(cvar_removexp);
  1169.  
  1170. // Title
  1171. len += formatex(menu[len], sizeof menu - 1 - len, "\y%L \r[%d-%d]^n^n", id, "MENU_HCLASS_TITLE", HCLASSES_STARTID+1, min(HCLASSES_STARTID+7, g_hclass_i))
  1172.  
  1173. #if defined ZP_ALIGN_TEXT
  1174. // Align text
  1175. new spacers[400], g_hclass_spacers1, g_hclass_spacers2
  1176. new maxSpace1, maxSpace2, curSpace1[32], curSpace2[32]
  1177.  
  1178. // Get max width first
  1179. for (class = HCLASSES_STARTID; class < min(HCLASSES_STARTID+7, g_hclass_i); class++)
  1180. {
  1181. formatex(spacers, sizeof spacers - 1, "%d. %s", class-HCLASSES_STARTID+1, g_hclass_name[class])
  1182.  
  1183. g_hclass_spacers1 = strlen(spacers)
  1184. g_hclass_spacers2 = strlen(g_hclass_info[class])
  1185.  
  1186. if(g_hclass_spacers1 > maxSpace1) maxSpace1 = g_hclass_spacers1
  1187. if(g_hclass_spacers2 > maxSpace2) maxSpace2 = g_hclass_spacers2
  1188. }
  1189.  
  1190. // 1-7. Class List
  1191. for (class = HCLASSES_STARTID; class < min(HCLASSES_STARTID+7, g_hclass_i); class++)
  1192. {
  1193. formatex(spacers, sizeof spacers - 1, "%d. %s", class-HCLASSES_STARTID+1, g_hclass_name[class])
  1194.  
  1195. g_hclass_spacers1 = maxSpace1 - strlen(spacers)
  1196. g_hclass_spacers2 = maxSpace2 - strlen(g_hclass_info[class])
  1197.  
  1198. arrayset(curSpace1, '^0', sizeof curSpace1 - 1)
  1199. arrayset(curSpace2, '^0', sizeof curSpace2 - 1)
  1200.  
  1201. if(g_hclass_spacers1 != 0) arrayset(curSpace1, '^t', g_hclass_spacers1)
  1202. if(g_hclass_spacers2 != 0) arrayset(curSpace2, '^t', g_hclass_spacers2)
  1203.  
  1204. if (((class == g_humanclassnext[id] && g_hclass_showmenu[id] == false) || (userLevel[id] < g_hclass_lvl[class])) && (removexp == 0))
  1205. {
  1206. if (class == g_humanclassnext[id]) { curClassIcon = "*"; } else { curClassIcon = ""; }
  1207.  
  1208. len += formatex(menu[len], sizeof menu - 1 - len, "\d%s%d. %s %s %s %s %L %d^n", curClassIcon, class-HCLASSES_STARTID+1, g_hclass_name[class], curSpace1, g_hclass_info[class], curSpace2, id, "BOTH_ATTRIB_LEVEL", g_hclass_lvl[class])
  1209. } else if (removexp == 1) {
  1210. len += formatex(menu[len], sizeof menu - 1 - len, "\r%d.\w %s\y %s %s^n", class-HCLASSES_STARTID+1, g_hclass_name[class], curSpace1, g_hclass_info[class])
  1211. } else {
  1212. len += formatex(menu[len], sizeof menu - 1 - len, "\r%d.\w %s\y %s %s\w %s %L %d^n", class-HCLASSES_STARTID+1, g_hclass_name[class], curSpace1, g_hclass_info[class], curSpace2, id, "BOTH_ATTRIB_LEVEL", g_hclass_lvl[class])
  1213. }
  1214. }
  1215.  
  1216. #else
  1217. for (class = HCLASSES_STARTID; class < min(HCLASSES_STARTID+7, g_hclass_i); class++)
  1218. {
  1219. if (((class == g_humanclassnext[id] && g_hclass_showmenu[id] == false) || (userLevel[id] < g_hclass_lvl[class])) && (removexp == 0))
  1220. {
  1221. if (class == g_humanclassnext[id]) { curClassIcon = "*"; } else { curClassIcon = ""; }
  1222.  
  1223. len += formatex(menu[len], sizeof menu - 1 - len, "\d%s%d. %s - %s - %L %d^n", curClassIcon, class-HCLASSES_STARTID+1, g_hclass_name[class], g_hclass_info[class], id, "BOTH_ATTRIB_LEVEL", g_hclass_lvl[class])
  1224. } else if (removexp == 1) {
  1225. len += formatex(menu[len], sizeof menu - 1 - len, "\r%d.\w %s -\y %s^n", class-HCLASSES_STARTID+1, g_hclass_name[class], g_hclass_info[class]);
  1226. } else {
  1227. len += formatex(menu[len], sizeof menu - 1 - len, "\r%d.\w %s -\y %s\w - %L %d^n", class-HCLASSES_STARTID+1, g_hclass_name[class], g_hclass_info[class], id, "BOTH_ATTRIB_LEVEL", g_hclass_lvl[class])
  1228. }
  1229. }
  1230. #endif
  1231.  
  1232. // 8. Back - 9. Next - 0. Exit
  1233. len += formatex(menu[len], sizeof menu - 1 - len, "^n\r8.\w %L^n\r9.\w %L^n^n\r0.\w %L", id, "MENU_BACK", id, "MENU_NEXT", id, "MENU_EXIT")
  1234.  
  1235. show_menu(id, KEYSMENU, menu, -1, "Human Class Menu")
  1236. }
  1237.  
  1238. /* ----------------------- Menu Handlers -------------------------*/
  1239.  
  1240. // Game Menu
  1241. public menu_game(id, key)
  1242. {
  1243. if(get_pcvar_num(cvar_removexp) == 1) key++;
  1244.  
  1245. switch (key)
  1246. {
  1247. case 0: // Buy a level up
  1248. {
  1249. if(getAmmoPacks(id) >= getNeededPacks(id))
  1250. {
  1251. setAmmoPacks(id, getAmmoPacks(id) - getNeededPacks(id))
  1252. userLevel[id] += 1
  1253. save_data(id)
  1254.  
  1255. // Inform the user they leveled up
  1256. zp_colored_print(id, "^x04%s^x01 %L %d", textHeader, id ,"MENU_BUY_LEVEL", userLevel[id])
  1257. ShowHUD(id)
  1258. } else {
  1259. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id ,"ERR_NOTENOUGHPACKS")
  1260. }
  1261.  
  1262. // Return to the main xp menu
  1263. show_menu_game(id);
  1264.  
  1265. }
  1266.  
  1267. case 1: // Human Classes
  1268. {
  1269. // Restrict it here if we wanted to
  1270. show_menu_hclass(id)
  1271. }
  1272.  
  1273. case 2: // Zombie Classes
  1274. {
  1275. if (get_pcvar_num(cvar_removezombie) == 0)
  1276. {
  1277. // Restrict it here if we wanted to
  1278. show_menu_zclass(id)
  1279. }
  1280. }
  1281. }
  1282.  
  1283. return PLUGIN_HANDLED;
  1284. }
  1285.  
  1286. // Zombie Class Menu
  1287. public menu_zclass(id, key)
  1288. {
  1289. // Special keys / items list exceeded
  1290. if (key >= MENU_KEY_BACK || ZCLASSES_SELECTION >= g_zclass_i)
  1291. {
  1292. switch (key)
  1293. {
  1294. case MENU_KEY_BACK: // back
  1295. {
  1296. if (ZCLASSES_STARTID-7 >= 0) ZCLASSES_STARTID -= 7
  1297. }
  1298. case MENU_KEY_NEXT: // next
  1299. {
  1300. if (ZCLASSES_STARTID+7 < g_zclass_i) ZCLASSES_STARTID += 7
  1301. }
  1302. case MENU_KEY_EXIT: // exit
  1303. {
  1304. return PLUGIN_HANDLED;
  1305. }
  1306. }
  1307.  
  1308. // Show extra items menu again
  1309. show_menu_zclass(id)
  1310. return PLUGIN_HANDLED;
  1311. }
  1312.  
  1313. // They selected their own class
  1314. if (ZCLASSES_SELECTION == g_zombieclassnext[id])
  1315. {
  1316. //Plugin continues if this is false (sets class info on connect)
  1317. if( g_zclass_showmenu[id] == false) //when a client first connects, the menu shows all zombies as a choice even the one the client defaults to (index of 0)
  1318. {
  1319. // Alert them they already have chosen a zombie
  1320. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "ERR_ALREADYSELECTED")
  1321. show_menu_zclass(id)
  1322.  
  1323. // They had already chosen this zombie, dont rerun the command
  1324. return PLUGIN_HANDLED;
  1325. }
  1326. }
  1327.  
  1328. if (get_pcvar_num(cvar_removexp) == 0)
  1329. {
  1330. if (g_zclass_lvl[HCLASSES_SELECTION] > userLevel[id])
  1331. {
  1332. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "ERR_NOTLEVEL")
  1333. show_menu_zclass(id)
  1334. return PLUGIN_HANDLED;
  1335. }
  1336. }
  1337.  
  1338. // Store selection for the next infection
  1339. g_zombieclassnext[id] = ZCLASSES_SELECTION;
  1340.  
  1341. // Disable showing menu since theyve chosen
  1342. g_zclass_showmenu[id] = false;
  1343.  
  1344. // Show selected zombie class info and stats
  1345. zp_colored_print(id, "^x04%s^x01 %L: %s", textHeader, id, "ZOMBIE_SELECT_XP", g_zclass_name[g_zombieclassnext[id]])
  1346. zp_colored_print(id, "^x04%s^x01 %L: %d %L: %d %L: %d %L: %d%%", textHeader, id, "ZOMBIE_ATTRIB1_XP", g_zclass_hp[g_zombieclassnext[id]], id, "ZOMBIE_ATTRIB2_XP", g_zclass_spd[g_zombieclassnext[id]],
  1347. id, "ZOMBIE_ATTRIB3_XP", floatround(g_zclass_grav[g_zombieclassnext[id]]*800), id, "ZOMBIE_ATTRIB4_XP", floatround(g_zclass_kb[g_zombieclassnext[id]]*100))
  1348.  
  1349. // Set the class for zombie plague
  1350. zp_set_user_zombie_class(id, g_zombieclassnext[id])
  1351.  
  1352. return PLUGIN_HANDLED;
  1353. }
  1354.  
  1355. // Human Class Menu
  1356. public menu_hclass(id, key)
  1357. {
  1358. // Special keys / items list exceeded
  1359. if (key >= MENU_KEY_BACK || HCLASSES_SELECTION >= g_hclass_i)
  1360. {
  1361. switch (key)
  1362. {
  1363. case MENU_KEY_BACK: // back
  1364. {
  1365. if (HCLASSES_STARTID-7 >= 0) HCLASSES_STARTID -= 7
  1366. }
  1367. case MENU_KEY_NEXT: // next
  1368. {
  1369. if (HCLASSES_STARTID+7 < g_hclass_i) HCLASSES_STARTID += 7
  1370. }
  1371. case MENU_KEY_EXIT: // exit
  1372. {
  1373. return PLUGIN_HANDLED;
  1374. }
  1375. }
  1376.  
  1377. // Show human list again
  1378. show_menu_hclass(id)
  1379. return PLUGIN_HANDLED;
  1380. }
  1381.  
  1382. if (HCLASSES_SELECTION == g_humanclassnext[id])
  1383. {
  1384. // When a client first connects, the menu shows all zombies as a choice even the one the client defaults to (index of 0)
  1385. if( g_hclass_showmenu[id] == false)
  1386. {
  1387. // Alert them they alaerdy have chosen a zombie
  1388. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "ERR_ALREADYSELECTED")
  1389. show_menu_hclass(id)
  1390. return PLUGIN_HANDLED; //they had already chosen this zombie, dont rerun the command
  1391. }
  1392. }
  1393.  
  1394. if (get_pcvar_num(cvar_removexp) == 0)
  1395. {
  1396. if (g_hclass_lvl[HCLASSES_SELECTION] > userLevel[id])
  1397. {
  1398. zp_colored_print(id, "^x04%s^x01 %L", textHeader, id, "ERR_NOTLEVEL")
  1399. show_menu_hclass(id)
  1400. return PLUGIN_HANDLED;
  1401. }
  1402. }
  1403.  
  1404. // Store selection for the next infection
  1405. g_humanclassnext[id] = HCLASSES_SELECTION;
  1406.  
  1407. // Disable showing menu since theyve chosen
  1408. g_hclass_showmenu[id] = false;
  1409.  
  1410. // Show selected human class info and stats
  1411. zp_colored_print(id, "^x04%s^x01 %L: %s", textHeader, id, "HUMAN_SELECT_XP", g_hclass_name[g_humanclassnext[id]])
  1412. zp_colored_print(id, "^x04%s^x01 %L: %d %L: %d %L: %d", textHeader, id, "HUMAN_ATTRIB1_XP", g_hclass_hp[g_humanclassnext[id]], id, "HUMAN_ATTRIB2_XP", g_hclass_spd[g_humanclassnext[id]],
  1413. id, "HUMAN_ATTRIB3_XP", floatround(g_hclass_grav[g_humanclassnext[id]]*800), id)
  1414.  
  1415. return PLUGIN_HANDLED;
  1416. }
  1417.  
  1418. public ShowHUD(taskid)
  1419. {
  1420. //if (get_pcvar_num(cvar_removexp) == 1 ) return;
  1421.  
  1422. static id;
  1423.  
  1424. // Our ID
  1425. id = ID_SHOWHUD;
  1426.  
  1427. // Player died?
  1428. if (!is_user_alive(id))
  1429. {
  1430. // Get spectating target
  1431. id = pev(id, PEV_SPEC_TARGET) //other persons ID
  1432.  
  1433. // Target not alive
  1434. if (!is_user_alive(id)) return;
  1435. }
  1436.  
  1437. // Format the classname
  1438. static red, green, blue, g_name[sizeof g_hclass_name]; // Hopefully g_zclass_name and g_zclass_name will be left the same array size
  1439.  
  1440. if ( g_human[id] == false ) // zombies
  1441. {
  1442. red = 0
  1443. green = 255
  1444. blue = 0
  1445.  
  1446. formatex(g_name, sizeof g_name - 1, "%L", id, "HUD_ZOMBIE");
  1447. }
  1448. else // humans
  1449. {
  1450. red = 0
  1451. green = 255
  1452. blue = 0
  1453.  
  1454. copy(g_name, sizeof g_name - 1, g_hclass_name[g_humanclass[id]]);
  1455. }
  1456.  
  1457. if (id != ID_SHOWHUD)
  1458. {
  1459. if (get_pcvar_num(cvar_removexp) == 0 )
  1460. {
  1461. // Set our HUD in position for spectating
  1462. set_hudmessage(255, 255, 255, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1);
  1463. ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync2, "%L: %s - %L: %d", ID_SHOWHUD, "HUD_CLASS", g_name, ID_SHOWHUD, "HUD_LEVEL", userLevel[id]);
  1464. } else {
  1465. // Just show the class information
  1466. set_hudmessage(255, 255, 255, HUD_SPECT_X, HUD_SPECT_Y, 0, 6.0, 1.1, 0.0, 0.0, -1);
  1467. ShowSyncHudMsg(ID_SHOWHUD, g_MsgSync2, "%L: %s", ID_SHOWHUD, "HUD_CLASS", g_name);
  1468. }
  1469. } else {
  1470. if (get_pcvar_num(cvar_removexp) == 0 )
  1471. {
  1472. // Set our HUD in position for the player
  1473. set_hudmessage(red, green, blue, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1);
  1474. ShowSyncHudMsg(id, g_MsgSync2, "%L: %s - %L: %d^t^t^t", id, "HUD_CLASS", g_name, id, "HUD_LEVEL", userLevel[id]);
  1475. } else {
  1476. // Just show the class information
  1477. set_hudmessage(red, green, blue, HUD_STATS_X, HUD_STATS_Y, 0, 6.0, 1.1, 0.0, 0.0, -1);
  1478. ShowSyncHudMsg(id, g_MsgSync2, "%L: %s^t^t^t", id, "HUD_CLASS", g_name);
  1479. }
  1480. }
  1481. }
  1482.  
  1483. // Native: native_get_user_human_class
  1484. public native_get_user_human_class(id)
  1485. {
  1486. return g_humanclass[id];
  1487. }
  1488.  
  1489. // Native: zpxp_register_human_class
  1490. public native_register_human_class(const name[], const info[], const model[], const weapons[], hp, speed, Float:gravity, level)
  1491. {
  1492. // Reached human classes limit
  1493. if (g_hclass_i >= sizeof g_hclass_name)
  1494. return -1;
  1495.  
  1496. // Strings passed byref
  1497. param_convert(1)
  1498. param_convert(2)
  1499. param_convert(3)
  1500. param_convert(4)
  1501.  
  1502. // Add the class
  1503. copy(g_hclass_name[g_hclass_i], sizeof g_hclass_name[] - 1, name)
  1504. copy(g_hclass_info[g_hclass_i], sizeof g_hclass_info[] - 1, info)
  1505. copy(g_hclass_model[g_hclass_i], sizeof g_hclass_model[] - 1, model)
  1506. copy(g_hclass_weapons[g_hclass_i], sizeof g_hclass_weapons[] - 1, weapons)
  1507. g_hclass_hp[g_hclass_i] = hp
  1508. g_hclass_spd[g_hclass_i] = speed
  1509. g_hclass_grav[g_hclass_i] = gravity
  1510. g_hclass_lvl[g_hclass_i] = level
  1511.  
  1512.  
  1513. // For the load_data and save_data
  1514. new tSave[40]
  1515. formatex(tSave, sizeof tSave - 1, "%s%s", name, info);
  1516. replace_all(tSave, sizeof tSave - 1, ";", "")
  1517. replace_all(tSave, sizeof tSave - 1, " ", "")
  1518. g_hclass_load[g_hclass_i] = tSave;
  1519.  
  1520. // Increase registered classes counter
  1521. g_hclass_i++
  1522.  
  1523. // Return id under which we registered the class
  1524. return g_hclass_i-1;
  1525. }
  1526.  
  1527. // Native: zpxp_register_zombie_class
  1528. public native_register_zombie_class(const name[], const info[], const model[], const clawmodel[], hp, speed, Float:gravity, Float:knockback, level)
  1529. {
  1530. // Dont return -1, we wil get lots of server window print errors from the plugins
  1531. if( get_pcvar_num(cvar_removezombie) == 2) return 0;
  1532.  
  1533. //Bugfix for loading zombies
  1534. loadedZombies = true;
  1535.  
  1536. // Strings passed byref
  1537. param_convert(1)
  1538. param_convert(2)
  1539. param_convert(3)
  1540. param_convert(4)
  1541.  
  1542. // Save the name, level required, and classid
  1543. copy(g_zclass_name[g_zclass_i], sizeof g_zclass_name[] - 1, name)
  1544. copy(g_zclass_info[g_zclass_i], sizeof g_zclass_info[] - 1, info)
  1545. copy(g_zclass_model[g_zclass_i], sizeof g_zclass_model[] - 1, model)
  1546. copy(g_zclass_clawmodel[g_zclass_i], sizeof g_zclass_clawmodel[] - 1, clawmodel)
  1547.  
  1548. g_zclass_hp[g_zclass_i] = hp
  1549. g_zclass_spd[g_zclass_i] = speed
  1550. g_zclass_grav[g_zclass_i] = gravity
  1551. g_zclass_kb[g_zclass_i] = knockback
  1552. g_zclass_lvl[g_zclass_i] = level
  1553.  
  1554. // For the load_data and save_data
  1555. new tSave[40]
  1556. formatex(tSave, sizeof tSave - 1, "%s%s", name, info);
  1557. replace_all(tSave, sizeof tSave - 1, ";", "")
  1558. replace_all(tSave, sizeof tSave - 1, " ", "")
  1559. g_zclass_load[g_zclass_i] = tSave;
  1560.  
  1561. // Get the classid from zombie plague
  1562. new g_returnclass_id;
  1563. g_returnclass_id = zp_register_zombie_class(g_zclass_name[g_zclass_i], g_zclass_info[g_zclass_i], g_zclass_model[g_zclass_i], g_zclass_clawmodel[g_zclass_i], g_zclass_hp[g_zclass_i] / 2, g_zclass_spd[g_zclass_i], g_zclass_grav[g_zclass_i], g_zclass_kb[g_zclass_i]);
  1564.  
  1565. // Make sure there was no error
  1566. if( g_returnclass_id == -1 )
  1567. {
  1568. server_print("%s %L", textHeader, LANG_PLAYER, "ERR_BADRETURN");
  1569. return -1
  1570. }
  1571.  
  1572. // Increase registered classes counter
  1573. g_zclass_i++
  1574.  
  1575. // Return id under which we registered the class
  1576. return g_zclass_i-1;
  1577. }
  1578.  
  1579. public native_register_extra_item(const name[], cost, team)
  1580. {
  1581. //TO DO
  1582.  
  1583. }
  1584.  
  1585. /*================================================================================
  1586. --The following are copied directly from zombie_plague, no reinventing wheels...
  1587. [Shared Functions]
  1588. =================================================================================*/
  1589.  
  1590. // Welcome Message Task
  1591. public welcome_msg()
  1592. {
  1593. // Show mod info
  1594. zp_colored_print(0, "^x04%s^x01 %L", textHeaderOrig, LANG_PLAYER, "NOTICE_INFO_XP")
  1595. }
  1596.  
  1597. // Log Event Round Start
  1598. public logevent_round_start()
  1599. {
  1600. // Freezetime ends
  1601. g_freezetime = false
  1602. }
  1603.  
  1604. // Get User Team
  1605. stock fm_get_user_team(id)
  1606. {
  1607. return get_pdata_int(id, OFFSET_CSTEAMS, OFFSET_LINUX);
  1608. }
  1609.  
  1610. zp_colored_print(target, const message[], any:...)
  1611. {
  1612. static buffer[512], i, argscount
  1613. argscount = numargs()
  1614.  
  1615. // Send to everyone
  1616. if (!target)
  1617. {
  1618. static player
  1619. for (player = 1; player <= g_maxplayers; player++)
  1620. {
  1621. // Not connected
  1622. if (!is_user_connected(player))
  1623. continue;
  1624.  
  1625. // Remember changed arguments
  1626. static changed[5], changedcount // [5] = max LANG_PLAYER occurencies
  1627. changedcount = 0
  1628.  
  1629. // Replace LANG_PLAYER with player id
  1630. for (i = 2; i < argscount; i++)
  1631. {
  1632. if (getarg(i) == LANG_PLAYER)
  1633. {
  1634. setarg(i, 0, player)
  1635. changed[changedcount] = i
  1636. changedcount++
  1637. }
  1638. }
  1639.  
  1640. // Format message for player
  1641. vformat(buffer, sizeof buffer - 1, message, 3)
  1642.  
  1643. // Send it
  1644. message_begin(MSG_ONE, g_msgSayText, _, player)
  1645. write_byte(player)
  1646. write_string(buffer)
  1647. message_end()
  1648.  
  1649. // Replace back player id's with LANG_PLAYER
  1650. for (i = 0; i < changedcount; i++)
  1651. setarg(changed[i], 0, LANG_PLAYER)
  1652. }
  1653. }
  1654.  
  1655. // Send to specific target
  1656. else
  1657. {
  1658. // Replace LANG_PLAYER with player id
  1659. for (i = 2; i < argscount; i++)
  1660. {
  1661. if (getarg(i) == LANG_PLAYER)
  1662. setarg(i, 0, target)
  1663. }
  1664.  
  1665. // Format message for player
  1666. vformat(buffer, sizeof buffer - 1, message, 3)
  1667.  
  1668. // Send it
  1669. message_begin(MSG_ONE, g_msgSayText, _, target)
  1670. write_byte(target)
  1671. write_string(buffer)
  1672. message_end()
  1673. }
  1674. }
  1675.  
  1676. /*================================================================================
  1677. Code JUST for giving guns
  1678. ================================================================================*/
  1679.  
  1680. // Drop primary/secondary weapons
  1681. stock drop_weapons(id, dropwhat)
  1682. {
  1683. // Get user weapons
  1684. static weapons[32], num, i, weaponid
  1685. num = 0 // reset passed weapons count (bugfix)
  1686. get_user_weapons(id, weapons, num)
  1687.  
  1688. // Loop through them and drop primaries or secondaries
  1689. for (i = 0; i < num; i++)
  1690. {
  1691. // Prevent re-indexing the array
  1692. weaponid = weapons[i]
  1693.  
  1694. if ((dropwhat == 1 && ((1<<weaponid) & PRIMARY_WEAPONS_BIT_SUM)) || (dropwhat == 2 && ((1<<weaponid) & SECONDARY_WEAPONS_BIT_SUM)))
  1695. {
  1696. // Get the weapon entity
  1697. static wname[32], weapon_ent
  1698. get_weaponname(weaponid, wname, sizeof wname - 1)
  1699. weapon_ent = fm_find_ent_by_owner(-1, wname, id);
  1700.  
  1701. // Hack: store weapon bpammo on PEV_ADDITIONAL_AMMO
  1702. set_pev(weapon_ent, PEV_ADDITIONAL_AMMO, fm_get_user_bpammo(id, weaponid))
  1703.  
  1704. // Player drops the weapon and looses his bpammo
  1705. engclient_cmd(id, "drop", wname)
  1706. fm_set_user_bpammo(id, weaponid, 0)
  1707. }
  1708. }
  1709. }
  1710.  
  1711. // Set User BP Ammo
  1712. stock fm_set_user_bpammo(id, weapon, amount)
  1713. {
  1714. static offset
  1715.  
  1716. switch(weapon)
  1717. {
  1718. case CSW_AWP: offset = OFFSET_AWM_AMMO;
  1719. case CSW_SCOUT,CSW_AK47,CSW_G3SG1: offset = OFFSET_SCOUT_AMMO;
  1720. case CSW_M249: offset = OFFSET_PARA_AMMO;
  1721. case CSW_M4A1,CSW_FAMAS,CSW_AUG,CSW_SG550,CSW_GALI,CSW_SG552: offset = OFFSET_FAMAS_AMMO;
  1722. case CSW_M3,CSW_XM1014: offset = OFFSET_M3_AMMO;
  1723. case CSW_USP,CSW_UMP45,CSW_MAC10: offset = OFFSET_USP_AMMO;
  1724. case CSW_FIVESEVEN,CSW_P90: offset = OFFSET_FIVESEVEN_AMMO;
  1725. case CSW_DEAGLE: offset = OFFSET_DEAGLE_AMMO;
  1726. case CSW_P228: offset = OFFSET_P228_AMMO;
  1727. case CSW_GLOCK18,CSW_MP5NAVY,CSW_TMP,CSW_ELITE: offset = OFFSET_GLOCK_AMMO;
  1728. case CSW_FLASHBANG: offset = OFFSET_FLASH_AMMO;
  1729. case CSW_HEGRENADE: offset = OFFSET_HE_AMMO;
  1730. case CSW_SMOKEGRENADE: offset = OFFSET_SMOKE_AMMO;
  1731. case CSW_C4: offset = OFFSET_C4_AMMO;
  1732. default: return;
  1733. }
  1734.  
  1735. set_pdata_int(id, offset, amount, OFFSET_LINUX)
  1736. }
  1737.  
  1738. // Get User BP Ammo
  1739. stock fm_get_user_bpammo(id, weapon)
  1740. {
  1741. static offset
  1742.  
  1743. switch(weapon)
  1744. {
  1745. case CSW_AWP: offset = OFFSET_AWM_AMMO;
  1746. case CSW_SCOUT,CSW_AK47,CSW_G3SG1: offset = OFFSET_SCOUT_AMMO;
  1747. case CSW_M249: offset = OFFSET_PARA_AMMO;
  1748. case CSW_M4A1,CSW_FAMAS,CSW_AUG,CSW_SG550,CSW_GALI,CSW_SG552: offset = OFFSET_FAMAS_AMMO;
  1749. case CSW_M3,CSW_XM1014: offset = OFFSET_M3_AMMO;
  1750. case CSW_USP,CSW_UMP45,CSW_MAC10: offset = OFFSET_USP_AMMO;
  1751. case CSW_FIVESEVEN,CSW_P90: offset = OFFSET_FIVESEVEN_AMMO;
  1752. case CSW_DEAGLE: offset = OFFSET_DEAGLE_AMMO;
  1753. case CSW_P228: offset = OFFSET_P228_AMMO;
  1754. case CSW_GLOCK18,CSW_MP5NAVY,CSW_TMP,CSW_ELITE: offset = OFFSET_GLOCK_AMMO;
  1755. case CSW_FLASHBANG: offset = OFFSET_FLASH_AMMO;
  1756. case CSW_HEGRENADE: offset = OFFSET_HE_AMMO;
  1757. case CSW_SMOKEGRENADE: offset = OFFSET_SMOKE_AMMO;
  1758. case CSW_C4: offset = OFFSET_C4_AMMO;
  1759. default: return -1;
  1760. }
  1761.  
  1762. return get_pdata_int(id, offset, OFFSET_LINUX);
  1763. }
  1764.  
  1765. // Give an item to a player (from fakemeta_util)
  1766. stock fm_give_item(id, const item[])
  1767. {
  1768. static ent
  1769. ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, item))
  1770. if (!pev_valid(ent)) return;
  1771.  
  1772. static Float:originF[3]
  1773. pev(id, pev_origin, originF)
  1774. set_pev(ent, pev_origin, originF)
  1775. set_pev(ent, pev_spawnflags, pev(ent, pev_spawnflags) | SF_NORESPAWN)
  1776. dllfunc(DLLFunc_Spawn, ent)
  1777.  
  1778. static save
  1779. save = pev(ent, pev_solid)
  1780. dllfunc(DLLFunc_Touch, ent, id)
  1781. if (pev(ent, pev_solid) != save)
  1782. return;
  1783.  
  1784. engfunc(EngFunc_RemoveEntity, ent)
  1785. }
  1786.  
  1787. // Strip user weapons (from fakemeta_util)
  1788. stock fm_strip_user_weapons(id)
  1789. {
  1790. static ent
  1791. ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "player_weaponstrip"))
  1792. if (!pev_valid(ent)) return;
  1793.  
  1794. dllfunc(DLLFunc_Spawn, ent)
  1795. dllfunc(DLLFunc_Use, ent, id)
  1796. engfunc(EngFunc_RemoveEntity, ent)
  1797. }
  1798.  
  1799.  
  1800. // Find entity by its owner (from fakemeta_util)
  1801. stock fm_find_ent_by_owner(entity, const classname[], owner)
  1802. {
  1803. while ((entity = engfunc(EngFunc_FindEntityByString, entity, "classname", classname)) && pev(entity, pev_owner) != owner) {}
  1804.  
  1805. return entity;
  1806. }
  1807.  
  1808. strip_weapons (id)
  1809. {
  1810. if( !get_pcvar_num(cvar_removeweapons) )
  1811. {
  1812. // Drop previous weapons
  1813. drop_weapons(id, 1)
  1814. drop_weapons(id, 2)
  1815. }
  1816.  
  1817. // Strip off from weapons
  1818. fm_strip_user_weapons(id)
  1819. fm_give_item(id, "weapon_knife")
  1820. }
  1821.  
  1822. // Buy Primary Weapon
  1823. give_primary_weapon(id, key)
  1824. {
  1825. // Get weapon index
  1826. static weaponid
  1827. weaponid = get_weaponid(g_primary_items[key])
  1828.  
  1829. // Give the new weapon
  1830. fm_give_item(id, g_primary_items[key])
  1831. fm_set_user_bpammo(id, weaponid, MAXBPAMMO[key])
  1832.  
  1833. /*
  1834. // Give additional items
  1835. static i
  1836. for (i = 0; i < sizeof g_additional_items; i++)
  1837. fm_give_item(id, g_additional_items[i])
  1838. */
  1839. }
  1840.  
  1841. give_secondary_weapon(id, key)
  1842. {
  1843. // Get weapon index
  1844. static weaponid
  1845. weaponid = get_weaponid(g_secondary_items[key])
  1846.  
  1847. // Give the new weapon with full ammo
  1848. fm_give_item(id, g_secondary_items[key])
  1849. fm_set_user_bpammo(id, weaponid, MAXBPAMMO[weaponid])
  1850.  
  1851. }
  1852. /*================================================================================
  1853. End Code just for giving guns
  1854. ================================================================================*/
Add Comment
Please, Sign In to add comment