HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2. * _______ _ _ __ __
  3. * | _____/ | | | | \ \ __ / /
  4. * | | | | | | | | / \ | |
  5. * | | | |____| | | |/ __ \| |
  6. * | | ___ | ______ | | / \ |
  7. * | | |_ | | | | | | / \ |
  8. * | | | | | | | | | | | |
  9. * | |____| | | | | | | | | |
  10. * |_______/ |_| |_| \_/ \_/
  11. *
  12. *
  13. *
  14. * Last Edited: 07-04-09
  15. *
  16. * ============
  17. * Changelog:
  18. * ============
  19. *
  20. * v2.2
  21. * -Added Off / Admin only capabilities
  22. *
  23. * v2.1
  24. * -Added some pets
  25. * -Fixed death animations
  26. * -Fixed chat text bug
  27. *
  28. * v2.0
  29. * -Added ML
  30. *
  31. * v1.0
  32. * -Initial Release
  33. *
  34. */
  35.  
  36. #define VERSION "2.2"
  37.  
  38. #include <amxmodx>
  39. #include <amxmisc>
  40. #include <chr_engine>
  41.  
  42. #define PET_NUM 17
  43.  
  44. static const pet_name[PET_NUM][32] =
  45. {
  46. "Headcrab",
  47. "Rat",
  48. "Bat",
  49. "Frog",
  50. "Floater",
  51. "Cockroach",
  52. "Hyper Bat",
  53. "Mom",
  54. "Grunt",
  55. "Fish",
  56. "Baby Headcrab",
  57. "Roach",
  58. "Gargantuan",
  59. "Bull Squid",
  60. "Hound Eye",
  61. "Loading Machine",
  62. "Controller"
  63. }
  64.  
  65. static const pet_models[PET_NUM][32] =
  66. {
  67. "models/headcrab.mdl",
  68. "models/bigrat.mdl",
  69. "models/boid.mdl",
  70. "models/chumtoad.mdl",
  71. "models/floater.mdl",
  72. "models/roach.mdl",
  73. "models/stukabat.mdl",
  74. "models/big_mom.mdl",
  75. "models/agrunt.mdl",
  76. "models/archer.mdl",
  77. "models/baby_headcrab.mdl",
  78. "models/roach.mdl",
  79. "models/garg.mdl",
  80. "models/bullsquid.mdl",
  81. "models/houndeye.mdl",
  82. "models/loader.mdl",
  83. "models/controller.mdl"
  84. }
  85.  
  86. static const pet_idle[PET_NUM] =
  87. {
  88. 0,
  89. 1,
  90. 0,
  91. 0,
  92. 0,
  93. 1,
  94. 13,
  95. 0,
  96. 0,
  97. 0,
  98. 1,
  99. 0,
  100. 7,
  101. 1,
  102. 1,
  103. 3,
  104. 3
  105. }
  106.  
  107. static const Float:pet_idle_speed[PET_NUM] =
  108. {
  109. 1.0,
  110. 1.0,
  111. 1.0,
  112. 1.0,
  113. 1.0,
  114. 1.0,
  115. 0.5,
  116. 1.0,
  117. 1.0,
  118. 1.0,
  119. 1.0,
  120. 1.0,
  121. 1.0,
  122. 1.0,
  123. 1.0,
  124. 1.0,
  125. 1.0
  126. }
  127.  
  128. static const pet_run[PET_NUM] =
  129. {
  130. 4,
  131. 4,
  132. 0,
  133. 5,
  134. 0,
  135. 0,
  136. 13,
  137. 3,
  138. 3,
  139. 6,
  140. 4,
  141. 0,
  142. 4,
  143. 0,
  144. 3,
  145. 2,
  146. 9
  147. }
  148.  
  149. static const Float:pet_run_speed[PET_NUM] =
  150. {
  151. 2.0,
  152. 6.0,
  153. 3.0,
  154. 0.75,
  155. 1.0,
  156. 1.0,
  157. 13.0,
  158. 1.0,
  159. 1.0,
  160. 0.6,
  161. 0.6,
  162. 1.0,
  163. 1.0,
  164. 2.0,
  165. 1.0,
  166. 0.4,
  167. 1.0
  168. }
  169.  
  170. static const pet_die[PET_NUM] =
  171. {
  172. 7,
  173. 7,
  174. 0,
  175. 12,
  176. 0,
  177. 0,
  178. 5,
  179. 4,
  180. 22,
  181. 9,
  182. 7,
  183. 1,
  184. 14,
  185. 16,
  186. 6,
  187. 5,
  188. 18
  189. }
  190.  
  191. static const Float:pet_die_length[PET_NUM] =
  192. {
  193. 2.4,
  194. 2.4,
  195. 0.1,
  196. 3.0,
  197. 0.1,
  198. 0.1,
  199. 3.0,
  200. 5.0,
  201. 5.0,
  202. 3.0,
  203. 3.0,
  204. 1.0,
  205. 6.0,
  206. 2.5,
  207. 2.5,
  208. 7.0,
  209. 7.0
  210. }
  211.  
  212. static const Float:pet_minus_z_standing[PET_NUM] =
  213. {
  214. 36.0,
  215. 36.0,
  216. 5.0,
  217. 36.0,
  218. 5.0,
  219. 36.0,
  220. 10.0,
  221. 36.0,
  222. 36.0,
  223. 20.0,
  224. 36.0,
  225. 36.0,
  226. 36.0,
  227. 36.0,
  228. 36.0,
  229. 36.0,
  230. 0.0
  231. }
  232.  
  233. static const Float:pet_minus_z_crouching[PET_NUM] =
  234. {
  235. 16.0,
  236. 16.0,
  237. 6.0,
  238. 16.0,
  239. 6.0,
  240. 16.0,
  241. 11.0,
  242. 16.0,
  243. 16.0,
  244. 30.0,
  245. 16.0,
  246. 16.0,
  247. 16.0,
  248. 16.0,
  249. 16.0,
  250. 16.0,
  251. 0.0
  252. }
  253.  
  254. static const Float:pet_max_distance[PET_NUM] =
  255. {
  256. 300.0,
  257. 300.0,
  258. 300.0,
  259. 300.0,
  260. 300.0,
  261. 300.0,
  262. 300.0,
  263. 1000.0,
  264. 600.0,
  265. 300.0,
  266. 300.0,
  267. 300.0,
  268. 800.0,
  269. 400.0,
  270. 400.0,
  271. 1000.0,
  272. 800.0
  273. }
  274.  
  275. static const Float:pet_min_distance[PET_NUM] =
  276. {
  277. 80.0,
  278. 80.0,
  279. 80.0,
  280. 80.0,
  281. 80.0,
  282. 80.0,
  283. 80.0,
  284. 300.0,
  285. 200.0,
  286. 80.0,
  287. 80.0,
  288. 80.0,
  289. 250.0,
  290. 100.0,
  291. 100.0,
  292. 300.0,
  293. 200.0
  294. }
  295.  
  296. new pet[33]
  297. new pettype[33]
  298. new maxplayers
  299. new pets_off_pcvar
  300. new pets_adminonly_pcvar
  301.  
  302. //menu
  303. new currently_on[33]
  304.  
  305. public plugin_init()
  306. {
  307. register_plugin("GHW Pet Followers",VERSION,"GHW_Chronic")
  308.  
  309. register_concmd("amx_pets","cmd_pets",ADMIN_SLAY," Brings up the menu to turn pets on/admin only/off")
  310. register_menu("PetsMenu",(1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9),"menu_pressed")
  311.  
  312. register_clcmd("say","say_hook")
  313. register_clcmd("say_team","say_hook")
  314.  
  315. register_event("DeathMsg","DeathMsg","a")
  316. register_forward(FM_Think,"FM_Think_hook")
  317.  
  318. pets_off_pcvar = register_cvar("pets_off","0")
  319. pets_adminonly_pcvar = register_cvar("pets_adminonly","0")
  320.  
  321. maxplayers = get_maxplayers()
  322.  
  323. register_dictionary("GHW_Pet_Followers.txt")
  324. }
  325.  
  326. public plugin_precache()
  327. {
  328. for(new i=0;i<PET_NUM;i++) precache_model(pet_models[i])
  329. }
  330.  
  331. public cmd_pets(id,level,cid)
  332. {
  333. if(!cmd_access(id,level,cid,1))
  334. {
  335. return PLUGIN_HANDLED
  336. }
  337.  
  338. currently_on[id] = 0
  339. create_menu(id)
  340.  
  341. return PLUGIN_HANDLED
  342. }
  343.  
  344. public create_menu(id)
  345. {
  346. new Menu[1024]
  347. format(Menu,1023,"GHW Pet Mod^n^n")
  348.  
  349. new keys
  350.  
  351. new current_setting[32]
  352. for(new i=currently_on[id];i<PET_NUM && i<currently_on[id] + 7;i++)
  353. {
  354. if(get_pcvar_num(pets_off_pcvar) & power(2,i))
  355. {
  356. format(current_setting,31,"Off")
  357. }
  358. else if(get_pcvar_num(pets_adminonly_pcvar) & power(2,i))
  359. {
  360. format(current_setting,31,"Admin")
  361. }
  362. else
  363. {
  364. format(current_setting,31,"On")
  365. }
  366. format(Menu,1023,"%s%d. %s \R%s^n",Menu,i - currently_on[id] + 1,pet_name[i],current_setting)
  367.  
  368. keys |= (1<<i - currently_on[id])
  369. }
  370.  
  371. if(currently_on[id] > 0)
  372. {
  373. format(Menu,1023,"%s^n8. Back",Menu)
  374. keys |= (1<<7)
  375. }
  376. if(currently_on[id] + 7 < PET_NUM)
  377. {
  378. format(Menu,1023,"%s^n9. Next",Menu)
  379. keys |= (1<<8)
  380. }
  381.  
  382. format(Menu,1023,"%s^n^n0. Exit",Menu)
  383. keys |= (1<<9)
  384.  
  385. show_menu(id,keys,Menu,-1,"PetsMenu")
  386. }
  387.  
  388. public menu_pressed(id,key)
  389. {
  390. switch(key)
  391. {
  392. case 7:
  393. {
  394. //Back
  395. currently_on[id] -= 7
  396. }
  397. case 8:
  398. {
  399. //Next
  400. currently_on[id] += 7
  401. }
  402. case 9:
  403. {
  404. //Nothing - Exit
  405. return PLUGIN_HANDLED
  406. }
  407. default:
  408. {
  409. //Selected a Pet
  410. if(get_pcvar_num(pets_off_pcvar) & power(2,key + currently_on[id]))
  411. {
  412. set_pcvar_num(pets_off_pcvar,get_pcvar_num(pets_off_pcvar) - power(2,key + currently_on[id]))//Out of Off list
  413. }
  414. else if(get_pcvar_num(pets_adminonly_pcvar) & power(2,key + currently_on[id]))
  415. {
  416. set_pcvar_num(pets_adminonly_pcvar,get_pcvar_num(pets_adminonly_pcvar) - power(2,key + currently_on[id]))//Out of Admin list
  417. set_pcvar_num(pets_off_pcvar,get_pcvar_num(pets_off_pcvar) + power(2,key + currently_on[id]))//Into Off list
  418. }
  419. else
  420. {
  421. set_pcvar_num(pets_adminonly_pcvar,get_pcvar_num(pets_adminonly_pcvar) + power(2,key + currently_on[id]))//Into Admin list
  422. }
  423. }
  424. }
  425.  
  426. create_menu(id)
  427.  
  428. return PLUGIN_HANDLED
  429. }
  430.  
  431. public client_disconnect(id) handle_DeathMsg(id)
  432.  
  433. public DeathMsg() handle_DeathMsg(read_data(2))
  434.  
  435. public handle_DeathMsg(id)
  436. {
  437. if(pet[id] && pev_valid(pet[id]))
  438. {
  439. set_pev(pet[id],pev_animtime,100.0)
  440. set_pev(pet[id],pev_framerate,1.0)
  441. set_pev(pet[id],pev_sequence,pet_die[pettype[id]])
  442. set_pev(pet[id],pev_gaitsequence,pet_die[pettype[id]])
  443. set_task(pet_die_length[pettype[id]],"remove_pet",pet[id])
  444. }
  445. pet[id]=0
  446. }
  447.  
  448. public remove_pet(ent) if(pev_valid(ent)) engfunc(EngFunc_RemoveEntity,ent)
  449.  
  450. public say_hook(id)
  451. {
  452. new arg[32]
  453. read_argv(1,arg,31)
  454. if(equali(arg,"/pet Headcrab")) pet_cmd_handle(id,0)
  455. else if(equali(arg,"/pet Rat")) pet_cmd_handle(id,1)
  456. else if(equali(arg,"/pet Bat")) pet_cmd_handle(id,2)
  457. else if(equali(arg,"/pet Frog")) pet_cmd_handle(id,3)
  458. else if(equali(arg,"/pet Floater")) pet_cmd_handle(id,4)
  459. else if(equali(arg,"/pet Cockroach")) pet_cmd_handle(id,5)
  460. else if(equali(arg,"/pet Hyper") || equali(arg,"/pet Hyper Bat")) pet_cmd_handle(id,6)
  461. else if(equali(arg,"/pet Mom")) pet_cmd_handle(id,7)
  462. else if(equali(arg,"/pet Grunt")) pet_cmd_handle(id,8)
  463. else if(equali(arg,"/pet Fish")) pet_cmd_handle(id,9)
  464. else if(equali(arg,"/pet Baby Headcrab") || equali(arg,"/pet Baby")) pet_cmd_handle(id,10)
  465. else if(equali(arg,"/pet Roach") || equali(arg,"/pet Cockroach")) pet_cmd_handle(id,11)
  466. else if(equali(arg,"/pet Garg") || equali(arg,"/pet Gargantuan")) pet_cmd_handle(id,12)
  467. else if(equali(arg,"/pet Bull") || equali(arg,"/pet Bull Squid") || equali(arg,"/pet BullSquid") || equali(arg,"/pet Squid")) pet_cmd_handle(id,13)
  468. else if(equali(arg,"/pet Hound") || equali(arg,"/pet Hound Eye") || equali(arg,"/pet HoundEye") || equali(arg,"/pet Eye")) pet_cmd_handle(id,14)
  469. else if(equali(arg,"/pet Loader") || equali(arg,"/pet Loading") || equali(arg,"/pet Machine") || equali(arg,"/pet Loading Machine")) pet_cmd_handle(id,15)
  470. else if(equali(arg,"/pet Boss") || equali(arg,"/pet Controller")) pet_cmd_handle(id,16)
  471. else if(containi(arg,"/pet")==0) pet_cmd_handle(id,random_pet(id))
  472. else if(containi(arg,"/nopet")==0)
  473. {
  474. if(pet[id]) client_print(id,print_chat,"[AMXX] %L",id,"MSG_REMOVEPET")
  475. else client_print(id,print_chat,"[AMXX] %L",id,"MSG_NOREMOVEPET")
  476. handle_DeathMsg(id)
  477. }
  478. }
  479.  
  480. public random_pet(id)
  481. {
  482. new num = random_num(0,PET_NUM-1);
  483.  
  484. if((get_pcvar_num(pets_off_pcvar) & power(2,num)) || ((get_pcvar_num(pets_adminonly_pcvar) & power(2,num)) && !is_user_admin(id)))
  485. num = random_pet(id)
  486.  
  487. return num;
  488. }
  489.  
  490. public pet_cmd_handle(id,num)
  491. {
  492. if(pet[id])
  493. {
  494. handle_DeathMsg(id)
  495. //client_print(id,print_chat,"[AMXX] %L",id,"MSG_NOGIVEPET_HAVE")
  496. }
  497. else if(!is_user_alive(id))
  498. {
  499. client_print(id,print_chat,"[AMXX] %L",id,"MSG_NOGIVEPET_DEAD")
  500. }
  501. else
  502. {
  503. if(get_pcvar_num(pets_off_pcvar) & power(2,num))
  504. {
  505. client_print(id,print_chat,"[AMXX] %L",id,"MSG_DISABLED")
  506. }
  507. else if((get_pcvar_num(pets_adminonly_pcvar) & power(2,num)) && !is_user_admin(id))
  508. {
  509. client_print(id,print_chat,"[AMXX] %L",id,"MSG_ADMINONLY")
  510. }
  511. else
  512. {
  513. pet[id] = engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"info_target"))
  514. set_pev(pet[id],pev_classname,"GHW_Pet")
  515. pettype[id] = num
  516. engfunc(EngFunc_SetModel,pet[id],pet_models[pettype[id]])
  517. new Float:origin[3]
  518. pev(id,pev_origin,origin)
  519. if(is_user_crouching(id)) origin[2] -= pet_minus_z_crouching[pettype[id]]
  520. else origin[2] -= pet_minus_z_standing[pettype[id]]
  521. set_pev(pet[id],pev_origin,origin)
  522. set_pev(pet[id],pev_solid,SOLID_NOT)
  523. set_pev(pet[id],pev_movetype,MOVETYPE_FLY)
  524. set_pev(pet[id],pev_owner,33)
  525. set_pev(pet[id],pev_nextthink,1.0)
  526. set_pev(pet[id],pev_sequence,0)
  527. set_pev(pet[id],pev_gaitsequence,0)
  528. set_pev(pet[id],pev_framerate,1.0)
  529. client_print(id,print_chat,"[AMXX] %L",id,"MSG_GIVEPET",pet_name[pettype[id]])
  530. }
  531. }
  532. }
  533.  
  534. public FM_Think_hook(ent)
  535. {
  536. for(new i=0;i<=maxplayers;i++)
  537. {
  538. if(ent==pet[i])
  539. {
  540. static Float:origin[3]
  541. static Float:origin2[3]
  542. static Float:velocity[3]
  543. pev(ent,pev_origin,origin2)
  544. get_offset_origin_body(i,Float:{50.0,0.0,0.0},origin)
  545. if(is_user_crouching(i)) origin[2] -= pet_minus_z_crouching[pettype[i]]
  546. else origin[2] -= pet_minus_z_standing[pettype[i]]
  547.  
  548. if(get_distance_f(origin,origin2)>pet_max_distance[pettype[i]])
  549. {
  550. set_pev(ent,pev_origin,origin)
  551. }
  552. else if(get_distance_f(origin,origin2)>pet_min_distance[pettype[i]])
  553. {
  554. get_speed_vector(origin2,origin,250.0,velocity)
  555. set_pev(ent,pev_velocity,velocity)
  556. if(pev(ent,pev_sequence)!=pet_run[pettype[i]] || pev(ent,pev_framerate)!=pet_run_speed[pettype[i]])
  557. {
  558. set_pev(ent,pev_frame,1)
  559. set_pev(ent,pev_sequence,pet_run[pettype[i]])
  560. set_pev(ent,pev_gaitsequence,pet_run[pettype[i]])
  561. set_pev(ent,pev_framerate,pet_run_speed[pettype[i]])
  562. }
  563. }
  564. else if(get_distance_f(origin,origin2)<pet_min_distance[pettype[i]] - 5.0)
  565. {
  566. if(pev(ent,pev_sequence)!=pet_idle[pettype[i]] || pev(ent,pev_framerate)!=pet_idle_speed[pettype[i]])
  567. {
  568. set_pev(ent,pev_frame,1)
  569. set_pev(ent,pev_sequence,pet_idle[pettype[i]])
  570. set_pev(ent,pev_gaitsequence,pet_idle[pettype[i]])
  571. set_pev(ent,pev_framerate,pet_idle_speed[pettype[i]])
  572. }
  573. set_pev(ent,pev_velocity,Float:{0.0,0.0,0.0})
  574. }
  575. pev(i,pev_origin,origin)
  576. origin[2] = origin2[2]
  577. entity_set_aim(ent,origin)
  578.  
  579. set_pev(ent,pev_nextthink,1.0)
  580. break;
  581. }
  582. }
  583. }
  584.