iPixel99

train plugin

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