HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <fakemeta>
  4. #include <xs>
  5.  
  6. #define PLUGIN "Magic Marker"
  7. #define VERSION "3.1"
  8. #define AUTHOR "stupok69"
  9.  
  10. #define MAX_PLAYERS 32
  11. #define USAGE_LEVEL ADMIN_KICK
  12.  
  13. new Float:origin[MAX_PLAYERS+1][3]
  14. new prethink_counter[MAX_PLAYERS+1]
  15. new bool:is_drawing[MAX_PLAYERS+1]
  16. new bool:is_holding[MAX_PLAYERS+1]
  17.  
  18. new spriteid
  19.  
  20. public plugin_init()
  21. {
  22. register_plugin(PLUGIN, VERSION, AUTHOR)
  23. register_clcmd("+paint", "paint_handler", USAGE_LEVEL, "Paint on the walls!")
  24. register_clcmd("-paint", "paint_handler", USAGE_LEVEL, "Paint on the walls!")
  25. register_forward(FM_PlayerPreThink, "forward_FM_PlayerPreThink", 0)
  26. }
  27.  
  28. public plugin_precache()
  29. {
  30. spriteid = precache_model("sprites/lgtning.spr")
  31. }
  32.  
  33. public paint_handler(id, level, cid)
  34. {
  35. if(!cmd_access(id, level, cid, 1))
  36. return PLUGIN_HANDLED
  37.  
  38. if(!is_user_alive(id))
  39. {
  40. client_print(id, print_chat, "* Nem hasznalhatod a filctollat,mert halott vagy.")
  41. return PLUGIN_HANDLED
  42. }
  43.  
  44. static cmd[2]
  45. read_argv(0, cmd, 1)
  46.  
  47. switch(cmd[0])
  48. {
  49. case '+': is_drawing[id] = true
  50. case '-': is_drawing[id] = false
  51. }
  52. return PLUGIN_HANDLED
  53. }
  54.  
  55. public forward_FM_PlayerPreThink(id)
  56. {
  57. if(prethink_counter[id]++ > 5)
  58. {
  59. if(is_drawing[id] && !is_aiming_at_sky(id))
  60. {
  61. static Float:cur_origin[3], Float:distance
  62.  
  63. cur_origin = origin[id]
  64.  
  65. if(!is_holding[id])
  66. {
  67. fm_get_aim_origin(id, origin[id])
  68. move_toward_client(id, origin[id])
  69. is_holding[id] = true
  70. return FMRES_IGNORED
  71. }
  72.  
  73. fm_get_aim_origin(id, origin[id])
  74. move_toward_client(id, origin[id])
  75.  
  76. distance = get_distance_f(origin[id], cur_origin)
  77.  
  78. if(distance > 2)
  79. {
  80. draw_line(origin[id], cur_origin)
  81. }
  82. }
  83. else
  84. {
  85. is_holding[id] = false
  86. }
  87. prethink_counter[id] = 0
  88. }
  89.  
  90. return FMRES_IGNORED
  91. }
  92.  
  93. stock draw_line(Float:origin1[3], Float:origin2[3])
  94. {
  95. message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
  96. write_byte(TE_BEAMPOINTS)
  97. engfunc(EngFunc_WriteCoord, origin1[0])
  98. engfunc(EngFunc_WriteCoord, origin1[1])
  99. engfunc(EngFunc_WriteCoord, origin1[2])
  100. engfunc(EngFunc_WriteCoord, origin2[0])
  101. engfunc(EngFunc_WriteCoord, origin2[1])
  102. engfunc(EngFunc_WriteCoord, origin2[2])
  103. write_short(spriteid)
  104. write_byte(0)
  105. write_byte(10)
  106. write_byte(255)
  107. write_byte(50)
  108. write_byte(0)
  109. write_byte(random(255))
  110. write_byte(random(255))
  111. write_byte(random(255))
  112. write_byte(255)
  113. write_byte(0)
  114. message_end()
  115. }
  116.  
  117. //from fakemeta_util.inc
  118. stock fm_get_aim_origin(index, Float:origin[3])
  119. {
  120. static Float:start[3], Float:view_ofs[3]
  121. pev(index, pev_origin, start)
  122. pev(index, pev_view_ofs, view_ofs)
  123. xs_vec_add(start, view_ofs, start)
  124.  
  125. static Float:dest[3]
  126. pev(index, pev_v_angle, dest)
  127. engfunc(EngFunc_MakeVectors, dest)
  128. global_get(glb_v_forward, dest)
  129. xs_vec_mul_scalar(dest, 9999.0, dest)
  130. xs_vec_add(start, dest, dest)
  131.  
  132. engfunc(EngFunc_TraceLine, start, dest, 0, index, 0)
  133. get_tr2(0, TR_vecEndPos, origin)
  134.  
  135. return 1
  136. }
  137.  
  138. stock move_toward_client(id, Float:origin[3])
  139. {
  140. static Float:player_origin[3]
  141.  
  142. pev(id, pev_origin, player_origin)
  143.  
  144. origin[0] += (player_origin[0] > origin[0]) ? 1.0 : -1.0
  145. origin[1] += (player_origin[1] > origin[1]) ? 1.0 : -1.0
  146. origin[2] += (player_origin[2] > origin[2]) ? 1.0 : -1.0
  147. }
  148. //Thanks AdaskoMX!
  149. bool:is_aiming_at_sky(index)
  150. {
  151. new Float:origin[3];
  152. fm_get_aim_origin(index, origin);
  153.  
  154. return engfunc(EngFunc_PointContents, origin) == CONTENTS_SKY;
  155. }
  156.