Advertisement
Guest User

Untitled

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