Advertisement
Arxero

plugin_trail

May 15th, 2018
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.54 KB | None | 0 0
  1. /*****************************************************************************************
  2. *
  3. * plugin_trail.sma
  4. *
  5. * By Bahrmanou (amiga5707@hotmail.com)
  6. *
  7. *****************************************************************************************/
  8. /*****************************************************************************************
  9. If some map cause problem (crash the server) because of too much precaches, create a file
  10. in your AmxModx configs folder named 'sensiblemaps.cfg' and add the map name (WITHOUT the
  11. extension '.bsp') in that file.
  12. So if the map is in the list, the plugin prevents trail sprites to be precached (i.e. the
  13. trails are DISABLED for this map.
  14. *****************************************************************************************/
  15. #include <amxmodx>
  16. #include <amxmisc>
  17. #include <engine>
  18.  
  19. #define PLUGNAME "plugin_trail"
  20. #define VERSION "1.3.1"
  21. #define AUTHOR "Bahrmanou"
  22.  
  23. #define ACCESS_LEVEL ADMIN_RESERVATION
  24. #define ACCESS_ADMIN ADMIN_ADMIN
  25.  
  26. #define MAX_TEXT_LENGTH 200
  27. #define MAX_NAME_LENGTH 40
  28. #define MAX_PLAYERS 32
  29. #define MAX_DISTANCE 300
  30.  
  31. #define CFG_FILE "colors.cfg"
  32. #define MAX_COLORS 200
  33.  
  34. #define DEF_TRAIL_LIFE 2
  35.  
  36. #define TASKID 1337 // change if it interfere with another plugin!
  37. #define TICK 0.1
  38.  
  39. #define NUM_SPRITES 29
  40.  
  41. new bool:gl_parsed
  42. new bool:gl_trail
  43. new bool:gl_not_this_map
  44.  
  45. new gl_trail_life
  46. new gl_trail_size[MAX_PLAYERS]
  47. new gl_trail_brightness[MAX_PLAYERS]
  48. new gl_trail_type[MAX_PLAYERS]
  49.  
  50. new gl_sprite_name[NUM_SPRITES][] = {
  51. "sprites/laserbeam.spr",
  52. "sprites/blueflare1.spr",
  53. "sprites/dot.spr",
  54. "sprites/flare5.spr",
  55. "sprites/flare6.spr",
  56. "sprites/plasma.spr",
  57. "sprites/smoke.spr",
  58. "sprites/xbeam5.spr",
  59. "sprites/xenobeam.spr",
  60. "sprites/xssmke1.spr",
  61. "sprites/zbeam3.spr",
  62. "sprites/zbeam2.spr",
  63. "sprites/trails/minecraft.spr",
  64. "sprites/trails/def_T.spr",
  65. "sprites/trails/love.spr",
  66. "sprites/trails/hp.spr",
  67. "sprites/trails/Biohazard.spr",
  68. "sprites/trails/CT.spr",
  69. "sprites/trails/lightning.spr",
  70. "sprites/trails/letters.spr",
  71. "sprites/trails/ice.spr",
  72. "sprites/trails/box.spr",
  73. "sprites/trails/zik.spr",
  74. "sprites/trails/vselennaya.spr",
  75. "sprites/trails/tok.spr",
  76. "sprites/trails/zet.spr",
  77. "sprites/trails/snow_white.spr",
  78. "sprites/trails/Shar.spr",
  79. "sprites/trails/present.spr"
  80. }
  81. new gl_sprite[NUM_SPRITES]
  82. new gl_def_sprite_size[NUM_SPRITES] = {
  83. 5, 12, 4, 16, 16, 6, 9, 4, 15, 14, 15, 20, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12
  84. }
  85. new gl_def_sprite_brightness[NUM_SPRITES] = {
  86. 160, 255, 200, 255, 255, 230, 150, 150, 240, 220, 200, 200, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160, 160
  87. }
  88.  
  89. new gl_players[MAX_PLAYERS]
  90.  
  91. new gl_player_position[MAX_PLAYERS][3]
  92. new gl_timer_count[MAX_PLAYERS]
  93. new gl_timer_limit
  94.  
  95. new gl_player_colors[MAX_PLAYERS][3]
  96. new gl_color_names[MAX_COLORS][MAX_NAME_LENGTH]
  97. new gl_colors[MAX_COLORS][3]
  98. new gl_num_colors
  99.  
  100. public plugin_init() {
  101. register_plugin(PLUGNAME, VERSION, AUTHOR)
  102. register_concmd("amx_trail","cmdTrail", ACCESS_LEVEL, "- ['on'|'off'|'1'|'0'] : enable/disable trails.")
  103. register_concmd("amx_trail_user","cmdUserTrail", ACCESS_LEVEL, "- <name or #userid> <colorname | 'random' | 'off'> : set user trail.")
  104. register_concmd("amx_trail_type", "cmdTrailType", ACCESS_LEVEL, "- <type> : set trail type for all players.")
  105. register_concmd("amx_trail_life","cmdTrailLife", ACCESS_LEVEL, "- [duration] : get/set trail duration, in seconds.")
  106. register_concmd("amx_trail_size","cmdTrailSize", ACCESS_LEVEL, "- [size] : get/set trail size.")
  107. register_concmd("amx_trail_brightness","cmdTrailBrightness", ACCESS_LEVEL, "- [brightness] : get/set trail brightness.")
  108. register_concmd("amx_trail_reload", "cmdReload", ACCESS_LEVEL, ": reload colors configuration file.")
  109. register_clcmd("say", "SayCmd", 0, "")
  110.  
  111. gl_parsed = gl_trail = parse_file()
  112. if (!gl_sprite[0]) gl_trail = false
  113.  
  114. gl_trail_life = DEF_TRAIL_LIFE
  115. gl_timer_limit = floatround(float(gl_trail_life)/TICK)
  116. }
  117.  
  118. public plugin_modules() {
  119. require_module("engine")
  120. }
  121.  
  122. public plugin_precache() {
  123. if (check_map()) {
  124. gl_not_this_map = true
  125. return
  126. }
  127.  
  128. for (new i=0; i<NUM_SPRITES; i++) {
  129. gl_sprite[i] = precache_model(gl_sprite_name[i])
  130. }
  131. }
  132.  
  133. public client_putinserver(id) {
  134. gl_trail_type[id] = gl_sprite[0]
  135. gl_trail_size[id] = gl_def_sprite_size[0]
  136. gl_trail_brightness[id] = gl_def_sprite_brightness[0]
  137. }
  138.  
  139. public client_disconnect(id) {
  140. if (task_exists(TASKID+id)) remove_task(TASKID+id)
  141. gl_player_colors[id][0] = gl_player_colors[id][1] = gl_player_colors[id][2] = 0
  142. }
  143.  
  144. /*****************************************************************************************
  145. *
  146. * cmdTrail ['on'|'off'|'1'|'0'] : enable/disable trails.
  147. *
  148. *****************************************************************************************/
  149. public cmdTrail(id, level, cid) {
  150. if (!cmd_access(id, level, cid, 1)) return PLUGIN_HANDLED
  151.  
  152. if (!gl_parsed) {
  153. console_print(id, "Trails are OFF because I couldn't read the config file '%s'!", CFG_FILE)
  154. return PLUGIN_HANDLED
  155. }
  156. if (gl_not_this_map) {
  157. console_print(id, "Trails are disabled for this map!")
  158. return PLUGIN_HANDLED
  159. }
  160.  
  161. new str[5]
  162. read_argv(1, str, 4)
  163. if (equali(str, "on") || equali(str, "1")) {
  164. if (gl_trail) {
  165. console_print(id, "Trails are already enabled.")
  166. } else {
  167. gl_trail = true
  168. console_print(id, "Trails are now ENABLED.")
  169. }
  170. } else if (equali(str, "off") || equali(str, "0")) {
  171. if (!gl_trail) {
  172. console_print(id, "Trails are already disabled.")
  173. }else {
  174. gl_trail = false
  175. new playercount
  176. get_players(gl_players, playercount)
  177. for (new i=0; i<playercount; i++) {
  178. kill_trail_task(gl_players[i])
  179. }
  180. say_to_all("Your trail has been removed.", id)
  181. console_print(id, "Trails are now DISABLED.")
  182. }
  183. } else {
  184. if (gl_trail) {
  185. console_print(id, "Trails are ENABLED.")
  186. } else {
  187. console_print(id, "Trails are DISABLED.")
  188. }
  189. }
  190.  
  191. return PLUGIN_HANDLED
  192. }
  193.  
  194. /*****************************************************************************************
  195. *
  196. * cmdUserTrail <name or #userid> <colorname | 'random' | 'off'> : set user trail.
  197. *
  198. *****************************************************************************************/
  199. public cmdUserTrail(id, level, cid) {
  200. if (!cmd_access(id, level, cid, 3)) return PLUGIN_HANDLED
  201.  
  202. if (!gl_parsed) {
  203. console_print(id, "Trails are OFF because I couldn't read the config file '%s'!", CFG_FILE)
  204. return PLUGIN_HANDLED
  205. }
  206. if (gl_not_this_map) {
  207. console_print(id, "Trails are disabled for this map!")
  208. return PLUGIN_HANDLED
  209. }
  210.  
  211. new user[MAX_NAME_LENGTH+1], colorname[MAX_NAME_LENGTH]
  212. new plName[MAX_NAME_LENGTH+1]
  213.  
  214. read_argv(1, user, MAX_NAME_LENGTH)
  215. read_argv(2, colorname, MAX_NAME_LENGTH-1)
  216.  
  217. new player = cmd_target(id, user, 6)
  218. if (!player) {
  219. console_print(id, "Unknown player: %s", user)
  220. return PLUGIN_HANDLED
  221. }
  222. get_user_name(player, plName, MAX_NAME_LENGTH)
  223. if (access(player, ADMIN_IMMUNITY) && id!=player) {
  224. console_print(id, "You cannot do that to %s, you silly bear!", plName)
  225. return PLUGIN_HANDLED
  226. }
  227. if (!is_user_alive(player)) {
  228. console_print(id, "Only alive players, please!")
  229. return PLUGIN_HANDLED
  230. }
  231.  
  232. if (equali(colorname, "off")) {
  233. if (!gl_player_colors[player][0] && !gl_player_colors[player][1] && !gl_player_colors[player][2]) {
  234. console_print(id, "The %s's trail is already off!", plName)
  235. return PLUGIN_HANDLED
  236. }
  237. kill_trail_task(player)
  238. console_print(id, "The %s's trail has been removed.", plName)
  239. client_print(player, print_chat, "Your trail has been removed.")
  240. } else if (equali(colorname, "random")) {
  241. do_trail(player, "", "")
  242. console_print(id, "%s has now a random color trail.", plName)
  243. } else {
  244. do_trail(player, colorname, "")
  245. console_print(id, "%s has now a %s trail.", plName, colorname)
  246. }
  247.  
  248. return PLUGIN_HANDLED
  249. }
  250.  
  251. /*****************************************************************************************
  252. *
  253. * cmdTrailType <type> : set trail type (sprite) for all players
  254. *
  255. *****************************************************************************************/
  256. public cmdTrailType(id, level, cid) {
  257. if (!cmd_access(id, level, cid, 2)) return PLUGIN_HANDLED
  258.  
  259. if (!gl_parsed) {
  260. console_print(id, "Trails are OFF becaus I couldn't read the config file '%s'!", CFG_FILE)
  261. return PLUGIN_HANDLED
  262. }
  263. if (gl_not_this_map) {
  264. console_print(id, "Trails are disabled for this map!")
  265. return PLUGIN_HANDLED
  266. }
  267.  
  268. new str[5], type
  269. read_argv(1, str, 4)
  270. type = str_to_num(str)
  271. if (type<1 || type>NUM_SPRITES) {
  272. console_print(id, "Type must be in [1,%d] range!", NUM_SPRITES)
  273. return PLUGIN_HANDLED
  274. }
  275. for (new i=0; i<MAX_PLAYERS; i++) {
  276. gl_trail_type[i] = gl_sprite[type-1]
  277. gl_trail_size[i] = gl_def_sprite_size[type-1]
  278. gl_trail_brightness[i] = gl_def_sprite_brightness[type-1]
  279. }
  280. restart_player_trail(id)
  281. return PLUGIN_HANDLED
  282. }
  283.  
  284. /*****************************************************************************************
  285. *
  286. * cmdTrailLife [duration] : get/set trail duration, in seconds.
  287. *
  288. *****************************************************************************************/
  289. public cmdTrailLife(id, level, cid) {
  290. if (!cmd_access(id, level, cid, 1)) return PLUGIN_HANDLED
  291.  
  292. if (!gl_parsed) {
  293. console_print(id, "Trails are OFF because I couldn't read the config file '%s'!", CFG_FILE)
  294. return PLUGIN_HANDLED
  295. }
  296. if (gl_not_this_map) {
  297. console_print(id, "Trails are disabled for this map!")
  298. return PLUGIN_HANDLED
  299. }
  300.  
  301. new Str[3], life
  302.  
  303. read_argv(1, Str, 2)
  304. if (!Str[0]) {
  305. console_print(id, "Trail life is currently %d seconds.", gl_trail_life)
  306. return PLUGIN_HANDLED
  307. }
  308. life = str_to_num(Str)
  309. if (life<1 || life>30) {
  310. console_print(id, "Trail life must be in [1,30] range!")
  311. return PLUGIN_HANDLED
  312. }
  313. gl_trail_life = life
  314. gl_timer_limit = floatround(float(life)/TICK)
  315. restart_players_trails()
  316.  
  317. return PLUGIN_HANDLED
  318. }
  319.  
  320. /*****************************************************************************************
  321. *
  322. * cmdTrailSize [size] : get/set trail size.
  323. *
  324. *****************************************************************************************/
  325. public cmdTrailSize(id, level, cid) {
  326. if (!cmd_access(id, level, cid, 1)) return PLUGIN_HANDLED
  327.  
  328. if (!gl_parsed) {
  329. console_print(id, "Trails are OFF because I couldn't read the config file '%s'!", CFG_FILE)
  330. return PLUGIN_HANDLED
  331. }
  332. if (gl_not_this_map) {
  333. console_print(id, "Trails are disabled for this map!")
  334. return PLUGIN_HANDLED
  335. }
  336.  
  337. new Str[3], size
  338.  
  339. read_argv(1, Str, 2)
  340. if (!Str[0]) {
  341. console_print(id, "Your trail size is currently %d.", gl_trail_size[id])
  342. return PLUGIN_HANDLED
  343. }
  344. size = str_to_num(Str)
  345. if (size<1) {
  346. console_print(id, "Trail size must be positive!")
  347. return PLUGIN_HANDLED
  348. }
  349. gl_trail_size[id] = size
  350. restart_player_trail(id)
  351.  
  352. return PLUGIN_HANDLED
  353. }
  354.  
  355. /*****************************************************************************************
  356. *
  357. * cmdTrailBrightness [brightness] : get/set trail brightness.
  358. *
  359. *****************************************************************************************/
  360. public cmdTrailBrightness(id, level, cid) {
  361. if (!cmd_access(id, level, cid, 1)) return PLUGIN_HANDLED
  362.  
  363. if (!gl_parsed) {
  364. console_print(id, "Trails are OFF because I couldn't read the config file '%s'!", CFG_FILE)
  365. return PLUGIN_HANDLED
  366. }
  367. if (gl_not_this_map) {
  368. console_print(id, "Trails are disabled for this map!")
  369. return PLUGIN_HANDLED
  370. }
  371.  
  372. new Str[3], bright
  373.  
  374. read_argv(1, Str, 3)
  375. if (!Str[0]) {
  376. console_print(id, "Your trail brightness is currently %d.", gl_trail_brightness[id])
  377. return PLUGIN_HANDLED
  378. }
  379. bright = str_to_num(Str)
  380. if (bright<1 || bright>255) {
  381. console_print(id, "Brightness must be in [1,255] range!")
  382. return PLUGIN_HANDLED
  383. }
  384. gl_trail_brightness[id] = bright
  385. restart_player_trail(id)
  386.  
  387. return PLUGIN_HANDLED
  388. }
  389.  
  390. /*****************************************************************************************
  391. *
  392. * cmdReload : reload configuration file.
  393. *
  394. *****************************************************************************************/
  395. public cmdReload(id, level, cid) {
  396. if (!cmd_access(id, level, cid, 1)) return PLUGIN_HANDLED
  397.  
  398. if (gl_not_this_map) {
  399. console_print(id, "Trails are disabled for this map!")
  400. return PLUGIN_HANDLED
  401. }
  402.  
  403. gl_parsed = parse_file()
  404.  
  405. if (gl_parsed) {
  406. console_print(id, "Ok, configuration file successfuly reloaded.")
  407. } else {
  408. console_print(id, "Uh Oh...There was a problem! Please check your amx log file to know whats causing this.")
  409. }
  410. return PLUGIN_HANDLED
  411. }
  412.  
  413. /*****************************************************************************************
  414. *
  415. * sayCmd : say trail <[['light'|'dark'] colorname] | ['random'] | ['off'] | ['help']>
  416. *
  417. *****************************************************************************************/
  418. public SayCmd(id, level, cid) {
  419. new args[128], msg[200], plName[MAX_NAME_LENGTH], colname[MAX_NAME_LENGTH], arg2[MAX_NAME_LENGTH], arg3[MAX_NAME_LENGTH], typenum
  420.  
  421. read_args(args, 128)
  422. remove_quotes(args)
  423.  
  424. if (equali(args, "trail", 5)) {
  425. if (!gl_trail) {
  426. client_print(id, print_chat, "Trails have been disabled.")
  427. return PLUGIN_HANDLED
  428. }
  429. if (gl_not_this_map) {
  430. client_print(id, print_chat, "Trails have been disabled for this map.")
  431. return PLUGIN_HANDLED
  432. }
  433.  
  434. get_user_name(id, plName, MAX_NAME_LENGTH)
  435. if (!get_user_team(id) && !access(id, ADMIN_ADMIN)) {
  436. client_print(id, print_chat, "You must be playing!")
  437. return PLUGIN_HANDLED
  438. }
  439.  
  440. if (!args[5]) {
  441. do_trail(id, "", "")
  442. return PLUGIN_HANDLED
  443. } else {
  444. parse(args[6], colname, MAX_NAME_LENGTH, arg2, MAX_NAME_LENGTH, arg3, MAX_NAME_LENGTH)
  445. // console_print(id, "restline = '%s'", restline)
  446. typenum = str_to_num(colname)
  447. }
  448.  
  449. if (equali(colname, "off")) {
  450. if (!gl_player_colors[id][0] && !gl_player_colors[id][1] && !gl_player_colors[id][2]) {
  451. client_print(id, print_chat, "Your trail is already off!")
  452. return PLUGIN_HANDLED
  453. }
  454. kill_trail_task(id)
  455. client_print(id, print_chat, "Your trail was removed.")
  456. format(msg, 199, "%s's trail was removed.", plName)
  457. say_to_all(msg, id)
  458. return PLUGIN_HANDLED
  459. } else if (equali(colname, "random")) {
  460. do_trail(id, "", "")
  461. return PLUGIN_HANDLED
  462. } else if (equali(colname, "help")) {
  463. trail_help(id)
  464. return PLUGIN_HANDLED
  465. }
  466.  
  467. if (typenum) {
  468. if (typenum<1 || typenum>NUM_SPRITES) {
  469. client_print(id, print_chat, "Type must be in the range [1,%d].", NUM_SPRITES)
  470. return PLUGIN_HANDLED
  471. }
  472. typenum--
  473. gl_trail_type[id] = gl_sprite[typenum]
  474. gl_trail_size[id] = gl_def_sprite_size[typenum]
  475. gl_trail_brightness[id] = gl_def_sprite_brightness[typenum]
  476. if (arg2[0]) {
  477. colname = arg2
  478. arg2 = arg3
  479. } else {
  480. if (!gl_player_colors[id][0] && !gl_player_colors[id][1] && !gl_player_colors[id][2]) {
  481. do_trail(id, "", "")
  482. return PLUGIN_HANDLED
  483. }
  484. new r = gl_player_colors[id][0]
  485. new g = gl_player_colors[id][1]
  486. new b = gl_player_colors[id][2]
  487. kill_trail_task(id)
  488. gl_player_colors[id][0] = r
  489. gl_player_colors[id][1] = g
  490. gl_player_colors[id][2] = b
  491. get_user_origin(id, gl_player_position[id])
  492. set_task(TICK, "check_position", TASKID+id, "", 0, "b")
  493. trail_msg(id)
  494. client_print(id, print_chat, "You have a trail of type %d.", typenum+1)
  495. format(msg, 199, "%s has a type %d trail.", plName, typenum+1)
  496. say_to_all(msg, id)
  497. return PLUGIN_HANDLED
  498. }
  499. }
  500.  
  501. if (equali(colname, "dark")) {
  502. copy(colname, MAX_NAME_LENGTH-1, arg2)
  503. if (!colname[0]) {
  504. client_print(id, print_chat, "Specify a color name!")
  505. return PLUGIN_HANDLED
  506. }
  507. do_trail(id, colname, "dark")
  508. } else if (equali(colname, "light")) {
  509. copy(colname, MAX_NAME_LENGTH-1, arg2)
  510. if (!colname[0]) {
  511. client_print(id, print_chat, "Specify a color name!")
  512. return PLUGIN_HANDLED
  513. }
  514. do_trail(id, colname, "light")
  515. }
  516. else {
  517. do_trail(id, colname, "")
  518. }
  519. }
  520. return PLUGIN_CONTINUE
  521. }
  522.  
  523. /*****************************************************************************************
  524. *****************************************************************************************/
  525. do_trail(id, colname[], intensity[]) {
  526. new i, msg[200]
  527. new name[33]
  528.  
  529. get_user_name(id, name, 32)
  530. if (!colname[0]) {
  531. kill_trail_task(id)
  532. gl_player_colors[id][0] = random(256)
  533. gl_player_colors[id][1] = random(256)
  534. gl_player_colors[id][2] = random(256)
  535. get_user_origin(id, gl_player_position[id])
  536. set_task(TICK, "check_position", TASKID+id, "", 0, "b")
  537. trail_msg(id)
  538. client_print(id, print_chat, "You have a random color trail.")
  539. format(msg, 199, "%s has a random color trail.", name)
  540. say_to_all(msg, id)
  541. return
  542. }
  543. for (i=0; i<gl_num_colors; i++) {
  544. if (equali(colname, gl_color_names[i])) {
  545. new Float:intens, r, g, b
  546. if (equali(intensity, "dark")) {
  547. intens = 0.5
  548. } else if (equali(intensity, "light")) {
  549. intens = 2.0
  550. } else {
  551. copy(intensity, 1, "")
  552. intens = 1.0
  553. }
  554. kill_trail_task(id)
  555. r = floatround(float(gl_colors[i][0]) * intens)
  556. g = floatround(float(gl_colors[i][1]) * intens)
  557. b = floatround(float(gl_colors[i][2]) * intens)
  558. gl_player_colors[id][0] = min(r, 255)
  559. gl_player_colors[id][1] = min(g, 255)
  560. gl_player_colors[id][2] = min(b, 255)
  561. get_user_origin(id, gl_player_position[id])
  562. set_task(TICK, "check_position", TASKID+id, "", 0, "b")
  563. trail_msg(id)
  564. if (intensity[0]) {
  565. client_print(id, print_chat, "You have a %s %s trail.", intensity, colname)
  566. format(msg, 199, "%s has now a %s %s trail.", name, intensity, colname)
  567. } else {
  568. client_print(id, print_chat, "You have a %s trail.", colname)
  569. format(msg, 199, "%s has now a %s trail.", name, colname)
  570. }
  571. say_to_all(msg, id)
  572. return
  573. }
  574. }
  575. client_print(id, print_chat, "Sorry, %s, but I dont recognize the color '%s'!", name, colname)
  576. return
  577. }
  578.  
  579. /*****************************************************************************************
  580. *****************************************************************************************/
  581. public check_position(taskid) {
  582. new origin[3], id = taskid-TASKID
  583.  
  584. if (!get_user_team(id)) {
  585. kill_trail_msg(id)
  586. return
  587. }
  588.  
  589. get_user_origin(id, origin)
  590. if (origin[0]!=gl_player_position[id][0] || origin[1]!=gl_player_position[id][1] || origin[2]!=gl_player_position[id][2]) {
  591. if (get_distance(origin, gl_player_position[id])>MAX_DISTANCE || gl_timer_count[id] >= gl_timer_limit/2) {
  592. kill_trail_msg(id)
  593. trail_msg(id)
  594. }
  595. gl_player_position[id][0] = origin[0]
  596. gl_player_position[id][1] = origin[1]
  597. gl_player_position[id][2] = origin[2]
  598. gl_timer_count[id] = 0
  599. } else {
  600. if (gl_timer_count[id] < gl_timer_limit) gl_timer_count[id]++
  601. }
  602. }
  603.  
  604. /*****************************************************************************************
  605. *****************************************************************************************/
  606. kill_trail_task(id) {
  607. if (task_exists(TASKID+id)) remove_task(TASKID+id)
  608. kill_trail_msg(id)
  609. gl_player_colors[id][0] = gl_player_colors[id][1] = gl_player_colors[id][2] = 0
  610. }
  611.  
  612. /*****************************************************************************************
  613. *****************************************************************************************/
  614. kill_trail_msg(id) {
  615. gl_timer_count[id] = 0
  616.  
  617. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  618. write_byte(99) // TE_KILLBEAM
  619. write_short(id)
  620. message_end()
  621. }
  622.  
  623. /*****************************************************************************************
  624. *****************************************************************************************/
  625. trail_msg(id) {
  626. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  627. write_byte(22) // TE_BEAMFOLLOW
  628. write_short(id)
  629. write_short(gl_trail_type[id])
  630. write_byte(gl_trail_life*10)
  631. write_byte(gl_trail_size[id])
  632. write_byte(gl_player_colors[id][0])
  633. write_byte(gl_player_colors[id][1])
  634. write_byte(gl_player_colors[id][2])
  635. write_byte(gl_trail_brightness[id])
  636. message_end()
  637.  
  638. }
  639.  
  640. /*****************************************************************************************
  641. *****************************************************************************************/
  642. restart_player_trail(id) {
  643. if (task_exists(TASKID+id)) {
  644. remove_task(TASKID+id)
  645. kill_trail_msg(id)
  646. get_user_origin(id, gl_player_position[id])
  647. set_task(TICK, "check_position", TASKID+id, "", 0, "b")
  648. trail_msg(id)
  649. }
  650. }
  651.  
  652. /*****************************************************************************************
  653. *****************************************************************************************/
  654. restart_players_trails() {
  655. new playercount
  656.  
  657. get_players(gl_players, playercount)
  658. for (new i=0; i<playercount; i++) {
  659. restart_player_trail(gl_players[i])
  660. }
  661. }
  662.  
  663. /*****************************************************************************************
  664. *****************************************************************************************/
  665. say_to_all(msg[], id) {
  666. new playercount
  667.  
  668. get_players(gl_players, playercount)
  669. for (new i=0; i<playercount; i++) {
  670. if (gl_players[i]!=id) client_print(gl_players[i], print_chat, msg)
  671. }
  672. }
  673.  
  674. /*****************************************************************************************
  675. *****************************************************************************************/
  676. trail_help(id) {
  677. new msg[200], clen=0
  678.  
  679. console_print(id, "^nTrail Colors List:^n")
  680. for (new i=0; i<gl_num_colors; i++) {
  681. clen += format(msg[clen], 199-clen, "%s ", gl_color_names[i])
  682. if (clen > 80) {
  683. console_print(id, msg)
  684. copy(msg, 1, "")
  685. clen = 0
  686. }
  687. }
  688. console_print(id, "^nNOTE: All colors can be prefixed by the words 'light' or 'dark'.^n")
  689. console_print(id, "^nSay 'trail <color>' to get a colored trail.^nSay 'trail off' to turn trail off.")
  690. console_print(id, "Say 'trail <number> [color]' to change the look of the trail.^n")
  691. console_print(id, "^nExamples:")
  692. console_print(id, " trail")
  693. console_print(id, " trail off")
  694. console_print(id, " trail tomato")
  695. console_print(id, " trail 6 gold")
  696. console_print(id, " trail 11 light blue")
  697. client_print(id, print_chat, "The colors list has been displayed in your console.")
  698. }
  699.  
  700. /*****************************************************************************************
  701. *****************************************************************************************/
  702. bool:parse_file() {
  703. new got_line, line_num=0, len=0, parsed
  704. new r[3][4], g[3][4], b[3][4]
  705. new full_line[MAX_TEXT_LENGTH], rest_line[MAX_TEXT_LENGTH], cfgdir[MAX_TEXT_LENGTH], cfgpath[MAX_TEXT_LENGTH]
  706.  
  707. gl_num_colors = 0
  708. get_configsdir(cfgdir, MAX_TEXT_LENGTH)
  709. format(cfgpath, MAX_TEXT_LENGTH, "%s/%s", cfgdir, CFG_FILE)
  710. if (!file_exists(cfgpath)) {
  711. log_amx("ERROR: Cannot find configuration file '%s'!", cfgpath)
  712. return false
  713. }
  714. got_line = read_file(cfgpath, line_num, full_line, MAX_TEXT_LENGTH, len)
  715. if (got_line <=0) {
  716. log_amx("ERROR: Cannot read configuration file '%s'!", cfgpath)
  717. return false
  718. }
  719. while (got_line>0) {
  720. if (!equal(full_line, "//", 2) && len) {
  721. strtok(full_line, gl_color_names[gl_num_colors], MAX_NAME_LENGTH, rest_line, MAX_TEXT_LENGTH, ' ', 1)
  722. copy(full_line, MAX_TEXT_LENGTH, rest_line)
  723.  
  724. parsed = parse(full_line,r[0],3,g[0],3,b[0],3)
  725. if (parsed<3) {
  726. log_amx("ERROR: Not enough colors, line %d in configuration file '%s'!", 1+line_num, CFG_FILE)
  727. return false
  728. }
  729. gl_colors[gl_num_colors][0] = str_to_num(r[0])
  730. gl_colors[gl_num_colors][1] = str_to_num(g[0])
  731. gl_colors[gl_num_colors][2] = str_to_num(b[0])
  732.  
  733. gl_num_colors++
  734. if (gl_num_colors>=MAX_COLORS) {
  735. log_amx("WARNING: Max colors reached in file '%s'!", CFG_FILE)
  736. return true
  737. }
  738. }
  739. line_num++
  740. got_line = read_file(cfgpath, line_num, full_line, MAX_TEXT_LENGTH, len)
  741. }
  742. return true
  743. }
  744.  
  745. check_map() {
  746. new got_line, line_num, len
  747. new cfgdir[MAX_TEXT_LENGTH]
  748. new cfgpath[MAX_TEXT_LENGTH]
  749. new mapname[MAX_NAME_LENGTH]
  750. new txt[MAX_TEXT_LENGTH]
  751.  
  752. get_configsdir(cfgdir, MAX_TEXT_LENGTH-1)
  753. get_mapname(mapname, MAX_NAME_LENGTH-1)
  754.  
  755. format(cfgpath, MAX_TEXT_LENGTH, "%s/sensiblemaps.cfg", cfgdir)
  756.  
  757. if (file_exists(cfgpath)) {
  758. got_line = read_file(cfgpath, line_num, txt, MAX_TEXT_LENGTH-1, len)
  759. while (got_line>0) {
  760. if (equali(txt, mapname)) return 1
  761. line_num++
  762. got_line = read_file(cfgpath, line_num, txt, MAX_TEXT_LENGTH-1, len)
  763. }
  764. }
  765. return 0
  766. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement