Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.67 KB | None | 0 0
  1. /*******************************************************************************
  2.  
  3. Parachute
  4.  
  5. Version: 1.3
  6. Author: KRoTaL/JTP10181
  7.  
  8. 0.1 Release
  9. 0.1.1 Players can't buy a parachute if they already own one
  10. 0.1.2 Release for AMX MOD X
  11. 0.1.3 Minor changes
  12. 0.1.4 Players lose their parachute if they die
  13. 0.1.5 Added amx_parachute cvar
  14. 0.1.6 Changed set_origin to movetype_follow (you won't see your own parachute)
  15. 0.1.7 Added amx_parachute <name> | admins with admin level a get a free parachute
  16. 0.1.8 JTP - Cleaned up code, fixed runtime error
  17. 1.0 JTP - Should be final version, made it work on basically any mod
  18. 1.1 JTP - Added Changes from AMX Version 0.1.8
  19. Added say give_parachute and parachute_fallspeed cvar
  20. Plays the release animation when you touch the ground
  21. Added chat responder for automatic help
  22. 1.2 JTP - Added cvar to disable the detach animation
  23. Redid animation code to improve organization
  24. Force "walk" animation on players when falling
  25. Change users gravity when falling to avoid choppiness
  26. 1.3 JTP - Upgraded to pCVARs
  27.  
  28. Commands:
  29.  
  30. say buy_parachute - buys a parachute (CStrike ONLY)
  31. saw sell_parachute - sells your parachute (75% of the purchase price)
  32. say give_parachute <nick, #userid or @team> - gives your parachute to the player
  33.  
  34. amx_parachute <nick, #userid or @team> - gives a player a free parachute (CStrike ONLY)
  35. amx_parachute @all - gives everyone a free parachute (CStrike ONLY)
  36.  
  37. Press +use to slow down your fall.
  38.  
  39. Cvars:
  40.  
  41. sv_parachute "1" - 0: disables the plugin - 1: enables the plugin
  42.  
  43. parachute_cost "1000" - cost of the parachute (CStrike ONLY)
  44.  
  45. parachute_payback "75" - how many percent of the parachute cost you get when you sell your parachute
  46. (ie. (75/100) * 1000 = 750$)
  47.  
  48. parachute_fallspeed "100" - speed of the fall when you use the parachute
  49.  
  50.  
  51. Setup (AMXX 1.x):
  52.  
  53. Install the amxx file.
  54. Enable engine and cstrike (for cs only) in the amxx modules.ini
  55. Put the parachute.mdl file in the modname/models/ folder
  56.  
  57. *******************************************************************************/
  58.  
  59. #include <amxmodx>
  60. #include <amxmisc>
  61. #include <engine>
  62. #include <cstrike>
  63. #include <fun>
  64.  
  65. new bool:has_parachute[33]
  66. new para_ent[33]
  67. new gCStrike = 0
  68. new pDetach, pFallSpeed, pEnabled, pCost, pPayback
  69.  
  70. #define PARACHUTE_LEVEL ADMIN_LEVEL_A
  71.  
  72. public plugin_init()
  73. {
  74. register_plugin("Parachute", "1.3", "KRoT@L/JTP10181")
  75. pEnabled = register_cvar("sv_parachute", "1" )
  76. pFallSpeed = register_cvar("parachute_fallspeed", "100")
  77. pDetach = register_cvar("parachute_detach", "1")
  78.  
  79. if (cstrike_running()) gCStrike = true
  80.  
  81. if (gCStrike) {
  82.  
  83. pCost = register_cvar("parachute_cost", "0")
  84. pPayback = register_cvar("parachute_payback", "75")
  85.  
  86. register_concmd("amx_parachute", "admin_give_parachute", PARACHUTE_LEVEL, "<nick, #userid or @team>" )
  87. }
  88.  
  89. register_clcmd("say", "HandleSay")
  90. register_clcmd("say_team", "HandleSay")
  91.  
  92. register_event("ResetHUD", "newSpawn", "be")
  93. register_event("DeathMsg", "death_event", "a")
  94.  
  95. //Setup jtp10181 CVAR
  96. new cvarString[256], shortName[16]
  97. copy(shortName,15,"chute")
  98.  
  99. register_cvar("jtp10181","",FCVAR_SERVER|FCVAR_SPONLY)
  100. get_cvar_string("jtp10181",cvarString,255)
  101.  
  102. if (strlen(cvarString) == 0) {
  103. formatex(cvarString,255,shortName)
  104. set_cvar_string("jtp10181",cvarString)
  105. }
  106. else if (contain(cvarString,shortName) == -1) {
  107. format(cvarString,255,"%s,%s",cvarString, shortName)
  108. set_cvar_string("jtp10181",cvarString)
  109. }
  110. }
  111.  
  112. public plugin_natives()
  113. {
  114. set_module_filter("module_filter")
  115. set_native_filter("native_filter")
  116. }
  117.  
  118. public module_filter(const module[])
  119. {
  120. if (!cstrike_running() && equali(module, "cstrike")) {
  121. return PLUGIN_HANDLED
  122. }
  123.  
  124. return PLUGIN_CONTINUE
  125. }
  126.  
  127. public native_filter(const name[], index, trap)
  128. {
  129. if (!trap) return PLUGIN_HANDLED
  130.  
  131. return PLUGIN_CONTINUE
  132. }
  133.  
  134. public client_connect(id)
  135. {
  136. parachute_reset(id)
  137. }
  138.  
  139. public client_disconnect(id)
  140. {
  141. parachute_reset(id)
  142. }
  143.  
  144. public death_event()
  145. {
  146. new id = read_data(2)
  147. parachute_reset(id)
  148. }
  149.  
  150. parachute_reset(id)
  151. {
  152. if(para_ent[id] > 0) {
  153. if (is_valid_ent(para_ent[id])) {
  154. remove_entity(para_ent[id])
  155. }
  156. }
  157.  
  158. if (is_user_alive(id)) set_user_gravity(id, 1.0)
  159.  
  160. has_parachute[id] = false
  161. para_ent[id] = 0
  162. }
  163.  
  164. public newSpawn(id)
  165. {
  166. if(para_ent[id] > 0) {
  167. remove_entity(para_ent[id])
  168. set_user_gravity(id, 1.0)
  169. para_ent[id] = 0
  170. }
  171.  
  172. if (!gCStrike || access(id,PARACHUTE_LEVEL) || get_pcvar_num(pCost) <= 0) {
  173. has_parachute[id] = true
  174. //set_view(id, CAMERA_3RDPERSON)
  175. }
  176. set_task(0.7, "setari")
  177. }
  178.  
  179. public HandleSay(id)
  180. {
  181. if(!is_user_connected(id)) return PLUGIN_CONTINUE
  182.  
  183. new args[128]
  184. read_args(args, 127)
  185. remove_quotes(args)
  186.  
  187. if (gCStrike) {
  188. if (equali(args, "buy_parachute")) {
  189. buy_parachute(id)
  190. return PLUGIN_HANDLED
  191. }
  192. else if (equali(args, "sell_parachute")) {
  193. sell_parachute(id)
  194. return PLUGIN_HANDLED
  195. }
  196. else if (containi(args, "give_parachute") == 0) {
  197. give_parachute(id,args[15])
  198. return PLUGIN_HANDLED
  199. }
  200. }
  201.  
  202. if (containi(args, "parachute") != -1) {
  203. if (gCStrike) client_print(id, print_chat, "[AMXX] команды Парашюта: buy_parachute, sell_parachute, give_parachute")
  204. client_print(id, print_chat, "[AMXX], Чтобы использовать твой парашют нажимают и держат твою +use кнопку, падая")
  205. }
  206.  
  207. return PLUGIN_CONTINUE
  208. }
  209.  
  210. public buy_parachute(id)
  211. {
  212. if (!gCStrike) return PLUGIN_CONTINUE
  213. if (!is_user_connected(id)) return PLUGIN_CONTINUE
  214.  
  215. if (!get_pcvar_num(pEnabled)) {
  216. client_print(id, print_chat, "[AMXX] Плагин парашута отключен ")
  217. return PLUGIN_HANDLED
  218. }
  219.  
  220. if (has_parachute[id]) {
  221. client_print(id, print_chat, "[AMXX] У тебя уже есть парашют")
  222. return PLUGIN_HANDLED
  223. }
  224.  
  225. new money = cs_get_user_money(id)
  226. new cost = get_pcvar_num(pCost)
  227.  
  228. if (money < cost) {
  229. client_print(id, print_chat, "[AMXX] У тебя нет денег для парашюта - $ Затрат %i", cost)
  230. return PLUGIN_HANDLED
  231. }
  232.  
  233. cs_set_user_money(id, money - cost)
  234. client_print(id, print_chat, "[AMXX] Ты купил парашют. Чтобы использовать это, нажми +use.")
  235. has_parachute[id] = true
  236.  
  237. return PLUGIN_HANDLED
  238. }
  239.  
  240. public sell_parachute(id)
  241. {
  242. if (!gCStrike) return PLUGIN_CONTINUE
  243. if (!is_user_connected(id)) return PLUGIN_CONTINUE
  244.  
  245. if (!get_pcvar_num(pEnabled)) {
  246. client_print(id, print_chat, "[AMXX] Парашут выключен")
  247. return PLUGIN_HANDLED
  248. }
  249.  
  250. if (!has_parachute[id]) {
  251. client_print(id, print_chat, "[AMXX] У тебя нет парашюта, чтобы продать")
  252. return PLUGIN_HANDLED
  253. }
  254.  
  255. if (access(id,PARACHUTE_LEVEL)) {
  256. client_print(id, print_chat, "[AMXX] Ты не можешь продать свой свободный парашют admin")
  257. return PLUGIN_HANDLED
  258. }
  259.  
  260. parachute_reset(id)
  261.  
  262. new money = cs_get_user_money(id)
  263. new cost = get_pcvar_num(pCost)
  264.  
  265. new sellamt = floatround(cost * (get_pcvar_num(pPayback) / 100.0))
  266. cs_set_user_money(id, money + sellamt)
  267.  
  268. client_print(id, print_chat, "[AMX] Ты продал свой используемый парашют за $ %d", sellamt)
  269.  
  270. return PLUGIN_CONTINUE
  271. }
  272.  
  273. public give_parachute(id,args[])
  274. {
  275. if (!gCStrike) return PLUGIN_CONTINUE
  276. if (!is_user_connected(id)) return PLUGIN_CONTINUE
  277.  
  278. if (!get_pcvar_num(pEnabled)) {
  279. client_print(id, print_chat, "[AMXX] Плагин парошют выключен")
  280. return PLUGIN_HANDLED
  281. }
  282.  
  283. if (!has_parachute[id]) {
  284. client_print(id, print_chat, "[AMXX] У тебя нет парашюта, чтобы дать")
  285. return PLUGIN_HANDLED
  286. }
  287.  
  288. new player = cmd_target(id, args, 4)
  289. if (!player) return PLUGIN_HANDLED
  290.  
  291. new id_name[32], pl_name[32]
  292. get_user_name(id, id_name, 31)
  293. get_user_name(player, pl_name, 31)
  294.  
  295. if(has_parachute[player]) {
  296. client_print(id, print_chat, "[AMXX] У %s уже есть парашют.", pl_name)
  297. return PLUGIN_HANDLED
  298. }
  299.  
  300. parachute_reset(id)
  301. has_parachute[player] = true
  302.  
  303. client_print(id, print_chat, "[AMXX] Ты дал свой парашют %s.", pl_name)
  304. client_print(player, print_chat, "[AMXX] %s дал парашют тебе.", id_name)
  305.  
  306. return PLUGIN_HANDLED
  307. }
  308.  
  309. public admin_give_parachute(id, level, cid) {
  310.  
  311. if (!gCStrike) return PLUGIN_CONTINUE
  312.  
  313. if(!cmd_access(id,level,cid,2)) return PLUGIN_HANDLED
  314.  
  315. if (!get_pcvar_num(pEnabled)) {
  316. client_print(id, print_chat, "[AMXX] Плагин выключен")
  317. return PLUGIN_HANDLED
  318. }
  319.  
  320. new arg[32], name[32], name2[32], authid[35], authid2[35]
  321. read_argv(1,arg,31)
  322. get_user_name(id,name,31)
  323. get_user_authid(id,authid,34)
  324.  
  325. if (arg[0]=='@'){
  326. new players[32], inum
  327. if (equali("T",arg[1])) copy(arg[1],31,"TERRORIST")
  328. if (equali("ALL",arg[1])) get_players(players,inum)
  329. else get_players(players,inum,"e",arg[1])
  330.  
  331. if (inum == 0) {
  332. console_print(id,"No clients in such team")
  333. return PLUGIN_HANDLED
  334. }
  335.  
  336. for(new a = 0; a < inum; a++) {
  337. has_parachute[players[a]] = true
  338. }
  339.  
  340. switch(get_cvar_num("amx_show_activity")) {
  341. case 2: client_print(0,print_chat,"")
  342. case 1: client_print(0,print_chat,"")
  343. }
  344. }
  345. else {
  346.  
  347. new player = cmd_target(id,arg,6)
  348. if (!player) return PLUGIN_HANDLED
  349.  
  350. has_parachute[player] = true
  351.  
  352. get_user_name(player,name2,31)
  353. get_user_authid(player,authid2,34)
  354.  
  355. switch(get_cvar_num("amx_show_activity")) {
  356. case 2: client_print(0,print_chat,"^"%s^" acum ai parasuta",name2)
  357. case 1: client_print(0,print_chat,"^"%s^" acum ai parasuta",name2)
  358. }
  359. }
  360. return PLUGIN_HANDLED
  361. }
  362.  
  363. public client_PreThink(id)
  364. {
  365. //parachute.mdl animation information
  366. //0 - deploy - 84 frames
  367. //1 - idle - 39 frames
  368. //2 - detach - 29 frames
  369.  
  370. if (!get_pcvar_num(pEnabled)) return
  371. if (!is_user_alive(id) || !has_parachute[id]) return
  372.  
  373. new Float:fallspeed = get_pcvar_float(pFallSpeed) * -1.0
  374. new Float:frame
  375.  
  376. new button = get_user_button(id)
  377. new oldbutton = get_user_oldbutton(id)
  378. new flags = get_entity_flags(id)
  379.  
  380. if (para_ent[id] > 0 && (flags & FL_ONGROUND)) {
  381.  
  382. if (get_pcvar_num(pDetach)) {
  383.  
  384. if (get_user_gravity(id) == 0.1) set_user_gravity(id, 1.0)
  385.  
  386. if (entity_get_int(para_ent[id],EV_INT_sequence) != 2) {
  387. entity_set_int(para_ent[id], EV_INT_sequence, 2)
  388. entity_set_int(para_ent[id], EV_INT_gaitsequence, 1)
  389. entity_set_float(para_ent[id], EV_FL_frame, 0.0)
  390. entity_set_float(para_ent[id], EV_FL_fuser1, 0.0)
  391. entity_set_float(para_ent[id], EV_FL_animtime, 0.0)
  392. entity_set_float(para_ent[id], EV_FL_framerate, 0.0)
  393. return
  394. }
  395.  
  396. frame = entity_get_float(para_ent[id],EV_FL_fuser1) + 2.0
  397. entity_set_float(para_ent[id],EV_FL_fuser1,frame)
  398. entity_set_float(para_ent[id],EV_FL_frame,frame)
  399.  
  400. if (frame > 254.0) {
  401. remove_entity(para_ent[id])
  402. para_ent[id] = 0
  403. }
  404. }
  405. else {
  406. remove_entity(para_ent[id])
  407. set_user_gravity(id, 1.0)
  408. para_ent[id] = 0
  409. }
  410.  
  411. return
  412. }
  413.  
  414. if (button & IN_USE) {
  415.  
  416. new Float:velocity[3]
  417. entity_get_vector(id, EV_VEC_velocity, velocity)
  418.  
  419. if (velocity[2] < 0.0) {
  420.  
  421. if(para_ent[id] <= 0) {
  422. para_ent[id] = create_entity("info_target")
  423. if(para_ent[id] > 0) {
  424. entity_set_string(para_ent[id],EV_SZ_classname,"parachute")
  425. entity_set_edict(para_ent[id], EV_ENT_aiment, id)
  426. entity_set_edict(para_ent[id], EV_ENT_owner, id)
  427. entity_set_int(para_ent[id], EV_INT_movetype, MOVETYPE_FOLLOW)
  428. entity_set_int(para_ent[id], EV_INT_sequence, 0)
  429. entity_set_int(para_ent[id], EV_INT_gaitsequence, 1)
  430. entity_set_float(para_ent[id], EV_FL_frame, 0.0)
  431. entity_set_float(para_ent[id], EV_FL_fuser1, 0.0)
  432. }
  433. }
  434.  
  435. if (para_ent[id] > 0) {
  436.  
  437. entity_set_int(id, EV_INT_sequence, 3)
  438. entity_set_int(id, EV_INT_gaitsequence, 1)
  439. entity_set_float(id, EV_FL_frame, 1.0)
  440. entity_set_float(id, EV_FL_framerate, 1.0)
  441. set_user_gravity(id, 0.1)
  442.  
  443. velocity[2] = (velocity[2] + 40.0 < fallspeed) ? velocity[2] + 40.0 : fallspeed
  444. entity_set_vector(id, EV_VEC_velocity, velocity)
  445.  
  446. if (entity_get_int(para_ent[id],EV_INT_sequence) == 0) {
  447.  
  448. frame = entity_get_float(para_ent[id],EV_FL_fuser1) + 1.0
  449. entity_set_float(para_ent[id],EV_FL_fuser1,frame)
  450. entity_set_float(para_ent[id],EV_FL_frame,frame)
  451.  
  452. if (frame > 100.0) {
  453. entity_set_float(para_ent[id], EV_FL_animtime, 0.0)
  454. entity_set_float(para_ent[id], EV_FL_framerate, 0.4)
  455. entity_set_int(para_ent[id], EV_INT_sequence, 1)
  456. entity_set_int(para_ent[id], EV_INT_gaitsequence, 1)
  457. entity_set_float(para_ent[id], EV_FL_frame, 0.0)
  458. entity_set_float(para_ent[id], EV_FL_fuser1, 0.0)
  459. }
  460. }
  461. }
  462. }
  463. else if (para_ent[id] > 0) {
  464. remove_entity(para_ent[id])
  465. set_user_gravity(id, 1.0)
  466. para_ent[id] = 0
  467. }
  468. }
  469. else if ((oldbutton & IN_USE) && para_ent[id] > 0 ) {
  470. remove_entity(para_ent[id])
  471. set_user_gravity(id, 1.0)
  472. para_ent[id] = 0
  473. }
  474. }
  475.  
  476. public setari(id)
  477. {
  478. server_cmd("amx_parachute @all");
  479. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement