Arxero

plugin_trail

Aug 26th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.67 KB | None | 0 0
  1. /*****************************************************************************************
  2. *
  3. * plugin_trail.sma
  4. *
  5. * By Bahrmanou ([email protected])
  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_RCON
  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_team", "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 (!(get_user_flags(id) & ADMIN_ALL))
  425. {
  426. client_print(id, print_chat, "Enjoy the Trails! :-)");
  427. return PLUGIN_HANDLED;
  428. }
  429.  
  430. if (equali(args, "trail", 5)) {
  431. if (!gl_trail) {
  432. client_print(id, print_chat, "Trails have been disabled.")
  433. return PLUGIN_HANDLED
  434. }
  435. if (gl_not_this_map) {
  436. client_print(id, print_chat, "Trails have been disabled for this map.")
  437. return PLUGIN_HANDLED
  438. }
  439.  
  440. get_user_name(id, plName, MAX_NAME_LENGTH)
  441. if (!get_user_team(id) && !access(id, ADMIN_ADMIN)) {
  442. client_print(id, print_chat, "You must be playing!")
  443. return PLUGIN_HANDLED
  444. }
  445.  
  446. if (!args[5]) {
  447. do_trail(id, "", "")
  448. return PLUGIN_HANDLED
  449. } else {
  450. parse(args[6], colname, MAX_NAME_LENGTH, arg2, MAX_NAME_LENGTH, arg3, MAX_NAME_LENGTH)
  451. // console_print(id, "restline = '%s'", restline)
  452. typenum = str_to_num(colname)
  453. }
  454.  
  455. if (equali(colname, "off")) {
  456. if (!gl_player_colors[id][0] && !gl_player_colors[id][1] && !gl_player_colors[id][2]) {
  457. client_print(id, print_chat, "Your trail is already off!")
  458. return PLUGIN_HANDLED
  459. }
  460. kill_trail_task(id)
  461. client_print(id, print_chat, "Your trail was removed.")
  462. format(msg, 199, "%s's trail was removed.", plName)
  463. say_to_all(msg, id)
  464. return PLUGIN_HANDLED
  465. } else if (equali(colname, "random")) {
  466. do_trail(id, "", "")
  467. return PLUGIN_HANDLED
  468. } else if (equali(colname, "help")) {
  469. trail_help(id)
  470. return PLUGIN_HANDLED
  471. }
  472.  
  473. if (typenum) {
  474. if (typenum<1 || typenum>NUM_SPRITES) {
  475. client_print(id, print_chat, "Type must be in the range [1,%d].", NUM_SPRITES)
  476. return PLUGIN_HANDLED
  477. }
  478. typenum--
  479. gl_trail_type[id] = gl_sprite[typenum]
  480. gl_trail_size[id] = gl_def_sprite_size[typenum]
  481. gl_trail_brightness[id] = gl_def_sprite_brightness[typenum]
  482. if (arg2[0]) {
  483. colname = arg2
  484. arg2 = arg3
  485. } else {
  486. if (!gl_player_colors[id][0] && !gl_player_colors[id][1] && !gl_player_colors[id][2]) {
  487. do_trail(id, "", "")
  488. return PLUGIN_HANDLED
  489. }
  490. new r = gl_player_colors[id][0]
  491. new g = gl_player_colors[id][1]
  492. new b = gl_player_colors[id][2]
  493. kill_trail_task(id)
  494. gl_player_colors[id][0] = r
  495. gl_player_colors[id][1] = g
  496. gl_player_colors[id][2] = b
  497. get_user_origin(id, gl_player_position[id])
  498. set_task(TICK, "check_position", TASKID+id, "", 0, "b")
  499. trail_msg(id)
  500. client_print(id, print_chat, "You have a trail of type %d.", typenum+1)
  501. format(msg, 199, "%s has a type %d trail.", plName, typenum+1)
  502. say_to_all(msg, id)
  503. return PLUGIN_HANDLED
  504. }
  505. }
  506.  
  507. if (equali(colname, "dark")) {
  508. copy(colname, MAX_NAME_LENGTH-1, arg2)
  509. if (!colname[0]) {
  510. client_print(id, print_chat, "Specify a color name!")
  511. return PLUGIN_HANDLED
  512. }
  513. do_trail(id, colname, "dark")
  514. } else if (equali(colname, "light")) {
  515. copy(colname, MAX_NAME_LENGTH-1, arg2)
  516. if (!colname[0]) {
  517. client_print(id, print_chat, "Specify a color name!")
  518. return PLUGIN_HANDLED
  519. }
  520. do_trail(id, colname, "light")
  521. }
  522. else {
  523. do_trail(id, colname, "")
  524. }
  525. }
  526. return PLUGIN_CONTINUE
  527. }
  528.  
  529. /*****************************************************************************************
  530. *****************************************************************************************/
  531. do_trail(id, colname[], intensity[]) {
  532. new i, msg[200]
  533. new name[33]
  534.  
  535. get_user_name(id, name, 32)
  536. if (!colname[0]) {
  537. kill_trail_task(id)
  538. gl_player_colors[id][0] = random(256)
  539. gl_player_colors[id][1] = random(256)
  540. gl_player_colors[id][2] = random(256)
  541. get_user_origin(id, gl_player_position[id])
  542. set_task(TICK, "check_position", TASKID+id, "", 0, "b")
  543. trail_msg(id)
  544. client_print(id, print_chat, "You have a random color trail.")
  545. format(msg, 199, "%s has a random color trail.", name)
  546. say_to_all(msg, id)
  547. return
  548. }
  549. for (i=0; i<gl_num_colors; i++) {
  550. if (equali(colname, gl_color_names[i])) {
  551. new Float:intens, r, g, b
  552. if (equali(intensity, "dark")) {
  553. intens = 0.5
  554. } else if (equali(intensity, "light")) {
  555. intens = 2.0
  556. } else {
  557. copy(intensity, 1, "")
  558. intens = 1.0
  559. }
  560. kill_trail_task(id)
  561. r = floatround(float(gl_colors[i][0]) * intens)
  562. g = floatround(float(gl_colors[i][1]) * intens)
  563. b = floatround(float(gl_colors[i][2]) * intens)
  564. gl_player_colors[id][0] = min(r, 255)
  565. gl_player_colors[id][1] = min(g, 255)
  566. gl_player_colors[id][2] = min(b, 255)
  567. get_user_origin(id, gl_player_position[id])
  568. set_task(TICK, "check_position", TASKID+id, "", 0, "b")
  569. trail_msg(id)
  570. if (intensity[0]) {
  571. client_print(id, print_chat, "You have a %s %s trail.", intensity, colname)
  572. format(msg, 199, "%s has now a %s %s trail.", name, intensity, colname)
  573. } else {
  574. client_print(id, print_chat, "You have a %s trail.", colname)
  575. format(msg, 199, "%s has now a %s trail.", name, colname)
  576. }
  577. say_to_all(msg, id)
  578. return
  579. }
  580. }
  581. client_print(id, print_chat, "Sorry, %s, but I dont recognize the color '%s'!", name, colname)
  582. return
  583. }
  584.  
  585. /*****************************************************************************************
  586. *****************************************************************************************/
  587. public check_position(taskid) {
  588. new origin[3], id = taskid-TASKID
  589.  
  590. if (!get_user_team(id)) {
  591. kill_trail_msg(id)
  592. return
  593. }
  594.  
  595. get_user_origin(id, origin)
  596. if (origin[0]!=gl_player_position[id][0] || origin[1]!=gl_player_position[id][1] || origin[2]!=gl_player_position[id][2]) {
  597. if (get_distance(origin, gl_player_position[id])>MAX_DISTANCE || gl_timer_count[id] >= gl_timer_limit/2) {
  598. kill_trail_msg(id)
  599. trail_msg(id)
  600. }
  601. gl_player_position[id][0] = origin[0]
  602. gl_player_position[id][1] = origin[1]
  603. gl_player_position[id][2] = origin[2]
  604. gl_timer_count[id] = 0
  605. } else {
  606. if (gl_timer_count[id] < gl_timer_limit) gl_timer_count[id]++
  607. }
  608. }
  609.  
  610. /*****************************************************************************************
  611. *****************************************************************************************/
  612. kill_trail_task(id) {
  613. if (task_exists(TASKID+id)) remove_task(TASKID+id)
  614. kill_trail_msg(id)
  615. gl_player_colors[id][0] = gl_player_colors[id][1] = gl_player_colors[id][2] = 0
  616. }
  617.  
  618. /*****************************************************************************************
  619. *****************************************************************************************/
  620. kill_trail_msg(id) {
  621. gl_timer_count[id] = 0
  622.  
  623. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  624. write_byte(99) // TE_KILLBEAM
  625. write_short(id)
  626. message_end()
  627. }
  628.  
  629. /*****************************************************************************************
  630. *****************************************************************************************/
  631. trail_msg(id) {
  632. message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
  633. write_byte(22) // TE_BEAMFOLLOW
  634. write_short(id)
  635. write_short(gl_trail_type[id])
  636. write_byte(gl_trail_life*10)
  637. write_byte(gl_trail_size[id])
  638. write_byte(gl_player_colors[id][0])
  639. write_byte(gl_player_colors[id][1])
  640. write_byte(gl_player_colors[id][2])
  641. write_byte(gl_trail_brightness[id])
  642. message_end()
  643.  
  644. }
  645.  
  646. /*****************************************************************************************
  647. *****************************************************************************************/
  648. restart_player_trail(id) {
  649. if (task_exists(TASKID+id)) {
  650. remove_task(TASKID+id)
  651. kill_trail_msg(id)
  652. get_user_origin(id, gl_player_position[id])
  653. set_task(TICK, "check_position", TASKID+id, "", 0, "b")
  654. trail_msg(id)
  655. }
  656. }
  657.  
  658. /*****************************************************************************************
  659. *****************************************************************************************/
  660. restart_players_trails() {
  661. new playercount
  662.  
  663. get_players(gl_players, playercount)
  664. for (new i=0; i<playercount; i++) {
  665. restart_player_trail(gl_players[i])
  666. }
  667. }
  668.  
  669. /*****************************************************************************************
  670. *****************************************************************************************/
  671. say_to_all(msg[], id) {
  672. new playercount
  673.  
  674. get_players(gl_players, playercount)
  675. for (new i=0; i<playercount; i++) {
  676. if (gl_players[i]!=id) client_print(gl_players[i], print_chat, msg)
  677. }
  678. }
  679.  
  680. /*****************************************************************************************
  681. *****************************************************************************************/
  682. trail_help(id) {
  683. new msg[200], clen=0
  684.  
  685. console_print(id, "^nTrail Colors List:^n")
  686. for (new i=0; i<gl_num_colors; i++) {
  687. clen += format(msg[clen], 199-clen, "%s ", gl_color_names[i])
  688. if (clen > 80) {
  689. console_print(id, msg)
  690. copy(msg, 1, "")
  691. clen = 0
  692. }
  693. }
  694. console_print(id, "^nNOTE: All colors can be prefixed by the words 'light' or 'dark'.^n")
  695. console_print(id, "^nSay 'trail <color>' to get a colored trail.^nSay 'trail off' to turn trail off.")
  696. console_print(id, "Say 'trail <number> [color]' to change the look of the trail.^n")
  697. console_print(id, "^nExamples:")
  698. console_print(id, " trail")
  699. console_print(id, " trail off")
  700. console_print(id, " trail tomato")
  701. console_print(id, " trail 6 gold")
  702. console_print(id, " trail 11 light blue")
  703. client_print(id, print_chat, "The colors list has been displayed in your console.")
  704. }
  705.  
  706. /*****************************************************************************************
  707. *****************************************************************************************/
  708. bool:parse_file() {
  709. new got_line, line_num=0, len=0, parsed
  710. new r[3][4], g[3][4], b[3][4]
  711. new full_line[MAX_TEXT_LENGTH], rest_line[MAX_TEXT_LENGTH], cfgdir[MAX_TEXT_LENGTH], cfgpath[MAX_TEXT_LENGTH]
  712.  
  713. gl_num_colors = 0
  714. get_configsdir(cfgdir, MAX_TEXT_LENGTH)
  715. format(cfgpath, MAX_TEXT_LENGTH, "%s/%s", cfgdir, CFG_FILE)
  716. if (!file_exists(cfgpath)) {
  717. log_amx("ERROR: Cannot find configuration file '%s'!", cfgpath)
  718. return false
  719. }
  720. got_line = read_file(cfgpath, line_num, full_line, MAX_TEXT_LENGTH, len)
  721. if (got_line <=0) {
  722. log_amx("ERROR: Cannot read configuration file '%s'!", cfgpath)
  723. return false
  724. }
  725. while (got_line>0) {
  726. if (!equal(full_line, "//", 2) && len) {
  727. strtok(full_line, gl_color_names[gl_num_colors], MAX_NAME_LENGTH, rest_line, MAX_TEXT_LENGTH, ' ', 1)
  728. copy(full_line, MAX_TEXT_LENGTH, rest_line)
  729.  
  730. parsed = parse(full_line,r[0],3,g[0],3,b[0],3)
  731. if (parsed<3) {
  732. log_amx("ERROR: Not enough colors, line %d in configuration file '%s'!", 1+line_num, CFG_FILE)
  733. return false
  734. }
  735. gl_colors[gl_num_colors][0] = str_to_num(r[0])
  736. gl_colors[gl_num_colors][1] = str_to_num(g[0])
  737. gl_colors[gl_num_colors][2] = str_to_num(b[0])
  738.  
  739. gl_num_colors++
  740. if (gl_num_colors>=MAX_COLORS) {
  741. log_amx("WARNING: Max colors reached in file '%s'!", CFG_FILE)
  742. return true
  743. }
  744. }
  745. line_num++
  746. got_line = read_file(cfgpath, line_num, full_line, MAX_TEXT_LENGTH, len)
  747. }
  748. return true
  749. }
  750.  
  751. check_map() {
  752. new got_line, line_num, len
  753. new cfgdir[MAX_TEXT_LENGTH]
  754. new cfgpath[MAX_TEXT_LENGTH]
  755. new mapname[MAX_NAME_LENGTH]
  756. new txt[MAX_TEXT_LENGTH]
  757.  
  758. get_configsdir(cfgdir, MAX_TEXT_LENGTH-1)
  759. get_mapname(mapname, MAX_NAME_LENGTH-1)
  760.  
  761. format(cfgpath, MAX_TEXT_LENGTH, "%s/sensiblemaps.cfg", cfgdir)
  762.  
  763. if (file_exists(cfgpath)) {
  764. got_line = read_file(cfgpath, line_num, txt, MAX_TEXT_LENGTH-1, len)
  765. while (got_line>0) {
  766. if (equali(txt, mapname)) return 1
  767. line_num++
  768. got_line = read_file(cfgpath, line_num, txt, MAX_TEXT_LENGTH-1, len)
  769. }
  770. }
  771. return 0
  772. }
Add Comment
Please, Sign In to add comment