Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.01 KB | None | 0 0
  1. #include <amxmodx>
  2. #include <amxmisc>
  3. #include <engine>
  4. #include <fakemeta_util>
  5. #include <hamsandwich>
  6.  
  7. #define PLUGIN "Ghost"
  8. #define VERSION "1.0"
  9. #define AUTHOR "Unknown"
  10.  
  11. new const MODEL_GHOST[][] = {
  12. "models/GlobalKnifeHW/ghost.mdl",
  13. "models/GlobalKnifeHW/ghost2.mdl"
  14. }
  15.  
  16. #define GHOST_CLASS "ent_ghost"
  17. #define MAIN_ORIGIN1 pev_iuser1
  18. #define MAIN_ORIGIN2 pev_iuser2
  19. #define MAIN_ORIGIN3 pev_iuser3
  20. #define NEXT_ORIGIN1 pev_fuser1
  21. #define NEXT_ORIGIN2 pev_fuser2
  22. #define NEXT_ORIGIN3 pev_fuser3
  23. #define TOOK_NEXT pev_iuser4
  24. #define NEXT_FADE pev_fuser4
  25. #define THINK_RATE 0.075
  26. #define GHOST_SPEED 50.0
  27.  
  28. new Float: MIN_X = 300.0,Float:MAX_X = 1000.0;
  29. new Float: MIN_Y = 300.0,Float:MAX_Y = 1000.0;
  30. new Float: MIN_Z = -100.0,Float:MAX_Z = 100.0;
  31. new bool:g_save_cpl
  32.  
  33. enum{
  34. No = 0,
  35. Yes = 1
  36. }
  37.  
  38. static Array:g_cp_id, Array:g_cp_origin_x, Array:g_cp_origin_y, Array:g_cp_origin_z
  39.  
  40. public plugin_precache()
  41. {
  42. for(new i=0;i < sizeof(MODEL_GHOST);i++)
  43. precache_model(MODEL_GHOST[i])
  44. }
  45.  
  46. public plugin_init()
  47. {
  48. register_plugin(PLUGIN, VERSION, AUTHOR)
  49.  
  50. g_cp_id = ArrayCreate()
  51. g_cp_origin_x = ArrayCreate()
  52. g_cp_origin_y = ArrayCreate()
  53. g_cp_origin_z = ArrayCreate()
  54.  
  55. register_clcmd("ghost_menu", "ghosts_menu", ADMIN_RCON)
  56. register_think(GHOST_CLASS, "fw_ghost_think")
  57. get_maps_cfg()
  58. set_lights("c")
  59. }
  60.  
  61. public fw_ghost_think(ent)
  62. {
  63. if(!pev_valid(ent))
  64. return
  65. static took_next;
  66. render_it(ent)
  67. light_it_up(ent)
  68. took_next = pev(ent,TOOK_NEXT)
  69. if(!took_next)
  70. {
  71. static Float:x,Float:y,Float:z;
  72. static xi,yi,zi;
  73. xi= pev(ent,MAIN_ORIGIN1)
  74. yi = pev(ent,MAIN_ORIGIN2)
  75. zi = pev(ent,MAIN_ORIGIN3)
  76. x = float(xi)+random_float(MIN_X,MAX_X)
  77. y = float(yi)+random_float(MIN_Y,MAX_Y)
  78. z = float(zi)+random_float(MIN_Z,MAX_Z)
  79. set_pev(ent,NEXT_ORIGIN1,x)
  80. set_pev(ent,NEXT_ORIGIN2,y)
  81. set_pev(ent,NEXT_ORIGIN3,z)
  82. set_pev(ent,TOOK_NEXT,Yes)
  83. }
  84. else
  85. {
  86. static Float:next_coord[3];
  87. pev(ent,NEXT_ORIGIN1,next_coord[0])
  88. pev(ent,NEXT_ORIGIN2,next_coord[1])
  89. pev(ent,NEXT_ORIGIN3,next_coord[2])
  90. move_ent(ent,next_coord,GHOST_SPEED)
  91. }
  92. set_pev(ent, pev_nextthink, halflife_time() + 0.075)
  93. }
  94.  
  95. public light_it_up(ent)
  96. {
  97. static Float:origin[3]
  98. message_begin(MSG_BROADCAST,SVC_TEMPENTITY);
  99. write_byte(TE_DLIGHT) // TE id
  100. write_coord(floatround(origin[0])); // x
  101. write_coord(floatround(origin[1])); // y
  102. write_coord(floatround(origin[2])); // z
  103. write_byte(40) // radius
  104. write_byte(100) // r
  105. write_byte(100) // g
  106. write_byte(100) // b
  107. write_byte(2) // life
  108. write_byte(0) // decay rate
  109. message_end()
  110.  
  111. }
  112.  
  113. public render_it(ent)
  114. {
  115. new Float:next_fade;
  116. next_fade = 255.0 // incase
  117. pev(ent,NEXT_FADE,next_fade)
  118. if(255.0 > next_fade)
  119. {
  120. next_fade += 1.0
  121. if(next_fade > 255.0)
  122. {
  123. next_fade = 255.0
  124. set_pev(ent,NEXT_FADE,255.0)
  125. client_print(0,print_console,"%f",next_fade)
  126. }
  127. }
  128. else if(next_fade >= 254.0)
  129. {
  130. next_fade -= 1.0
  131. if(50.0 > next_fade)
  132. {
  133. next_fade = 10.0
  134. set_pev(ent,NEXT_FADE,10.0)
  135. client_print(0,print_console,"%f",next_fade)
  136. }
  137. }
  138. set_rendering(ent,kRenderFxNone,0,0,0,kRenderNormal,floatround(next_fade))
  139. }
  140.  
  141. public plugin_end() // dunno if this is needed but let's just put it, if it causes problems then remove it.
  142. {
  143. remove_ghosts()
  144. }
  145.  
  146. stock remove_ghosts()
  147. {
  148. new ghost = -1;
  149.  
  150. while((ghost=find_ent_by_class(ghost,GHOST_CLASS)))
  151. {
  152. if(pev_valid(ghost))
  153. remove_entity(ghost)
  154. }
  155. }
  156.  
  157. public move_ent(ent, Float:VicOrigin[3], Float:speed)
  158. {
  159. static Float:fl_Velocity[3]
  160. static Float:EntOrigin[3]
  161.  
  162. pev(ent, pev_origin, EntOrigin)
  163. turn_to_origin(ent, EntOrigin, VicOrigin)
  164. static Float:distance;
  165. distance = get_distance_f(EntOrigin, VicOrigin)
  166. if (25.0 > distance)
  167. set_pev(ent,TOOK_NEXT,No)
  168.  
  169. new Float:fl_Time = distance / speed
  170.  
  171. fl_Velocity[0] = (VicOrigin[0] - EntOrigin[0]) / fl_Time
  172. fl_Velocity[1] = (VicOrigin[1] - EntOrigin[1]) / fl_Time
  173. fl_Velocity[2] = (VicOrigin[2] - EntOrigin[2]) / fl_Time
  174. entity_set_vector(ent, EV_VEC_velocity, fl_Velocity)
  175.  
  176. }
  177.  
  178. public turn_to_origin(ent, Float:Ent_Origin[3], Float:Vic_Origin[3])
  179. {
  180. new Float:newAngle[3]
  181. entity_get_vector(ent, EV_VEC_angles, newAngle)
  182. new Float:x = Vic_Origin[0] - Ent_Origin[0]
  183. new Float:z = Vic_Origin[1] - Ent_Origin[1]
  184.  
  185. new Float:radians = floatatan(z/x, radian)
  186. newAngle[1] = radians * (180 / 3.14)
  187. if (Vic_Origin[0] < Ent_Origin[0])
  188. newAngle[1] -= 180.0
  189.  
  190. entity_set_vector(ent, EV_VEC_angles, newAngle)
  191. }
  192.  
  193. public get_maps_cfg()
  194. {
  195. new map[32]
  196. get_mapname(map, charsmax(map))
  197. formatex(map, charsmax(map),"%s.ini",map)
  198.  
  199. new cfgDir[64], i_Dir, i_File[128]
  200. get_configsdir(cfgDir, charsmax(cfgDir))
  201. formatex(cfgDir, charsmax(cfgDir), "%s/ghost", cfgDir)
  202.  
  203. i_Dir = open_dir(cfgDir, i_File, charsmax(i_File))
  204.  
  205. if(i_Dir)
  206. {
  207. while(next_file(i_Dir, i_File, charsmax(i_File)))
  208. {
  209. if (i_File[0] == '.')
  210. continue
  211.  
  212. if(equal(map, i_File))
  213. {
  214. format(i_File,128,"%s/%s",cfgDir, i_File)
  215. get_checkpoints(i_File)
  216. break
  217. }
  218. }
  219. }
  220. }
  221.  
  222. public set_maps_cfg()
  223. {
  224. new map[32]
  225. get_mapname(map, charsmax(map))
  226. formatex(map, charsmax(map),"%s.ini",map)
  227.  
  228. new cfgDir[64], i_File[128]
  229. get_configsdir(cfgDir, charsmax(cfgDir))
  230. formatex(cfgDir, charsmax(cfgDir), "%s/ghost", cfgDir)
  231. formatex(i_File, charsmax(i_File),"%s/%s",cfgDir, map)
  232.  
  233. if(!dir_exists(cfgDir))
  234. if(!mkdir(cfgDir))
  235. return
  236.  
  237. delete_file(i_File)
  238.  
  239. static cp_count; cp_count = ArraySize(g_cp_id)
  240. if(!cp_count)
  241. return
  242.  
  243. for(new i=0; i<cp_count; i++)
  244. {
  245. new text[128], Float:fOrigin[3], ent = ArrayGetCell(g_cp_id, i)
  246. pev(ent, pev_origin, fOrigin)
  247. format(text, charsmax(text),"^"%f^" ^"%f^" ^"%f^"",fOrigin[0], fOrigin[1], fOrigin[2])
  248. write_file(i_File, text, i)
  249. }
  250. }
  251.  
  252. public get_checkpoints(i_File[128])
  253. {
  254. new file = fopen(i_File,"rt")
  255.  
  256. while(file && !feof(file))
  257. {
  258. new sfLineData[512]
  259. fgets(file, sfLineData, charsmax(sfLineData))
  260.  
  261. if(sfLineData[0] == ';')
  262. continue
  263.  
  264. if(equal(sfLineData,""))
  265. continue
  266.  
  267. new i_origins[3][32], Float: fOrigins[3]
  268. parse(sfLineData, i_origins[0], 31, i_origins[1], 31, i_origins[2], 31)
  269.  
  270. fOrigins[0] = str_to_float(i_origins[0])
  271. fOrigins[1] = str_to_float(i_origins[1])
  272. fOrigins[2] = str_to_float(i_origins[2])
  273.  
  274. create_checkpoint(fOrigins)
  275. }
  276.  
  277. fclose(file)
  278. }
  279.  
  280. public ghosts_menu(id)
  281. {
  282. static cp_count; cp_count = ArraySize(g_cp_id)
  283.  
  284. new menu_name[90]
  285. format(menu_name, 90, "\rGhostMenu")
  286.  
  287. new i_menu = menu_create(menu_name, "menu_handler")
  288.  
  289. menu_additem(i_menu, "\wAdd ghost", "1", 0)
  290.  
  291. if(!cp_count)
  292. {
  293. menu_additem(i_menu, "\dDelete Previous added", "2", 0)
  294. menu_additem(i_menu, "\dDelete all", "3", 0)
  295. }
  296. else
  297. {
  298. menu_additem(i_menu, "\wDelete Previous added", "2", 0)
  299. menu_additem(i_menu, "\wDelete all", "3", 0)
  300. }
  301.  
  302. if(!g_save_cpl)
  303. menu_additem(i_menu, "\dSave changes", "4", 0)
  304. else menu_additem(i_menu, "\wSave changes", "4", 0)
  305.  
  306. menu_setprop(i_menu, MPROP_EXIT, MEXIT_ALL)
  307. menu_setprop(i_menu, MPROP_EXITNAME, "\yExit")
  308. menu_display(id, i_menu, 0)
  309.  
  310. return PLUGIN_HANDLED
  311. }
  312.  
  313. public menu_handler(id, menu, item)
  314. {
  315. if (item == MENU_EXIT)
  316. {
  317. menu_destroy(menu)
  318. return PLUGIN_HANDLED
  319. }
  320.  
  321. static cp_count; cp_count = ArraySize(g_cp_id)
  322. switch(item)
  323. {
  324. case 0:
  325. {
  326. g_save_cpl = true
  327.  
  328. static Float:fOrigins[3]
  329. fm_get_aim_origin(id, fOrigins)
  330. fOrigins[2]+=60
  331.  
  332. create_checkpoint(fOrigins)
  333. ghosts_menu(id)
  334. }
  335. case 1:
  336. {
  337. if(!cp_count)
  338. {
  339. client_print(id, print_chat, "No ghosts on this map")
  340. ghosts_menu(id)
  341. return PLUGIN_HANDLED
  342. }
  343.  
  344. g_save_cpl = true
  345. client_print(id, print_chat, "Ghost has been deleted")
  346.  
  347. remove_entity(ArrayGetCell(g_cp_id, cp_count-1))
  348. ArrayDeleteItem(g_cp_id, cp_count-1)
  349. ArrayDeleteItem(g_cp_origin_x, cp_count-1)
  350. ArrayDeleteItem(g_cp_origin_y, cp_count-1)
  351. ArrayDeleteItem(g_cp_origin_z, cp_count-1)
  352.  
  353. if(cp_count-1)
  354. {
  355. set_pev(ArrayGetCell(g_cp_id, cp_count-2), pev_body, 2)
  356. set_pev(ArrayGetCell(g_cp_id, cp_count-2), pev_skin, 0)
  357. }
  358.  
  359. ghosts_menu(id)
  360. }
  361. case 2:
  362. {
  363. if(!cp_count)
  364. {
  365. client_print(id, print_chat, "No ghosts on this map")
  366. ghosts_menu(id)
  367. return PLUGIN_HANDLED
  368. }
  369.  
  370. g_save_cpl = true
  371. client_print(id, print_chat, "Deleted %d ghosts", cp_count)
  372.  
  373. for(new i=0; i<cp_count; i++)
  374. remove_entity(ArrayGetCell(g_cp_id, i))
  375.  
  376. ArrayClear(g_cp_id)
  377. ArrayClear(g_cp_origin_x)
  378. ArrayClear(g_cp_origin_y)
  379. ArrayClear(g_cp_origin_z)
  380. ghosts_menu(id)
  381. }
  382. case 3:
  383. {
  384. if(!g_save_cpl)
  385. {
  386. ghosts_menu(id)
  387. return PLUGIN_HANDLED
  388. }
  389.  
  390. g_save_cpl = false
  391. set_maps_cfg()
  392.  
  393. client_print(id, print_chat, "Saved")
  394. ghosts_menu(id)
  395. }
  396. }
  397. return PLUGIN_HANDLED
  398. }
  399.  
  400. public create_checkpoint(Float: fOrigins[3])
  401. {
  402. static ent; ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
  403. if(!pev_valid(ent)) return
  404.  
  405. ArrayPushCell(g_cp_id, ent)
  406.  
  407. ArrayPushCell(g_cp_origin_x, fOrigins[0])
  408. ArrayPushCell(g_cp_origin_y, fOrigins[1])
  409. ArrayPushCell(g_cp_origin_z, fOrigins[2])
  410.  
  411. engfunc(EngFunc_SetModel, ent, MODEL_GHOST[random_num(0,(sizeof(MODEL_GHOST)-1))])
  412.  
  413. set_pev(ent, pev_origin, fOrigins)
  414. set_pev(ent, pev_solid, SOLID_NOT)
  415. set_pev(ent, pev_movetype, MOVETYPE_NOCLIP)
  416. set_pev(ent, pev_sequence, 0)
  417. set_pev(ent, pev_gaitsequence, 0)
  418. set_pev(ent, pev_framerate, 1.0)
  419. set_pev(ent, pev_classname, GHOST_CLASS)
  420. set_pev(ent,NEXT_FADE,255.0)
  421. new Float:origin[3];
  422. pev(ent, pev_origin, origin)
  423. set_pev(ent,MAIN_ORIGIN1,floatround(origin[0]))
  424. set_pev(ent,MAIN_ORIGIN2,floatround(origin[1]))
  425. set_pev(ent,MAIN_ORIGIN3,floatround(origin[2]))
  426. set_pev(ent,TOOK_NEXT,No)
  427. entity_set_size(ent,Float:{-45.0, -45.0, -45.0}, Float:{45.0, 45.0, 45.0})
  428. set_pev(ent, pev_nextthink, halflife_time() + THINK_RATE)
  429. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement