Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.36 KB | None | 0 0
  1. #include <zombie_escape>
  2. #include <xs>
  3.  
  4. #define IsInSafeZone(%0) bool:(is_user_alive(%0) && !ze_is_user_zombie(%0) && g_bIsInSafeZone[%0])
  5. #define SAFEZONE_CLASSNAME "custom_safezone"
  6. #define ADMIN_ACCESS ADMIN_RCON
  7. #define TASK_BASIS_SHOWZONES 1000
  8.  
  9. new const g_szSafeZoneDir[] = "ze_safezones"
  10. static const szCoordsNames[3][] =
  11. {
  12. "X-Coordinates",
  13. "Y-Coordinates",
  14. "Z-Coordinates"
  15. }
  16.  
  17. const OFFSET_CSMENUCODE = 205
  18. const KEYSMENU = MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9|MENU_KEY_0
  19.  
  20. new bool:g_bIsInSafeZone[33] = false,
  21. Float:g_flEscapeTime = 10.0,
  22. g_iDirection = 0,
  23. g_iStepUnits = 10,
  24. g_iEditorId = 0,
  25. g_iSpriteDot
  26.  
  27. public plugin_precache()
  28. {
  29. g_iSpriteDot = precache_model("sprites/dot.spr")
  30. precache_model("models/gib_skull.mdl")
  31. }
  32.  
  33. public plugin_init()
  34. {
  35. register_plugin("[ZE] Addons: Safe Zone", "1.0", "Jack")
  36.  
  37. RegisterHam(Ham_Touch, "trigger_hurt", "Fw_TouchTrigger_Pre", 0)
  38. RegisterHam(Ham_Touch, "info_target", "Fw_TouchSafeZone_Post", 0)
  39. register_clcmd("szm", "OpenSafeZoneMenu", ADMIN_ACCESS, " - Open the safezone menu")
  40.  
  41. register_menu("Safe Zone Menu", KEYSMENU, "MainHandler")
  42. register_menu("Edit Zone Menu", KEYSMENU, "EditHandler")
  43. register_menu("Delete Zone Menu", KEYSMENU, "DeleteHandler")
  44.  
  45. set_task(0.1, "LoadZoneTask")
  46. }
  47.  
  48. public LoadZoneTask()
  49. {
  50. LoadZone()
  51. }
  52.  
  53. public Fw_TouchTrigger_Pre(iEnt, id)
  54. {
  55. if(!is_user_alive(id) || !pev_valid(iEnt))
  56. return HAM_IGNORED
  57.  
  58.  
  59. if (pev(iEnt, pev_dmg) > 8000)
  60. {
  61. return HAM_SUPERCEDE
  62. }
  63.  
  64. return HAM_IGNORED
  65. }
  66.  
  67. public Fw_TouchSafeZone_Post(iEnt, id)
  68. {
  69. if (g_iEditorId)
  70. return HAM_IGNORED
  71.  
  72. if (!is_entity(iEnt))
  73. return HAM_IGNORED
  74.  
  75. if (!FClassnameIs(iEnt, SAFEZONE_CLASSNAME))
  76. return HAM_IGNORED
  77.  
  78. if (!FClassnameIs(id, "player"))
  79. return HAM_IGNORED
  80.  
  81. g_bIsInSafeZone[id] = true
  82. return HAM_IGNORED
  83. }
  84.  
  85. public client_disconnected(id)
  86. {
  87. if (id == g_iEditorId)
  88. HideTheZone()
  89. }
  90.  
  91. public OpenSafeZoneMenu(id)
  92. {
  93. if (!(get_user_flags(id) & ADMIN_ACCESS))
  94. {
  95. console_print(id, "You have no access.")
  96. return PLUGIN_HANDLED
  97. }
  98.  
  99. g_iEditorId = id
  100. if (rg_find_ent_by_class(-1, SAFEZONE_CLASSNAME) > 0)
  101. ShowTheZone()
  102.  
  103. ShowSafeZoneMenu(id)
  104. return PLUGIN_HANDLED
  105. }
  106.  
  107. ShowSafeZoneMenu(id)
  108. {
  109. static szMenu[250]
  110. new iLen, iEnt
  111.  
  112. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\rSafe Zone Menu^n^n")
  113. iEnt = rg_find_ent_by_class(-1, SAFEZONE_CLASSNAME)
  114.  
  115. if (iEnt > 0)
  116. {
  117. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d1. Create safe zone^n")
  118. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y2\d. \wEdit current safe zone^n")
  119. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y3\d. \wDelete current zone^n")
  120. }
  121. else
  122. {
  123. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y1\d. \wCreate safe zone^n")
  124. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d2. Edit current safe zone^n")
  125. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\d3. Delete current zone^n")
  126. }
  127.  
  128. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y4\d. \wSave all zones^n^n")
  129. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y0\d. \r%L", id, "EXIT")
  130. set_pdata_int(id, OFFSET_CSMENUCODE, 0)
  131. show_menu(id, KEYSMENU, szMenu, -1, "Safe Zone Menu")
  132. }
  133.  
  134. public MainHandler(id, key)
  135. {
  136. if (key == MENU_EXIT)
  137. {
  138. HideTheZone()
  139. return
  140. }
  141.  
  142. new iEnt = rg_find_ent_by_class(-1, SAFEZONE_CLASSNAME)
  143.  
  144. switch(key)
  145. {
  146. case 0: // Create safe zone
  147. {
  148. if (iEnt <= 0)
  149. {
  150. CreateZone(id)
  151. MainHandler(id, 1)
  152. }
  153. else
  154. {
  155. ze_colored_print(id, "There is already an existing safe zone.")
  156. ShowSafeZoneMenu(id)
  157. }
  158. }
  159. case 1: // Edit safe zone
  160. {
  161. if (iEnt > 0)
  162. {
  163. OpenEditMenu(id)
  164. ShowTheZone()
  165. }
  166. else
  167. {
  168. ze_colored_print(id, "There are no existing safe zones.")
  169. ShowSafeZoneMenu(id)
  170. }
  171. }
  172. case 2:
  173. {
  174. if (iEnt > 0)
  175. {
  176. OpenKillMenu(id)
  177. }
  178. else
  179. {
  180. ze_colored_print(id, "There are no existing safe zones.")
  181. ShowSafeZoneMenu(id)
  182. }
  183. }
  184. case 3:
  185. {
  186. if (iEnt > 0)
  187. {
  188. if (SaveZone())
  189. ze_colored_print(id, "Zone has been saved.")
  190. }
  191. else
  192. ze_colored_print(id, "There are no zones to save.")
  193.  
  194. ShowSafeZoneMenu(id)
  195. }
  196. }
  197. }
  198.  
  199. ShowTheZone()
  200. {
  201. new iEnt = rg_find_ent_by_class(-1, SAFEZONE_CLASSNAME)
  202. remove_task(TASK_BASIS_SHOWZONES + iEnt)
  203. set_entvar(iEnt, var_solid, SOLID_NOT)
  204. set_task(0.2, "ShowZoneBox", TASK_BASIS_SHOWZONES + iEnt, _, _, "b")
  205. }
  206.  
  207. public ShowZoneBox(taskid)
  208. {
  209. new iEnt = taskid - TASK_BASIS_SHOWZONES
  210.  
  211. if (!is_entity(iEnt) || g_iEditorId < 1)
  212. return
  213.  
  214. new Float:flPos[3]
  215. get_entvar(iEnt, var_origin, flPos)
  216.  
  217. if (!fm_is_in_viewcone(g_iEditorId, flPos))
  218. return
  219.  
  220. new Float:flEditorPos[3], Float:flHitPoint[3]
  221. get_entvar(g_iEditorId, var_origin, flEditorPos)
  222. fm_trace_line(-1, flEditorPos, flPos, flHitPoint)
  223.  
  224. // Line from the center of the entity to the creator of it
  225. DrawLine(flEditorPos[0], flEditorPos[1], flEditorPos[2] - 16.0, flPos[0], flPos[1], flPos[2], {255, 0, 0})
  226.  
  227. new Float:flDH = vector_distance(flEditorPos, flPos) - vector_distance(flEditorPos, flHitPoint)
  228.  
  229. if (floatabs(flDH) > 128.0)
  230. return
  231.  
  232. new Float:flMins[3], Float:flMaxs[3]
  233. get_entvar(iEnt, var_mins, flMins)
  234. get_entvar(iEnt, var_maxs, flMaxs)
  235.  
  236. for (new i = 0; i < 3; i++)
  237. {
  238. flMins[i] += flPos[i]
  239. flMaxs[i] += flPos[i]
  240. }
  241.  
  242. new color[3]
  243. color[0] = 255
  244. color[1] = 0
  245. color[2] = 255
  246.  
  247. // Sides of the created shape
  248. DrawLine(flMaxs[0], flMaxs[1], flMaxs[2], flMins[0], flMaxs[1], flMaxs[2], color)
  249. DrawLine(flMaxs[0], flMaxs[1], flMaxs[2], flMaxs[0], flMins[1], flMaxs[2], color)
  250. DrawLine(flMaxs[0], flMaxs[1], flMaxs[2], flMaxs[0], flMaxs[1], flMins[2], color)
  251. DrawLine(flMins[0], flMins[1], flMins[2], flMaxs[0], flMins[1], flMins[2], color)
  252. DrawLine(flMins[0], flMins[1], flMins[2], flMins[0], flMaxs[1], flMins[2], color)
  253. DrawLine(flMins[0], flMins[1], flMins[2], flMins[0], flMins[1], flMaxs[2], color)
  254. DrawLine(flMins[0], flMaxs[1], flMaxs[2], flMins[0], flMaxs[1], flMins[2], color)
  255. DrawLine(flMins[0], flMaxs[1], flMins[2], flMaxs[0], flMaxs[1], flMins[2], color)
  256. DrawLine(flMaxs[0], flMaxs[1], flMins[2], flMaxs[0], flMins[1], flMins[2], color)
  257. DrawLine(flMaxs[0], flMins[1], flMins[2], flMaxs[0], flMins[1], flMaxs[2], color)
  258. DrawLine(flMaxs[0], flMins[1], flMaxs[2], flMins[0], flMins[1], flMaxs[2], color)
  259. DrawLine(flMins[0], flMins[1], flMaxs[2], flMins[0], flMaxs[1], flMaxs[2], color)
  260.  
  261. // Tendon of the active coodinates
  262. switch(g_iDirection)
  263. {
  264. case 0: // X-Coordinates
  265. {
  266. DrawLine(flMaxs[0], flMaxs[1], flMaxs[2], flMaxs[0], flMins[1], flMins[2], { 255, 255, 0 })
  267. DrawLine(flMaxs[0], flMaxs[1], flMins[2], flMaxs[0], flMins[1], flMaxs[2], { 255, 255, 0 })
  268.  
  269. DrawLine(flMins[0], flMaxs[1], flMaxs[2], flMins[0], flMins[1], flMins[2], { 255, 0, 0 })
  270. DrawLine(flMins[0], flMaxs[1], flMins[2], flMins[0], flMins[1], flMaxs[2], { 255, 0, 0 })
  271. }
  272. case 1: // Y-Coordinates
  273. {
  274. DrawLine(flMins[0], flMins[1], flMins[2], flMaxs[0], flMins[1], flMaxs[2], { 255, 0, 0 })
  275. DrawLine(flMaxs[0], flMins[1], flMins[2], flMins[0], flMins[1], flMaxs[2], { 255, 0, 0 })
  276.  
  277. DrawLine(flMins[0], flMaxs[1], flMins[2], flMaxs[0], flMaxs[1], flMaxs[2], { 255, 255, 0 })
  278. DrawLine(flMaxs[0], flMaxs[1], flMins[2], flMins[0], flMaxs[1], flMaxs[2], { 255, 255, 0 })
  279. }
  280. case 2: // Z-Coordinates
  281. {
  282. DrawLine(flMaxs[0], flMaxs[1], flMaxs[2], flMins[0], flMins[1], flMaxs[2], { 255, 255, 0 })
  283. DrawLine(flMaxs[0], flMins[1], flMaxs[2], flMins[0], flMaxs[1], flMaxs[2], { 255, 255, 0 })
  284.  
  285. DrawLine(flMaxs[0], flMaxs[1], flMins[2], flMins[0], flMins[1], flMins[2], { 255, 0, 0 })
  286. DrawLine(flMaxs[0], flMins[1], flMins[2], flMins[0], flMaxs[1], flMins[2], { 255, 0, 0 })
  287. }
  288. }
  289. }
  290.  
  291. HideTheZone()
  292. {
  293. g_iEditorId = 0
  294. new iEnt = rg_find_ent_by_class(-1, SAFEZONE_CLASSNAME)
  295. remove_task(TASK_BASIS_SHOWZONES + iEnt)
  296. set_entvar(iEnt, var_solid, SOLID_TRIGGER)
  297. }
  298.  
  299. CreateZone(id)
  300. {
  301. new Float:flPos[3]
  302. get_entvar(id, var_origin, flPos)
  303. CreateNewZone(flPos)
  304. }
  305.  
  306. CreateNewZone(Float:flPos[3])
  307. {
  308. new Float:flMins[3] = { -32.0, -32.0, -32.0 }
  309. new Float:flMaxs[3] = { 32.0, 32.0, 32.0 }
  310. ShowZone(flPos, flMins, flMaxs)
  311. }
  312.  
  313. ShowZone(Float:flPos[3], Float:flMins[3], Float:flMaxs[3])
  314. {
  315. new iEnt = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
  316. set_entvar(iEnt, var_classname, SAFEZONE_CLASSNAME)
  317. set_entvar(iEnt, var_model, "models/gib_skull.mdl")
  318. set_entvar(iEnt, var_origin, flPos)
  319. set_entvar(iEnt, var_movetype, MOVETYPE_FLY)
  320. set_entvar(iEnt, var_solid, (g_iEditorId > 0) ? SOLID_NOT : SOLID_TRIGGER)
  321. engfunc(EngFunc_SetSize, iEnt, flMins, flMaxs)
  322. set_pev(iEnt, pev_effects, pev(iEnt, pev_effects) | EF_NODRAW)
  323. }
  324.  
  325. OpenEditMenu(id)
  326. {
  327. static szMenu[300]
  328. new iLen
  329.  
  330. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\rSafe Zone Menu\d:^n\rEdit current menu^n^n")
  331.  
  332. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y1\d. \wEscape time\d: \r%.1f^n", g_flEscapeTime)
  333. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y2\d. \wLess^n")
  334. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y3\d. \wMore^n")
  335.  
  336. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y4\d. \wChange size over\d: \r%s^n", szCoordsNames[g_iDirection])
  337.  
  338. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y5\d. \wStrip^n")
  339. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y6\d. \wWiden^n")
  340.  
  341. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y7\d. \wStrip^n")
  342. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y8\d. \wWiden^n")
  343.  
  344. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y9\d. \wIncreament \r%i \wunits^n^n", g_iStepUnits)
  345. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y0\d. \r%L", id, "BACK")
  346.  
  347. set_pdata_int(id, OFFSET_CSMENUCODE, 0)
  348. show_menu(id, KEYSMENU, szMenu, -1, "Edit Zone Menu")
  349. }
  350.  
  351. public EditHandler(id, key)
  352. {
  353. switch(key)
  354. {
  355. case 0: OpenEditMenu(id) // Useless
  356. case 1: // Increase escape time
  357. {
  358. g_flEscapeTime -= 1.0
  359. OpenEditMenu(id)
  360. }
  361. case 2: // Decrease escape time
  362. {
  363. g_flEscapeTime += 1.0
  364. OpenEditMenu(id)
  365. }
  366. case 3: // Change size over coordinates
  367. {
  368. g_iDirection = (g_iDirection < 2) ? g_iDirection + 1 : 0
  369. OpenEditMenu(id)
  370. }
  371. case 4: // Decrease the mins
  372. {
  373. DecreaseMins()
  374. OpenEditMenu(id)
  375. }
  376. case 5: // Increase the mins
  377. {
  378. IncreaseMins()
  379. OpenEditMenu(id)
  380. }
  381. case 6: // Decrease the maxs
  382. {
  383. DecreaseMaxs()
  384. OpenEditMenu(id)
  385. }
  386. case 7: // Increase the maxs
  387. {
  388. IncreaseMaxs()
  389. OpenEditMenu(id)
  390. }
  391. case 8: // Change unit
  392. {
  393. g_iStepUnits = (g_iStepUnits < 100) ? g_iStepUnits * 10 : 1
  394. OpenEditMenu(id)
  395. }
  396. default: // Leave
  397. {
  398. ShowSafeZoneMenu(id)
  399. }
  400. }
  401. }
  402.  
  403. DecreaseMins()
  404. {
  405. new iEnt = rg_find_ent_by_class(-1, SAFEZONE_CLASSNAME)
  406. new Float:flPos[3], Float:flMins[3], Float:flMaxs[3]
  407. get_entvar(iEnt, var_origin, flPos)
  408. get_entvar(iEnt, var_mins, flMins)
  409. get_entvar(iEnt, var_maxs, flMaxs)
  410.  
  411. if ((floatabs(flMins[g_iDirection]) + flMaxs[g_iDirection]) < g_iStepUnits + 1)
  412. return
  413.  
  414. flMins[g_iDirection] += float(g_iStepUnits) / 2.0
  415. flMaxs[g_iDirection] -= float(g_iStepUnits) / 2.0
  416. flPos[g_iDirection] += float(g_iStepUnits) / 2.0
  417.  
  418. set_entvar(iEnt, var_origin, flPos)
  419. engfunc(EngFunc_SetSize, iEnt, flMins, flMaxs)
  420. }
  421.  
  422. IncreaseMins()
  423. {
  424. new iEnt = rg_find_ent_by_class(-1, SAFEZONE_CLASSNAME)
  425. new Float:flPos[3], Float:flMins[3], Float:flMaxs[3]
  426. get_entvar(iEnt, var_origin, flPos)
  427. get_entvar(iEnt, var_mins, flMins)
  428. get_entvar(iEnt, var_maxs, flMaxs)
  429.  
  430. flPos[g_iDirection] -= float(g_iStepUnits) / 2.0
  431. flMins[g_iDirection] -= float(g_iStepUnits) / 2.0
  432. flMaxs[g_iDirection] += float(g_iStepUnits) / 2.0
  433.  
  434. set_entvar(iEnt, var_origin, flPos)
  435. engfunc(EngFunc_SetSize, iEnt, flMins, flMaxs)
  436. }
  437.  
  438. DecreaseMaxs()
  439. {
  440. new iEnt = rg_find_ent_by_class(-1, SAFEZONE_CLASSNAME)
  441. new Float:flPos[3], Float:flMins[3], Float:flMaxs[3]
  442. get_entvar(iEnt, var_origin, flPos)
  443. get_entvar(iEnt, var_mins, flMins)
  444. get_entvar(iEnt, var_maxs, flMaxs)
  445.  
  446. if ((floatabs(flMins[g_iDirection]) + flMaxs[g_iDirection]) < g_iStepUnits + 1)
  447. return
  448.  
  449. flMins[g_iDirection] += float(g_iStepUnits) / 2.0
  450. flMaxs[g_iDirection] -= float(g_iStepUnits) / 2.0
  451. flPos[g_iDirection] -= float(g_iStepUnits) / 2.0
  452.  
  453. set_entvar(iEnt, var_origin, flPos)
  454. engfunc(EngFunc_SetSize, iEnt, flMins, flMaxs)
  455. }
  456.  
  457. IncreaseMaxs()
  458. {
  459. new iEnt = rg_find_ent_by_class(-1, SAFEZONE_CLASSNAME)
  460. new Float:flPos[3], Float:flMins[3], Float:flMaxs[3]
  461. get_entvar(iEnt, var_origin, flPos)
  462. get_entvar(iEnt, var_mins, flMins)
  463. get_entvar(iEnt, var_maxs, flMaxs)
  464.  
  465. flMins[g_iDirection] -= float(g_iStepUnits) / 2.0
  466. flMaxs[g_iDirection] += float(g_iStepUnits) / 2.0
  467. flPos[g_iDirection] += float(g_iStepUnits) / 2.0
  468.  
  469. set_entvar(iEnt, var_origin, flPos)
  470. engfunc(EngFunc_SetSize, iEnt, flMins, flMaxs)
  471. }
  472.  
  473. OpenKillMenu(id)
  474. {
  475. static szMenu[300]
  476. new iLen
  477.  
  478. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\rDelete current zone\d?^n^n")
  479. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y1\d. \wYes, delete^n^n")
  480. iLen += formatex(szMenu[iLen], charsmax(szMenu) - iLen, "\y0\d. \rNo, back")
  481.  
  482. set_pdata_int(id, OFFSET_CSMENUCODE, 0)
  483. show_menu(id, KEYSMENU, szMenu, -1, "Delete Zone Menu")
  484. }
  485.  
  486. public DeleteHandler(id, key)
  487. {
  488. switch(key)
  489. {
  490. case 0: // Zone deleted
  491. {
  492. engfunc(EngFunc_RemoveEntity, rg_find_ent_by_class(-1, SAFEZONE_CLASSNAME))
  493. DeleteZone()
  494. ze_colored_print(id, "Zone has been deleted.")
  495. }
  496. case MENU_EXIT: ze_colored_print(id, "Zone has not been deleted.") // Zone not deleted
  497. }
  498.  
  499. ShowSafeZoneMenu(id)
  500. }
  501.  
  502. SaveZone()
  503. {
  504. new szConfigPath[50], szFilePath[50]
  505. get_configsdir(szConfigPath, charsmax(szConfigPath))
  506. formatex(szFilePath, charsmax(szFilePath), "%s/%s", szConfigPath, g_szSafeZoneDir)
  507.  
  508. if (!dir_exists(szFilePath))
  509. mkdir(szFilePath)
  510.  
  511. new szMapName[50], szZoneFile[100], szLine[100]
  512. get_mapname(szMapName, charsmax(szMapName))
  513. formatex(szZoneFile, charsmax(szZoneFile), "%s/%s.sz", szFilePath, szMapName)
  514.  
  515. if (file_exists(szZoneFile))
  516. delete_file(szZoneFile)
  517.  
  518. new iFileHandle = fopen(szZoneFile, "wt")
  519.  
  520. if (!iFileHandle)
  521. {
  522. set_fail_state("Couldn't open %s.", szZoneFile)
  523. return false
  524. }
  525.  
  526. new Float:flPos[3], Float:flMins[3], Float:flMaxs[3]
  527. new iEnt = rg_find_ent_by_class(-1, SAFEZONE_CLASSNAME)
  528.  
  529. get_entvar(iEnt, var_origin, flPos)
  530. get_entvar(iEnt, var_mins, flMins)
  531. get_entvar(iEnt, var_maxs, flMaxs)
  532.  
  533. formatex(szLine, charsmax(szLine),
  534. "%.1f %.1f %.1f %.0f %.0f %.0f %.0f %.0f %.0f %.1f",
  535. flPos[0], flPos[1], flPos[2],
  536. flMins[0], flMins[1], flMins[2],
  537. flMaxs[0], flMaxs[1], flMaxs[2],
  538. g_flEscapeTime)
  539. fputs(iFileHandle, szLine)
  540. fclose(iFileHandle)
  541.  
  542. return true
  543. }
  544.  
  545. LoadZone()
  546. {
  547. new szConfigPath[25], szZoneFile[40], szMapName[40]
  548. get_configsdir(szConfigPath, charsmax(szConfigPath))
  549. get_mapname(szMapName, charsmax(szMapName))
  550. formatex(szZoneFile, charsmax(szZoneFile), "%s/%s/%s.sz", szConfigPath, g_szSafeZoneDir, szMapName)
  551.  
  552. if (file_exists(szZoneFile))
  553. {
  554. new iFileHandle = fopen(szZoneFile, "rt")
  555.  
  556. if (!iFileHandle)
  557. {
  558. set_fail_state("Couldn't open %s.", szZoneFile)
  559. return
  560. }
  561.  
  562. new iLine, szLine[40], iLen,
  563. szMins[3][10], szMaxs[3][10], szPos[3][10], szEscapetime[5],
  564. Float:flPos[3], Float:flMins[3], Float:flMaxs[3]
  565.  
  566. while ((iLine = read_file(szZoneFile, iLine, szLine, charsmax(szLine)), iLen) != 0)
  567. {
  568. if (!strlen(szLine) || szLine[0] == ';')
  569. continue
  570.  
  571. parse(szLine,
  572. szPos[0], charsmax(szPos[]),
  573. szPos[1], charsmax(szPos[]),
  574. szPos[2], charsmax(szPos[]),
  575.  
  576. szMins[0], charsmax(szMins[]),
  577. szMins[1], charsmax(szMins[]),
  578. szMins[2], charsmax(szMins[]),
  579.  
  580. szMaxs[0], charsmax(szMaxs[]),
  581. szMaxs[1], charsmax(szMaxs[]),
  582. szMaxs[2], charsmax(szMaxs[]),
  583.  
  584. szEscapetime, charsmax(szEscapetime))
  585.  
  586. for (new i = 0; i < 3; i++)
  587. {
  588. flPos[i] = str_to_float(szPos[i])
  589. flMins[i] = str_to_float(szMins[i])
  590. flMaxs[i] = str_to_float(szMaxs[i])
  591. }
  592.  
  593. g_flEscapeTime = str_to_float(szEscapetime)
  594. break
  595. }
  596.  
  597. fclose(iFileHandle)
  598. }
  599. else
  600. {
  601. log_amx("No safe zones found")
  602. }
  603. }
  604.  
  605. DeleteZone()
  606. {
  607. new szConfigPath[50], szFilePath[100], szMapName[50]
  608. get_configsdir(szConfigPath, charsmax(szConfigPath))
  609. get_mapname(szMapName, charsmax(szMapName))
  610. formatex(szFilePath, charsmax(szFilePath), "%s/%s/%s.sz", szConfigPath, g_szSafeZoneDir, szMapName)
  611.  
  612. if (file_exists(szFilePath))
  613. delete_file(szFilePath)
  614. }
  615.  
  616. DrawLine(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2, color[3])
  617. {
  618. new flStart[3], flStop[3]
  619.  
  620. flStart[0] = floatround(x1)
  621. flStart[1] = floatround(y1)
  622. flStart[2] = floatround(z1)
  623.  
  624. flStop[0] = floatround(x2)
  625. flStop[1] = floatround(y2)
  626. flStop[2] = floatround(z2)
  627.  
  628. FX_Line(flStart, flStop, color)
  629. }
  630.  
  631. FX_Line(flStart[3], flStop[3], iColor[3])
  632. {
  633. message_begin(MSG_ONE_UNRELIABLE, SVC_TEMPENTITY, _, g_iEditorId)
  634. write_byte(TE_BEAMPOINTS)
  635. write_coord(flStart[0])
  636. write_coord(flStart[1])
  637. write_coord(flStart[2])
  638. write_coord(flStop[0])
  639. write_coord(flStop[1])
  640. write_coord(flStop[2])
  641. write_short(g_iSpriteDot)
  642. write_byte(1)
  643. write_byte(1)
  644. write_byte(4)
  645. write_byte(5)
  646. write_byte(0)
  647. write_byte(iColor[0])
  648. write_byte(iColor[1])
  649. write_byte(iColor[2])
  650. write_byte(200)
  651. write_byte(0)
  652. message_end()
  653. }
  654.  
  655. stock bool:fm_is_in_viewcone(iEnt, const Float:flPoint[3])
  656. {
  657. new Float:flAngles[3]
  658. get_entvar(iEnt, var_angles, flAngles)
  659. engfunc(EngFunc_MakeVectors, flAngles)
  660. global_get(glb_v_forward, flAngles)
  661. flAngles[2] = 0.0
  662.  
  663. new Float:flOrigin[3], Float:flDiff[3], Float:flNorm[3]
  664. get_entvar(iEnt, var_origin, flOrigin)
  665. xs_vec_sub(flPoint, flOrigin, flDiff)
  666. flDiff[2] = 0.0
  667. xs_vec_normalize(flDiff, flNorm)
  668.  
  669. new Float:flDot, Float:flFov
  670. flDot = xs_vec_dot(flNorm, flAngles)
  671. get_entvar(iEnt, var_fov, flFov)
  672.  
  673. if (flDot >= floatcos(flFov * M_PI / 360))
  674. return true
  675.  
  676. return false
  677. }
  678.  
  679. stock fm_trace_line(ignoreent, const Float:flStart[3], const Float:flEnd[3], Float:flRet[3])
  680. {
  681. engfunc(EngFunc_TraceLine, flStart, flEnd, ignoreent == -1 ? 1 : 0, ignoreent, 0)
  682.  
  683. new iEnt = get_tr2(0, TR_pHit)
  684. get_tr2(0, TR_vecEndPos, flRet)
  685.  
  686. return is_entity(iEnt) ? iEnt : 0
  687. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement