Advertisement
Arxero

plugin_trail

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