Advertisement
Guest User

Untitled

a guest
May 26th, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 122.55 KB | None | 0 0
  1. using UnityEngine;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using Oxide.Core;
  6. using Oxide.Core.Plugins;
  7. using Oxide.Game.Rust.Cui;
  8. using System.IO;
  9. using System.Reflection;
  10. using System.Text;
  11. using Oxide.Core.Libraries;
  12.  
  13. namespace Oxide.Plugins
  14. {
  15. [Info("LustyMap", "Kayzor", "1.1.19", ResourceId = 1333)]
  16. [Description("In-game Map and Minimap GUI")]
  17. public class LustyMap : RustPlugin
  18. {
  19. // System variables
  20. string mapurl = null;
  21. bool run = false;
  22. bool runningfriends = false;
  23. static bool debug = false;
  24. bool mapmode = false;
  25. bool minimap = true;
  26. bool left = true;
  27. bool compass = true;
  28. bool startopen = true;
  29. bool mapbutton = false;
  30. bool showmonuments = true;
  31. bool showcaves = true;
  32. bool showheli = true;
  33. bool showplane = true;
  34. bool showsupply = true;
  35. bool showdebris = true;
  36. bool shownames = true;
  37. bool showplayers = true;
  38. bool useurl = false;
  39. bool rustiofriends = false;
  40. bool rustio = false;
  41. bool friendapi = false;
  42. bool friendsapifriends = false;
  43. float offsetTop = 0;
  44. float offsetSide = 0;
  45. float scale = 0;
  46. int workmaxcycle = 196;
  47.  
  48. // Lists
  49. List<MapLocation> mapCustom = new List<MapLocation>();
  50. List<MapLocation> mapMonuments = new List<MapLocation>();
  51. List<ActiveEntity> activeEntities = new List<ActiveEntity>();
  52. List<string> customIamges = new List<string>();
  53.  
  54. // Dictionaries
  55. Dictionary<ulong, MapLocation> playerLocations = new Dictionary<ulong, MapLocation>();
  56.  
  57. // Text Strings
  58. string txtInvalid = null;
  59. string txtUnknown = null;
  60. string txtCmdMinimap = null;
  61. string txtCmdMode = null;
  62. string txtCmdCompass = null;
  63. string txtCmdStart = null;
  64. string txtCmdCaves = null;
  65. string txtCmdHeli = null;
  66. string txtCmdPlane = null;
  67. string txtCmdSupply = null;
  68. string txtCmdDebris = null;
  69. string txtCmdPlayers = null;
  70. string txtCmdMonuments = null;
  71. string txtCmdImages = null;
  72. string txtCmdUrl = null;
  73. string txtCmdMap = null;
  74. string txtCmdIOFriends = null;
  75. string txtCmdAPIFriends = null;
  76. string txtCmdAdmin = null;
  77. string txtCmdUseUrl = null;
  78.  
  79. string txtCmtMode = null;
  80. string txtCmdLocation = null;
  81. string txtCmdImage = null;
  82. string txtCmtMinimap = null;
  83. string txtCmtAlign = null;
  84. string txtCmtCompass = null;
  85. string txtCmtOpen = null;
  86. string txtCmtCaves = null;
  87. string txtCmtHeli = null;
  88. string txtCmtPlane = null;
  89. string txtCmtSupply = null;
  90. string txtCmtDebris = null;
  91. string txtCmtPlayers = null;
  92. string txtCmtMonuments = null;
  93. string txtCmtImages = null;
  94. string txtCmtUrl = null;
  95. string txtCmtLocation = null;
  96. string txtCmtLocationFail = null;
  97. string txtCmtImage = null;
  98. string txtCmtImageFail = null;
  99. string txtCmtIOFriends = null;
  100. string txtCmtAPIFriends = null;
  101. string txtCmtAdmin = null;
  102. string txtCmtUseUrl = null;
  103.  
  104. string txtCpsHead = null;
  105. string txtCpsN = null;
  106. string txtCpsNE = null;
  107. string txtCpsE = null;
  108. string txtCpsSE = null;
  109. string txtCpsS = null;
  110. string txtCpsSW = null;
  111. string txtCpsW = null;
  112. string txtCpsNW = null;
  113. string txtBtnClose = null;
  114. string txtBtnMap = null;
  115.  
  116. string txtMonLight = null;
  117. string txtMonCave = null;
  118. string txtMonWare = null;
  119. string txtMonDish = null;
  120. string txtMonTank = null;
  121. string txtMonPower = null;
  122. string txtMonTrain = null;
  123. string txtMonAir = null;
  124. string txtMonTunnel = null;
  125. string txtMonWater = null;
  126. string txtMonRad = null;
  127.  
  128. private float mapSize;
  129.  
  130. // RustIO Support
  131. private Library RustIOLib;
  132. private MethodInfo isRustIOInstalled;
  133. private MethodInfo hasRustIOFriend;
  134.  
  135. private void InitializeRustIO()
  136. {
  137. RustIOLib = Interface.GetMod().GetLibrary<Library>("RustIO");
  138. if (RustIOLib == null || (isRustIOInstalled = RustIOLib.GetFunction("IsInstalled")) == null || (hasRustIOFriend = RustIOLib.GetFunction("HasFriend")) == null)
  139. {
  140. RustIOLib = null;
  141. }
  142.  
  143. if (IsRustIOInstalled())
  144. {
  145. rustio = true;
  146. if (debug) { Puts("Rust:IO detected!"); }
  147. }
  148. else
  149. {
  150. rustio = false;
  151. if (debug) { Puts("Rust:IO not detected..."); }
  152. }
  153. }
  154.  
  155. private bool IsRustIOInstalled()
  156. {
  157. if (RustIOLib == null) return false;
  158. return (bool)isRustIOInstalled.Invoke(RustIOLib, new object[] { });
  159. }
  160.  
  161. private bool HasRustIOFriend(string playerId, string friendId)
  162. {
  163. if (RustIOLib == null) return false;
  164. return (bool)hasRustIOFriend.Invoke(RustIOLib, new object[] { playerId, friendId });
  165. }
  166.  
  167. // Friends API Support
  168. [PluginReference]
  169. private Plugin Friends;
  170.  
  171. private void InitializeFriendsAPI()
  172. {
  173. if (Friends != null)
  174. {
  175. friendapi = true;
  176. if (debug) { Puts("FriendsAPI detected!"); }
  177. }
  178. else
  179. {
  180. friendapi = false;
  181. if (debug) { Puts("FriendsAPI not detected..."); }
  182. }
  183. }
  184.  
  185. private bool AreFriendsAPIFriend(string playerId, string friendId)
  186. {
  187. try
  188. {
  189. bool result = (bool)Friends?.CallHook("AreFriends", playerId, friendId);
  190. return result;
  191. }
  192. catch
  193. {
  194. return false;
  195. }
  196. }
  197.  
  198. // Plugin Setup
  199. void Loaded()
  200. {
  201. // Default config values
  202. set("LustyMap", "MapURL", "", false);
  203. set("LustyMap", "MapMode", false, false);
  204. set("LustyMap", "Minimap", true, false);
  205. set("LustyMap", "Left", true, false);
  206. set("LustyMap", "Compass", true, false);
  207. set("LustyMap", "StartOpen", true, false);
  208. set("LustyMap", "Debug", false, false);
  209. set("LustyMap", "MapButton", false, false);
  210. set("LustyMap", "ShowMonuments", true, false);
  211. set("LustyMap", "ShowCaves", true, false);
  212. set("LustyMap", "ShowHeli", true, false);
  213. set("LustyMap", "ShowPlane", true, false);
  214. set("LustyMap", "ShowSupply", true, false);
  215. set("LustyMap", "ShowDebris", true, false);
  216. set("LustyMap", "ShowPlayers", true, false);
  217. set("LustyMap", "RustIOFriends", false, false);
  218. set("LustyMap", "FriendsAPIFriends", false, false);
  219. set("LustyMap", "UseURL", false, false);
  220.  
  221. set("Performance", "WorkPerCycle", workmaxcycle, false);
  222.  
  223. // Offset
  224. set("Minimap", "OffsetTop", 0, false);
  225. set("Minimap", "OffsetSide", 0, false);
  226. set("Minimap", "Scale", 1, false);
  227.  
  228. // Overwrite some settings on first use
  229. set("FirstUse", "1.1.12", true, false);
  230. if (Convert.ToBoolean(get("FirstUse", "1.1.12")))
  231. {
  232. set("LustyMap", "UseURL", true);
  233. set("FirstUse", "1.1.12", false, true);
  234. }
  235.  
  236. // Default/English text strings
  237. set("TextStrings", "InvalidSyntex", "Invalid syntex! usage: ", false);
  238. set("TextStrings", "UnknownCommand", "Unknown command, type <color=#00ff00ff>/map help</color> for a list of commands.", false);
  239. set("TextStrings", "MinimapCommand", "<color=#00ff00ff>/map minimap <true|false|left|right></color> - Enables, disables or sets the default alignment for the minimap.", false);
  240. set("TextStrings", "ModeCommand", "<color=#00ff00ff>/map mode <true|false></color> - Enables or disables complex mode.", false);
  241. set("TextStrings", "CompassCommand", "<color=#00ff00ff>/map compass <true|false></color> - Enables or disables the minimap compass.", false);
  242. set("TextStrings", "StartCommand", "<color=#00ff00ff>/map startopen <true|false></color> - Sets the default state for the minimap.", false);
  243. set("TextStrings", "CavesCommand", "<color=#00ff00ff>/map showcaves <true|false></color> - Enables or disables Caves from showing on the map.", false);
  244. set("TextStrings", "MonumentsCommand", "<color=#00ff00ff>/map showmonuments <true|false></color> - Enables or disables Monuments from showing on the map.", false);
  245. set("TextStrings", "ImagesCommand", "<color=#00ff00ff>/map images</color> - Reloads the Image cache.", false);
  246. set("TextStrings", "UrlCommand", "<color=#00ff00ff>/map url <url to map image></color> - Sets the map image, used as the background image.", false);
  247. set("TextStrings", "UseUrlCommand", "<color=#00ff00ff>/map useurl <true|false></color> - Enables or disables the map image from downloaded from the MapURL insead of loading from Data folder.", false);
  248. set("TextStrings", "PlaneCommand", "<color=#00ff00ff>/map showplane <true|false></color> - Enables or disables Airplanes from showing on the map.", false);
  249. set("TextStrings", "HeliCommand", "<color=#00ff00ff>/map showheli <true|false></color> - Enables or disables Helicopters from showing on the map.", false);
  250. set("TextStrings", "SupplyCommand", "<color=#00ff00ff>/map showsupply <true|false></color> - Enables or disables Supply Drops from showing on the map.", false);
  251. set("TextStrings", "DebrisCommand", "<color=#00ff00ff>/map showdebris <true|false></color> - Enables or disables Helicopter Debris from showing on the map.", false);
  252. set("TextStrings", "PlayersCommand", "<color=#00ff00ff>/map showplayers <true|false></color> - Enables or disables Players from showing on the map.", false);
  253. set("TextStrings", "LocationCommand", "<color=#00ff00ff>/map <add|remove> <name> (optional)<image name></color> - Adds|Removes a location from the map, (optional)using a custom image.", false);
  254. set("TextStrings", "ImageCommand", "<color=#00ff00ff>/map <addimage|removeimage> <name></color> - Adds a custom image which can be used with a custom map location.", false);
  255. set("TextStrings", "MapCommand", "<color=#00ff00ff>/map</color> has been <color=#00ff00ff>removed</color>, Please use keybind <color=#00ff00ff>M</color> to toggle the map instead.", false);
  256. set("TextStrings", "RustIOFriendsCommand", "<color=#00ff00ff>/map rustiofriends <true|false></color> - Enables or disables RustIO Friends displaying on the map and minimap for players.", false);
  257. set("TextStrings", "FriendsAPIFriendsCommand", "<color=#00ff00ff>/map friendsapifriends <true|false></color> - Enables or disables FriendsAPI Friends displaying on the map and minimap for players.", false);
  258. set("TextStrings", "AdminViewCommand", "<color=#00ff00ff>/map adminview</color> - Toggles Admin View for the map and minimap.", false);
  259.  
  260. set("TextStrings", "ModeCommit", "Complex mode has been <color=#00ff00ff>{0}</color>.", false);
  261. set("TextStrings", "MinimapCommit", "Minimap has been <color=#00ff00ff>{0}</color> for all players.", false);
  262. set("TextStrings", "AlignCommit", "Minimap has been set to the <color=#00ff00ff>{0}</color>.", false);
  263. set("TextStrings", "CompassCommit", "Minimap compass has been <color=#00ff00ff>{0}</color>.", false);
  264. set("TextStrings", "OpenCommit", "Minimap will be <color=#00ff00ff>{0}</color> by default.", false);
  265. set("TextStrings", "CavesCommit", "Showing Caves has been <color=#00ff00ff>{0}</color>.", false);
  266. set("TextStrings", "PlaneCommit", "Showing Airplanes has been <color=#00ff00ff>{0}</color>.", false);
  267. set("TextStrings", "HeliCommit", "Showing Helicopters has been <color=#00ff00ff>{0}</color>.", false);
  268. set("TextStrings", "SupplyCommit", "Showing Supply Drops has been <color=#00ff00ff>{0}</color>.", false);
  269. set("TextStrings", "DebrisCommit", "Showing Helicopter Debris has been <color=#00ff00ff>{0}</color>.", false);
  270. set("TextStrings", "PlayersCommit", "Showing Players has been <color=#00ff00ff>{0}</color>.", false);
  271. set("TextStrings", "MonumentsCommit", "Showing Monuments has been <color=#00ff00ff>{0}</color>.", false);
  272. set("TextStrings", "ImagesCommit", "Reloading the Image cache.", false);
  273. set("TextStrings", "UrlCommit", "Map URL has been set to: <color=#00ff00ff>{0}</color>", false);
  274. set("TextStrings", "UseUrlCommit", "Map URL mode has been <color=#00ff00ff>{0}</color>.", false);
  275. set("TextStrings", "RustIOFriendsCommit", "RustIO Friends has been <color=#00ff00ff>{0}</color>.", false);
  276. set("TextStrings", "FriendsAPIFriendsCommit", "FriendsAPI Friends has been <color=#00ff00ff>{0}</color>.", false);
  277. set("TextStrings", "AdminViewCommit", "Admin View has been <color=#00ff00ff>{0}</color>.", false);
  278.  
  279. set("TextStrings", "CloseButton", "Close Map", false);
  280. set("TextStrings", "MapButton", "Map", false);
  281.  
  282. set("CompassStrings", "Head", "Heading:", false);
  283. set("CompassStrings", "N", "North", false);
  284. set("CompassStrings", "NE", "North East", false);
  285. set("CompassStrings", "E", "East", false);
  286. set("CompassStrings", "SE", "South East", false);
  287. set("CompassStrings", "S", "South", false);
  288. set("CompassStrings", "SW", "South West", false);
  289. set("CompassStrings", "W", "West", false);
  290. set("CompassStrings", "NW", "North West", false);
  291.  
  292. set("MonumentStrings", "Lighthouse", "Lighthouse", false);
  293. set("MonumentStrings", "Cave", "Cave", false);
  294. set("MonumentStrings", "Warehouse", "Warehouse", false);
  295. set("MonumentStrings", "Dish", "Satellite Dish", false);
  296. set("MonumentStrings", "Sphere", "Sphere Tank", false);
  297. set("MonumentStrings", "Powerplant", "Powerplant", false);
  298. set("MonumentStrings", "Trainyard", "Trainyard", false);
  299. set("MonumentStrings", "Airfield", "Airfield", false);
  300. set("MonumentStrings", "Tunnel", "Military Tunnel", false);
  301. set("MonumentStrings", "Waterplant", "Water Treatment Plant", false);
  302. set("MonumentStrings", "Radtown", "Radtown", false);
  303.  
  304. // Load config values
  305. mapmode = Convert.ToBoolean(get("LustyMap", "MapMode"));
  306. minimap = Convert.ToBoolean(get("LustyMap", "Minimap"));
  307. left = Convert.ToBoolean(get("LustyMap", "Left"));
  308. compass = Convert.ToBoolean(get("LustyMap", "Compass"));
  309. startopen = Convert.ToBoolean(get("LustyMap", "StartOpen"));
  310. debug = Convert.ToBoolean(get("LustyMap", "Debug"));
  311. mapbutton = Convert.ToBoolean(get("LustyMap", "MapButton"));
  312. showmonuments = Convert.ToBoolean(get("LustyMap", "ShowMonuments"));
  313. showcaves = Convert.ToBoolean(get("LustyMap", "ShowCaves"));
  314. showheli = Convert.ToBoolean(get("LustyMap", "ShowHeli"));
  315. showplane = Convert.ToBoolean(get("LustyMap", "ShowPlane"));
  316. showsupply = Convert.ToBoolean(get("LustyMap", "ShowSupply"));
  317. showdebris = Convert.ToBoolean(get("LustyMap", "ShowDebris"));
  318. showplayers = Convert.ToBoolean(get("LustyMap", "ShowPlayers"));
  319. useurl = Convert.ToBoolean(get("LustyMap", "UseURL"));
  320. mapurl = Convert.ToString(get("LustyMap", "MapURL"));
  321. rustiofriends = Convert.ToBoolean(get("LustyMap", "RustIOFriends"));
  322. friendsapifriends = Convert.ToBoolean(get("LustyMap", "FriendsAPIFriends"));
  323.  
  324. workmaxcycle = Convert.ToInt16(get("Performance", "WorkPerCycle"));
  325.  
  326. offsetTop = Convert.ToSingle(get("Minimap", "OffsetTop"));
  327. offsetSide = Convert.ToSingle(get("Minimap", "OffsetSide"));
  328. scale = Convert.ToSingle(get("Minimap", "Scale"));
  329.  
  330. // Text strings
  331. txtInvalid = (string)get("TextStrings", "InvalidSyntex");
  332. txtUnknown = (string)get("TextStrings", "UnknownCommand");
  333. txtCmdMinimap = (string)get("TextStrings", "MinimapCommand");
  334. txtCmdMode = (string)get("TextStrings", "ModeCommand");
  335. txtCmdCompass = (string)get("TextStrings", "CompassCommand");
  336. txtCmdStart = (string)get("TextStrings", "StartCommand");
  337. txtCmdCaves = (string)get("TextStrings", "CavesCommand");
  338. txtCmdPlane = (string)get("TextStrings", "PlaneCommand");
  339. txtCmdHeli = (string)get("TextStrings", "HeliCommand");
  340. txtCmdSupply = (string)get("TextStrings", "SupplyCommand");
  341. txtCmdDebris = (string)get("TextStrings", "DebrisCommand");
  342. txtCmdPlayers = (string)get("TextStrings", "PlayersCommand");
  343. txtCmdMonuments = (string)get("TextStrings", "MonumentsCommand");
  344. txtCmdImages = (string)get("TextStrings", "ImagesCommand");
  345. txtCmdImage = (string)get("TextStrings", "ImageCommand");
  346. txtCmdLocation = (string)get("TextStrings", "LocationCommand");
  347. txtCmdUrl = (string)get("TextStrings", "UrlCommand");
  348. txtCmdUseUrl = (string)get("TextStrings", "UseUrlCommand");
  349. txtCmdMap = (string)get("TextStrings", "MapCommand");
  350. txtCmdIOFriends = (string)get("TextStrings", "RustIOFriendsCommand");
  351. txtCmdAPIFriends = (string)get("TextStrings", "FriendsAPIFriendsCommand");
  352. txtCmdAdmin = (string)get("TextStrings", "AdminViewCommand");
  353.  
  354. txtCmtMode = (string)get("TextStrings", "ModeCommit");
  355. txtCmtMinimap = (string)get("TextStrings", "MinimapCommit");
  356. txtCmtAlign = (string)get("TextStrings", "AlignCommit");
  357. txtCmtCompass = (string)get("TextStrings", "CompassCommit");
  358. txtCmtOpen = (string)get("TextStrings", "OpenCommit");
  359. txtCmtCaves = (string)get("TextStrings", "CavesCommit");
  360. txtCmtPlane = (string)get("TextStrings", "PlaneCommit");
  361. txtCmtHeli = (string)get("TextStrings", "HeliCommit");
  362. txtCmtSupply = (string)get("TextStrings", "SupplyCommit");
  363. txtCmtDebris = (string)get("TextStrings", "DebrisCommit");
  364. txtCmtPlayers = (string)get("TextStrings", "PlayersCommit");
  365. txtCmtMonuments = (string)get("TextStrings", "MonumentsCommit");
  366. txtCmtImages = (string)get("TextStrings", "ImagesCommit");
  367. txtCmtUrl = (string)get("TextStrings", "UrlCommit");
  368. txtCmtUseUrl = (string)get("TextStrings", "UseUrlCommit");
  369. txtCmtIOFriends = (string)get("TextStrings", "RustIOFriendsCommit");
  370. txtCmtAPIFriends = (string)get("TextStrings", "FriendsAPIFriendsCommit");
  371. txtCmtAdmin = (string)get("TextStrings", "AdminViewCommit");
  372.  
  373. txtBtnClose = (string)get("TextStrings", "CloseButton");
  374. txtBtnMap = (string)get("TextStrings", "MapButton");
  375.  
  376. txtCpsHead = (string)get("CompassStrings", "Head");
  377. txtCpsN = (string)get("CompassStrings", "N");
  378. txtCpsNE = (string)get("CompassStrings", "NE");
  379. txtCpsE = (string)get("CompassStrings", "E");
  380. txtCpsSE = (string)get("CompassStrings", "SE");
  381. txtCpsS = (string)get("CompassStrings", "S");
  382. txtCpsSW = (string)get("CompassStrings", "SW");
  383. txtCpsW = (string)get("CompassStrings", "W");
  384. txtCpsNW = (string)get("CompassStrings", "NW");
  385.  
  386. txtMonLight = (string)get("MonumentStrings", "Lighthouse");
  387. txtMonCave = (string)get("MonumentStrings", "Cave");
  388. txtMonWare = (string)get("MonumentStrings", "Warehouse");
  389. txtMonDish = (string)get("MonumentStrings", "Dish");
  390. txtMonTank = (string)get("MonumentStrings", "Sphere");
  391. txtMonPower = (string)get("MonumentStrings", "Powerplant");
  392. txtMonTrain = (string)get("MonumentStrings", "Trainyard");
  393. txtMonAir = (string)get("MonumentStrings", "Airfield");
  394. txtMonTunnel = (string)get("MonumentStrings", "Tunnel");
  395. txtMonWater = (string)get("MonumentStrings", "Waterplant");
  396. txtMonRad = (string)get("MonumentStrings", "Radtown");
  397.  
  398. // Load custom lists
  399. customIamges = Interface.Oxide.DataFileSystem.ReadObject<List<string>>("LustyMapImages");
  400. mapCustom = Interface.Oxide.DataFileSystem.ReadObject<List<MapLocation>>("LustyMapLocations");
  401. }
  402.  
  403. // Monuments
  404. private class MapLocation
  405. {
  406. public string name { get; set; }
  407. public double percentX { get; set; }
  408. public double percentZ { get; set; }
  409. public string icon { get; set; }
  410. }
  411.  
  412. void OnServerInitialized()
  413. {
  414. mapSize = TerrainMeta.Size.x;
  415. var monumentInfos = UnityEngine.Object.FindObjectsOfType<MonumentInfo>();
  416. if (debug) { Puts($"Found {monumentInfos.Length} monuments on the map."); }
  417. foreach (var monumentInfo in monumentInfos)
  418. {
  419. MapLocation monument = new MapLocation
  420. {
  421. percentX = GetMapPos(monumentInfo.transform.position.x),
  422. percentZ = GetMapPos(monumentInfo.transform.position.z)
  423. };
  424.  
  425. if (monumentInfo.Type == MonumentType.Lighthouse)
  426. {
  427. monument.name = txtMonLight;
  428. monument.icon = "lighthouse";
  429. mapMonuments.Add(monument);
  430. }
  431. else if (monumentInfo.Type == MonumentType.Cave)
  432. {
  433. monument.name = txtMonCave;
  434. monument.icon = "cave";
  435. mapMonuments.Add(monument);
  436. }
  437. else if (monumentInfo.name.ToLower().Contains("warehouse"))
  438. {
  439. monument.name = txtMonWare;
  440. monument.icon = "warehouse";
  441. mapMonuments.Add(monument);
  442. }
  443. else if (monumentInfo.name.ToLower().Contains("satellite"))
  444. {
  445. monument.name = txtMonDish;
  446. monument.icon = "dish";
  447. mapMonuments.Add(monument);
  448. }
  449. else if (monumentInfo.name.ToLower().Contains("sphere"))
  450. {
  451. monument.name = txtMonTank;
  452. monument.icon = "spheretank";
  453. mapMonuments.Add(monument);
  454. }
  455. else if (monumentInfo.name.ToLower().Contains("powerplant"))
  456. {
  457. monument.name = txtMonPower;
  458. monument.icon = "special";
  459. mapMonuments.Add(monument);
  460. }
  461. else if (monumentInfo.name.ToLower().Contains("trainyard"))
  462. {
  463. monument.name = txtMonTrain;
  464. monument.icon = "special";
  465. mapMonuments.Add(monument);
  466. }
  467. else if (monumentInfo.name.ToLower().Contains("airfield"))
  468. {
  469. monument.name = txtMonAir;
  470. monument.icon = "special";
  471. mapMonuments.Add(monument);
  472. }
  473. else if (monumentInfo.name.ToLower().Contains("tunnel"))
  474. {
  475. monument.name = txtMonTunnel;
  476. monument.icon = "special";
  477. mapMonuments.Add(monument);
  478. }
  479. else if (monumentInfo.name.ToLower().Contains("treatment"))
  480. {
  481. monument.name = txtMonWater;
  482. monument.icon = "special";
  483. mapMonuments.Add(monument);
  484. }
  485. else if (monumentInfo.Type == MonumentType.Radtown)
  486. {
  487. monument.name = txtMonRad;
  488. monument.icon = "radtown";
  489. mapMonuments.Add(monument);
  490. }
  491. else if (monumentInfo.name.ToLower().Contains("monuments"))
  492. {
  493. }
  494. else
  495. {
  496. // Missed one!
  497. if (debug) { Puts("Missed monument " + monumentInfo.name.ToLower()); }
  498. }
  499. }
  500.  
  501. CargoPlane[] planes = UnityEngine.Object.FindObjectsOfType<CargoPlane>();
  502. if (planes.Length > 0)
  503. {
  504. foreach (CargoPlane entity in planes)
  505. {
  506. addActive(entity);
  507. }
  508. }
  509. BaseHelicopter[] heli = UnityEngine.Object.FindObjectsOfType<BaseHelicopter>();
  510. if (heli.Length > 0)
  511. {
  512. foreach (BaseHelicopter entity in heli)
  513. {
  514. addActive(entity);
  515. }
  516. }
  517. SupplyDrop[] supply = UnityEngine.Object.FindObjectsOfType<SupplyDrop>();
  518. if (supply.Length > 0)
  519. {
  520. foreach (SupplyDrop entity in supply)
  521. {
  522. addActive(entity);
  523. }
  524. }
  525. HelicopterDebris[] debris = UnityEngine.Object.FindObjectsOfType<HelicopterDebris>();
  526. if (debris.Length > 0)
  527. {
  528. foreach (HelicopterDebris entity in debris)
  529. {
  530. addActive(entity);
  531. }
  532. }
  533.  
  534. // Check for RustIO (need a delay to allow RustIO to start)
  535. InitializeRustIO();
  536. timer.Once(30f, InitializeRustIO);
  537.  
  538. // Check for FriendsAPI
  539. InitializeFriendsAPI();
  540.  
  541. // Download Images
  542. cacheImages();
  543. }
  544.  
  545. private double GetMapPos(float pos)
  546. {
  547. return (pos + mapSize / 2.0) / mapSize;
  548. }
  549.  
  550. // Custom map locations
  551. bool addLocation(BasePlayer player, string name, string icon = "special")
  552. {
  553. if (mapCustom.Find(r => string.Equals(r.name, name, StringComparison.CurrentCultureIgnoreCase)) == null)
  554. {
  555. MapLocation location = new MapLocation
  556. {
  557. name = name,
  558. icon = icon,
  559. percentX = GetMapPos(player.transform.position.x),
  560. percentZ = GetMapPos(player.transform.position.z)
  561. };
  562.  
  563. // Add to list
  564. mapCustom.Add(location);
  565. Interface.Oxide.DataFileSystem.WriteObject("LustyMapLocations", mapCustom);
  566. return true;
  567. }
  568. return false;
  569. }
  570.  
  571. bool removeLocation(string name)
  572. {
  573. var loc = mapCustom.Find(r => string.Equals(r.name, name, StringComparison.CurrentCultureIgnoreCase));
  574. if (loc != null)
  575. {
  576. mapCustom.Remove(loc);
  577. Interface.Oxide.DataFileSystem.WriteObject("LustyMapLocations", mapCustom);
  578. return true;
  579. }
  580. return false;
  581. }
  582.  
  583.  
  584. // Planes and Helicopters!
  585. class ActiveEntity
  586. {
  587. public long ID { get; set; }
  588. public bool isplane { get; set; }
  589. public bool isheli { get; set; }
  590. public bool issupply { get; set; }
  591. public bool isdebris { get; set; }
  592. public BaseEntity entity { get; set; }
  593.  
  594. public string name { get; set; }
  595. public Vector3 position { get; set; }
  596. public double percentX { get; set; }
  597. public double percentZ { get; set; }
  598. public int row { get; set; }
  599. public int column { get; set; }
  600. public string icon { get; set; }
  601. }
  602.  
  603. void OnEntitySpawned(BaseEntity entity)
  604. {
  605. addActive(entity);
  606. }
  607.  
  608. void addActive(BaseEntity entity)
  609. {
  610. if (!(entity is CargoPlane) && !(entity is SupplyDrop) && !(entity is BaseHelicopter) && !(entity is HelicopterDebris)) return;
  611.  
  612. ActiveEntity activeEntity = new ActiveEntity
  613. {
  614. ID = DateTime.Now.Ticks,
  615. isplane = false,
  616. isheli = false,
  617. issupply = false,
  618. isdebris = false,
  619. entity = entity
  620. };
  621.  
  622. if (entity is CargoPlane)
  623. {
  624. activeEntity.isplane = true;
  625. activeEntity.name = "Plane";
  626. locationActive(activeEntity);
  627. activeEntities.Add(activeEntity);
  628. }
  629. else if (entity is BaseHelicopter)
  630. {
  631. activeEntity.isheli = true;
  632. activeEntity.name = "Helicopter";
  633. locationActive(activeEntity);
  634. activeEntities.Add(activeEntity);
  635. }
  636. else if (entity is SupplyDrop)
  637. {
  638. activeEntity.issupply = true;
  639. activeEntity.name = "Supply Drop";
  640. locationActive(activeEntity);
  641. activeEntities.Add(activeEntity);
  642. }
  643. else if (entity is HelicopterDebris)
  644. {
  645. activeEntity.isdebris = true;
  646. activeEntity.name = "Helicopter Debris";
  647. locationActive(activeEntity);
  648. activeEntities.Add(activeEntity);
  649. }
  650. }
  651.  
  652. int directionEntity(double rotation)
  653. {
  654. return (int)((rotation - 5) / 10 + 0.5) * 10;
  655. }
  656.  
  657. void locationActive(ActiveEntity activeEntity)
  658. {
  659. try
  660. {
  661. activeEntity.position = activeEntity.entity.transform.position;
  662. activeEntity.percentX = GetMapPos(activeEntity.position.x);
  663. activeEntity.percentZ = GetMapPos(activeEntity.position.z);
  664.  
  665. if (activeEntity.isplane)
  666. {
  667. activeEntity.icon = "plane" + directionEntity(activeEntity.entity.transform.rotation.eulerAngles.y);
  668. }
  669. else if (activeEntity.isheli)
  670. {
  671. activeEntity.icon = "heli" + directionEntity(activeEntity.entity.transform.rotation.eulerAngles.y);
  672. }
  673. else if (activeEntity.issupply)
  674. {
  675. activeEntity.icon = "supply";
  676. }
  677. else if (activeEntity.isdebris)
  678. {
  679. activeEntity.icon = "debris";
  680. }
  681. }
  682. catch
  683. {
  684. if (debug) { Puts("Removing Entity: " + activeEntity.name); }
  685. activeEntities.Remove(activeEntity);
  686. }
  687. }
  688.  
  689. void checkActive()
  690. {
  691. if (activeEntities.Count > 0)
  692. {
  693. for (int i = activeEntities.Count - 1; i >= 0; i--)
  694. {
  695. locationActive(activeEntities[i]);
  696. }
  697. }
  698. }
  699.  
  700. // Download Images
  701. ImageCache ImageAssets;
  702. GameObject LustyObject;
  703.  
  704. private void cacheImages()
  705. {
  706. // Disable map updates while downloading images...
  707. run = false;
  708.  
  709. // Initialize image cache
  710. LustyObject = new GameObject();
  711. ImageAssets = LustyObject.AddComponent<ImageCache>();
  712. ImageAssets.imageFiles.Clear();
  713.  
  714. // Icons
  715. if (debug) { Puts("Downloading images..."); }
  716. string dataDirectory = "file://" + Interface.Oxide.DataDirectory + Path.DirectorySeparatorChar + "LustyMap" + Path.DirectorySeparatorChar;
  717.  
  718. List<string> files = new List<string>()
  719. {
  720. "self",
  721. "friend",
  722. "other",
  723. "heli",
  724. "plane"
  725. };
  726.  
  727. foreach (string file in files)
  728. {
  729. string path = dataDirectory + "icons" + Path.DirectorySeparatorChar;
  730. string ext = ".png";
  731.  
  732. for (int i = 0; i <= 360; i = i + 10)
  733. {
  734. ImageAssets.getImage(file + i, path + file + i + ext);
  735. }
  736. }
  737.  
  738. ImageAssets.getImage("lighthouse", dataDirectory + "icons" + Path.DirectorySeparatorChar + "lighthouse.png");
  739. ImageAssets.getImage("radtown", dataDirectory + "icons" + Path.DirectorySeparatorChar + "radtown.png");
  740. ImageAssets.getImage("cave", dataDirectory + "icons" + Path.DirectorySeparatorChar + "cave.png");
  741. ImageAssets.getImage("warehouse", dataDirectory + "icons" + Path.DirectorySeparatorChar + "warehouse.png");
  742. ImageAssets.getImage("dish", dataDirectory + "icons" + Path.DirectorySeparatorChar + "dish.png");
  743. ImageAssets.getImage("spheretank", dataDirectory + "icons" + Path.DirectorySeparatorChar + "spheretank.png");
  744. ImageAssets.getImage("special", dataDirectory + "icons" + Path.DirectorySeparatorChar + "special.png");
  745. ImageAssets.getImage("supply", dataDirectory + "icons" + Path.DirectorySeparatorChar + "supply.png");
  746. ImageAssets.getImage("debris", dataDirectory + "icons" + Path.DirectorySeparatorChar + "debris.png");
  747.  
  748. // Other
  749. ImageAssets.getImage("mapbg", dataDirectory + "other" + Path.DirectorySeparatorChar + "mapbg.jpg");
  750.  
  751. // Map - TODO: Add option to auto detect RustIO address and download map
  752. if (useurl)
  753. {
  754. ImageAssets.getImage("mapimage", mapurl);
  755. }
  756. else
  757. {
  758. ImageAssets.getImage("mapimage", dataDirectory + "map.jpg");
  759. }
  760.  
  761. if (mapmode)
  762. {
  763. List<int> minmaps = new List<int>() { 32, 26, 12, 6 };
  764.  
  765. foreach (int minisize in minmaps)
  766. {
  767. for (int i = 0; i < minisize; i++)
  768. {
  769. for (int j = 0; j < minisize; j++)
  770. {
  771. ImageAssets.getImage("map-" + minisize + "-" + i + "-" + j, dataDirectory + "map" + minisize + "x" + minisize + Path.DirectorySeparatorChar + "map-" + i + "-" + j + ".jpeg");
  772. }
  773. }
  774. }
  775. }
  776.  
  777. foreach (string image in customIamges)
  778. {
  779. ImageAssets.getImage(image, dataDirectory + "custom" + Path.DirectorySeparatorChar + image + ".png");
  780. }
  781.  
  782. // Wait for downloads to complete...
  783. download();
  784. }
  785.  
  786.  
  787. // Image cache class
  788. public class ImageCache : MonoBehaviour
  789. {
  790. public Dictionary<string, string> imageFiles = new Dictionary<string, string>();
  791.  
  792. public int downloading = 0;
  793. public List<Queue> queued = new List<Queue>();
  794.  
  795. public class Queue
  796. {
  797. public string url { get; set; }
  798. public string name { get; set; }
  799. }
  800.  
  801. private void OnDestroy()
  802. {
  803. foreach (var value in imageFiles.Values)
  804. {
  805. FileStorage.server.RemoveEntityNum(uint.MaxValue, Convert.ToUInt32(value));
  806. }
  807. }
  808.  
  809. public void getImage(string name, string url)
  810. {
  811. if (imageFiles.ContainsKey(name))
  812. {
  813. if (LustyMap.debug)
  814. {
  815. Debug.Log("Error, duplicate image: " + name);
  816. }
  817. return;
  818. }
  819. // Queue download (too many connections at once causes errors), call the process function to initiate download...
  820. queued.Add(new Queue
  821. {
  822. url = url,
  823. name = name
  824. });
  825. }
  826.  
  827. IEnumerator WaitForRequest(Queue queue)
  828. {
  829. using (var www = new WWW(queue.url))
  830. {
  831. yield return www;
  832. // check for errors
  833. if (string.IsNullOrEmpty(www.error))
  834. {
  835. imageFiles.Add(queue.name, FileStorage.server.Store(www.bytes, FileStorage.Type.png, uint.MaxValue).ToString());
  836. downloading--;
  837. }
  838. else
  839. {
  840. if (LustyMap.debug)
  841. {
  842. Debug.Log("Error downloading: " + queue.name + " - " + www.error);
  843. }
  844. downloading--;
  845. }
  846. }
  847. }
  848.  
  849. public void process()
  850. {
  851. // Limit the number of simultaneous downloads...
  852. if (downloading < 100)
  853. {
  854. if (queued.Count > 0)
  855. {
  856. downloading++;
  857. StartCoroutine(WaitForRequest(queued[0]));
  858. queued.RemoveAt(0);
  859. }
  860. }
  861. }
  862. }
  863.  
  864. public string fetchImage(string name)
  865. {
  866. string result;
  867. if (ImageAssets.imageFiles.TryGetValue(name, out result))
  868. return result;
  869. if (debug) { Puts("[fetchImage]: error: " + name); }
  870. return string.Empty;
  871. }
  872.  
  873. // Called after cacheImages
  874. int wait = 0;
  875. void download()
  876. {
  877. // Keep processing downloads until complete...
  878. if (ImageAssets.queued.Count > 0 || ImageAssets.downloading > 0)
  879. {
  880. for (int i = 0; i < 150; i++)
  881. {
  882. ImageAssets.process();
  883. }
  884. timer.Once(0.1f, download);
  885.  
  886. wait++;
  887. if (wait > 100) { if (debug) { Puts("[ImageAsset]: " + ImageAssets.queued.Count + " Queued, " + ImageAssets.downloading + " Downloading..."); wait = 0; } }
  888. }
  889. else
  890. {
  891. if (debug) { Puts("Downloaded " + ImageAssets.imageFiles.Count + " images."); }
  892. StartUp();
  893. }
  894. }
  895.  
  896. // Custom images
  897. bool addCustom(string imagename)
  898. {
  899. if (customIamges.Find(r => r == imagename) == null)
  900. {
  901. customIamges.Add(imagename);
  902. Interface.Oxide.DataFileSystem.WriteObject("LustyMapImages", customIamges);
  903. return true;
  904. }
  905. return false;
  906. }
  907.  
  908. bool removeCustom(string imagename)
  909. {
  910. if (customIamges.Find(r => r == imagename) != null)
  911. {
  912. customIamges.Remove(imagename);
  913. Interface.Oxide.DataFileSystem.WriteObject("LustyMapImages", customIamges);
  914. return true;
  915. }
  916. return false;
  917. }
  918.  
  919. // Ready to start!
  920. void StartUp()
  921. {
  922. if (BasePlayer.activePlayerList.Count > 0)
  923. {
  924. foreach (BasePlayer player in BasePlayer.activePlayerList)
  925. {
  926. InitUser(player);
  927. }
  928. }
  929.  
  930. run = true;
  931. UpdateMapTimer();
  932. UpdateFriendsTimer();
  933. }
  934.  
  935. void UpdatePlayerLocation(BasePlayer player)
  936. {
  937. playerLocations[player.userID] = new MapLocation
  938. {
  939. name = RemoveSpecialCharacters(player.displayName),
  940. icon = "{icon}" + directionEntity(player.eyes.rotation.eulerAngles.y),
  941. percentX = GetMapPos(player.transform.position.x),
  942. percentZ = GetMapPos(player.transform.position.z)
  943. };
  944. }
  945.  
  946. // Worker Processes
  947. // Update Map
  948. private void UpdateMapTimer()
  949. {
  950. // Check / Update Plane / Heli
  951. checkActive();
  952.  
  953. // Update Player Locations
  954. if (BasePlayer.activePlayerList.Count > 0)
  955. {
  956. foreach (BasePlayer player in BasePlayer.activePlayerList)
  957. {
  958. try
  959. {
  960. UpdatePlayerLocation(player);
  961. minimapGUI(player);
  962. mapGUI(player);
  963. }
  964. catch (Exception e)
  965. {
  966. if (debug) { Puts("Error: UpdateMapTimer: " + e); }
  967. }
  968. }
  969. }
  970.  
  971. // Renew timer
  972. if (run) { timer.Once(0.95f, UpdateMapTimer); }
  973. }
  974.  
  975. // Update Firends
  976. int workCounter = 0;
  977. private void UpdateFriendsTimer()
  978. {
  979. // Refresh Friends if Enabled
  980. if ((rustio && rustiofriends) || (friendapi && friendsapifriends))
  981. {
  982. runningfriends = true;
  983. if (BasePlayer.activePlayerList.Count > 0)
  984. {
  985. float workneeded = BasePlayer.activePlayerList.Count * BasePlayer.activePlayerList.Count;
  986. int worktodo = 0;
  987. if (workneeded < workmaxcycle)
  988. {
  989. worktodo = BasePlayer.activePlayerList.Count;
  990. workCounter = 0;
  991. }
  992. else
  993. {
  994. float cyclesneeded = workneeded / workmaxcycle;
  995. worktodo = Convert.ToInt16(BasePlayer.activePlayerList.Count / cyclesneeded);
  996. }
  997.  
  998. for (int i = 0; i < worktodo; i++)
  999. {
  1000. if (workCounter >= BasePlayer.activePlayerList.Count) { workCounter = 0; }
  1001. try
  1002. {
  1003. BasePlayer player = BasePlayer.activePlayerList[workCounter];
  1004. updateFriends(player);
  1005. }
  1006. catch (Exception e)
  1007. {
  1008. if (debug) { Puts("Error: UpdateFriendsTimer: " + e); }
  1009. }
  1010. workCounter++;
  1011. }
  1012. }
  1013. // Renew timer
  1014. if (run) { timer.Once(1f, UpdateFriendsTimer); }
  1015. }
  1016. else
  1017. {
  1018. runningfriends = false;
  1019. }
  1020. }
  1021.  
  1022. // Friends
  1023. void updateFriends(BasePlayer player)
  1024. {
  1025. MapUser user = getUser(player);
  1026. user.friends.Clear();
  1027.  
  1028. // No need to run if user is admin
  1029. if (user.adminView)
  1030. {
  1031. return;
  1032. }
  1033.  
  1034. foreach (BasePlayer wannabe in BasePlayer.activePlayerList)
  1035. {
  1036. // Skip self
  1037. if (wannabe.userID == player.userID) { continue; }
  1038.  
  1039. // FriendsAPI
  1040. if (friendapi && friendsapifriends)
  1041. {
  1042. if (AreFriendsAPIFriend(wannabe.userID.ToString(), player.userID.ToString()))
  1043. {
  1044. user.friends.Add(wannabe.userID, "friend");
  1045. continue;
  1046. }
  1047. }
  1048. // RustIO
  1049. if (rustio && rustiofriends)
  1050. {
  1051. if (HasRustIOFriend(wannabe.userID.ToString(), player.userID.ToString()) && HasRustIOFriend(player.userID.ToString(), wannabe.userID.ToString()))
  1052. {
  1053. user.friends.Add(wannabe.userID, "friend");
  1054. continue;
  1055. }
  1056. }
  1057. }
  1058. }
  1059.  
  1060. // Cleanup on unload
  1061. void Unloaded()
  1062. {
  1063. if (BasePlayer.activePlayerList.Count > 0)
  1064. {
  1065. foreach (BasePlayer player in BasePlayer.activePlayerList)
  1066. {
  1067. CuiHelper.DestroyUi(player,"MinimapBG");
  1068. CuiHelper.DestroyUi(player,"Minimap");
  1069. CuiHelper.DestroyUi(player,"MinimapHUD");
  1070. CuiHelper.DestroyUi(player,"MapGUI");
  1071. CuiHelper.DestroyUi(player,"MapGUIBG");
  1072. }
  1073. }
  1074. UnityEngine.Object.Destroy(LustyObject);
  1075. }
  1076.  
  1077. // Chat commands
  1078. [ChatCommand("map")]
  1079. private void chatCmd(BasePlayer player, string command, string[] args)
  1080. {
  1081. if (args == null || args.Length == 0)
  1082. {
  1083. playerMsg(player, txtCmdMap);
  1084. }
  1085. else
  1086. {
  1087. if (isAdmin(player))
  1088. {
  1089. if (args[0].ToLower() == "mode")
  1090. {
  1091. if (args.Length > 1)
  1092. {
  1093. try
  1094. {
  1095. mapmode = Convert.ToBoolean(args[1]);
  1096. set("LustyMap", "MapMode", mapmode);
  1097.  
  1098. if (BasePlayer.activePlayerList.Count > 0)
  1099. {
  1100. foreach (BasePlayer activeplayer in BasePlayer.activePlayerList)
  1101. {
  1102. MapUser user = getUser(activeplayer);
  1103. user.minimapRefresh = true;
  1104. }
  1105. }
  1106.  
  1107. // Reload the image cache
  1108. cacheImages();
  1109.  
  1110. string disabled = "Disabled";
  1111. if (mapmode) { disabled = "Enabled"; }
  1112. playerMsg(player, string.Format(txtCmtMode, disabled));
  1113. return;
  1114. }
  1115. catch
  1116. {
  1117.  
  1118. }
  1119. }
  1120. playerMsg(player, txtInvalid + txtCmdMode);
  1121. }
  1122. else if (args[0].ToLower() == "compass")
  1123. {
  1124. if (args.Length > 1)
  1125. {
  1126. try
  1127. {
  1128. compass = Convert.ToBoolean(args[1]);
  1129. set("LustyMap", "Compass", compass);
  1130.  
  1131. string disabled = "Disabled";
  1132. if (compass) { disabled = "Enabled"; }
  1133. playerMsg(player, string.Format(txtCmtCompass, disabled));
  1134. return;
  1135. }
  1136. catch
  1137. {
  1138.  
  1139. }
  1140. }
  1141. playerMsg(player, txtInvalid + txtCmdCompass);
  1142. }
  1143. else if (args[0].ToLower() == "startopen")
  1144. {
  1145. if (args.Length > 1)
  1146. {
  1147. try
  1148. {
  1149. startopen = Convert.ToBoolean(args[1]);
  1150. set("LustyMap", "StartOpen", startopen);
  1151.  
  1152. string open = "Closed";
  1153. if (startopen) { open = "Open"; }
  1154. playerMsg(player, string.Format(txtCmtOpen, open));
  1155. return;
  1156. }
  1157. catch
  1158. {
  1159.  
  1160. }
  1161. }
  1162. playerMsg(player, txtInvalid + txtCmdStart);
  1163. }
  1164. else if (args[0].ToLower() == "minimap")
  1165. {
  1166. if (args.Length > 1)
  1167. {
  1168. if (args[1].ToLower() == "right")
  1169. {
  1170. left = false;
  1171. set("LustyMap", "Left", left);
  1172.  
  1173. if (BasePlayer.activePlayerList.Count > 0)
  1174. {
  1175. foreach (BasePlayer activeplayer in BasePlayer.activePlayerList)
  1176. {
  1177. MapUser user = getUser(activeplayer);
  1178. user.minimapRefresh = true;
  1179. }
  1180. }
  1181.  
  1182. string align = "Right";
  1183. playerMsg(player, string.Format(txtCmtAlign, align));
  1184. return;
  1185. }
  1186. else if (args[1].ToLower() == "left")
  1187. {
  1188. left = true;
  1189. set("LustyMap", "Left", left);
  1190.  
  1191. if (BasePlayer.activePlayerList.Count > 0)
  1192. {
  1193. foreach (BasePlayer activeplayer in BasePlayer.activePlayerList)
  1194. {
  1195. MapUser user = getUser(activeplayer);
  1196. user.minimapRefresh = true;
  1197. }
  1198. }
  1199.  
  1200. string align = "Left";
  1201. playerMsg(player, string.Format(txtCmtAlign, align));
  1202. return;
  1203. }
  1204. else if (args[1].ToLower() == "false")
  1205. {
  1206. minimap = false;
  1207. set("LustyMap", "Minimap", minimap);
  1208.  
  1209. if (BasePlayer.activePlayerList.Count > 0)
  1210. {
  1211. foreach (BasePlayer activeplayer in BasePlayer.activePlayerList)
  1212. {
  1213. CuiHelper.DestroyUi(activeplayer, "Minimap");
  1214. CuiHelper.DestroyUi(activeplayer, "MinimapBG");
  1215. CuiHelper.DestroyUi(activeplayer, "MinimapHUD");
  1216. }
  1217. }
  1218.  
  1219. string disabled = "Disabled";
  1220. playerMsg(player, string.Format(txtCmtMinimap, disabled));
  1221. return;
  1222. }
  1223. else if (args[1].ToLower() == "true")
  1224. {
  1225. minimap = true;
  1226. set("LustyMap", "Minimap", minimap);
  1227.  
  1228. if (BasePlayer.activePlayerList.Count > 0)
  1229. {
  1230. foreach (BasePlayer activeplayer in BasePlayer.activePlayerList)
  1231. {
  1232. MapUser user = getUser(activeplayer);
  1233. user.minimap = true;
  1234. user.minimapRefresh = true;
  1235. }
  1236. }
  1237.  
  1238. string disabled = "Enabled";
  1239. playerMsg(player, string.Format(txtCmtMinimap, disabled));
  1240. return;
  1241. }
  1242. else
  1243. {
  1244. playerMsg(player, txtInvalid + txtCmdMinimap);
  1245. }
  1246. }
  1247. }
  1248. else if (args[0].ToLower() == "url")
  1249. {
  1250. if (args.Length > 1)
  1251. {
  1252. try
  1253. {
  1254. mapurl = args[1];
  1255. set("LustyMap", "MapURL", mapurl);
  1256. playerMsg(player, string.Format(txtCmtUrl, mapurl));
  1257. return;
  1258. }
  1259. catch
  1260. {
  1261.  
  1262. }
  1263. }
  1264. playerMsg(player, txtInvalid + txtCmdUrl);
  1265. }
  1266. else if (args[0].ToLower() == "useurl")
  1267. {
  1268. if (args.Length > 1)
  1269. {
  1270. try
  1271. {
  1272. useurl = Convert.ToBoolean(args[1]);
  1273. set("LustyMap", "UseURL", useurl);
  1274. string disabled = "Disabled";
  1275. if (useurl) { disabled = "Enabled"; }
  1276. playerMsg(player, string.Format(txtCmtUseUrl, disabled));
  1277. return;
  1278. }
  1279. catch
  1280. {
  1281.  
  1282. }
  1283. }
  1284. playerMsg(player, txtInvalid + txtCmdUseUrl);
  1285. }
  1286. else if (args[0].ToLower() == "showcaves")
  1287. {
  1288. if (args.Length > 1)
  1289. {
  1290. try
  1291. {
  1292. showcaves = Convert.ToBoolean(args[1]);
  1293. set("LustyMap", "ShowCaves", showcaves);
  1294. string disabled = "Disabled";
  1295. if (showcaves) { disabled = "Enabled"; }
  1296. playerMsg(player, string.Format(txtCmtCaves, disabled));
  1297. return;
  1298. }
  1299. catch
  1300. {
  1301.  
  1302. }
  1303. }
  1304. playerMsg(player, txtInvalid + txtCmdCaves);
  1305. }
  1306. else if (args[0].ToLower() == "showmonuments")
  1307. {
  1308. if (args.Length > 1)
  1309. {
  1310. try
  1311. {
  1312. showmonuments = Convert.ToBoolean(args[1]);
  1313. set("LustyMap", "ShowMonuments", showmonuments);
  1314. string disabled = "Disabled";
  1315. if (showmonuments) { disabled = "Enabled"; }
  1316. playerMsg(player, string.Format(txtCmtMonuments, disabled));
  1317. return;
  1318. }
  1319. catch
  1320. {
  1321.  
  1322. }
  1323. }
  1324. playerMsg(player, txtInvalid + txtCmdMonuments);
  1325. }
  1326. else if (args[0].ToLower() == "showplane")
  1327. {
  1328. if (args.Length > 1)
  1329. {
  1330. try
  1331. {
  1332. showplane = Convert.ToBoolean(args[1]);
  1333. set("LustyMap", "ShowPlane", showplane);
  1334. string disabled = "Disabled";
  1335. if (showplane) { disabled = "Enabled"; }
  1336. playerMsg(player, string.Format(txtCmtPlane, disabled));
  1337. return;
  1338. }
  1339. catch
  1340. {
  1341.  
  1342. }
  1343. }
  1344. playerMsg(player, txtInvalid + txtCmdPlane);
  1345. }
  1346. else if (args[0].ToLower() == "showheli")
  1347. {
  1348. if (args.Length > 1)
  1349. {
  1350. try
  1351. {
  1352. showheli = Convert.ToBoolean(args[1]);
  1353. set("LustyMap", "ShowHeli", showheli);
  1354. string disabled = "Disabled";
  1355. if (showheli) { disabled = "Enabled"; }
  1356. playerMsg(player, string.Format(txtCmtHeli, disabled));
  1357. return;
  1358. }
  1359. catch
  1360. {
  1361.  
  1362. }
  1363. }
  1364. playerMsg(player, txtInvalid + txtCmdHeli);
  1365. }
  1366. else if (args[0].ToLower() == "showsupply")
  1367. {
  1368. if (args.Length > 1)
  1369. {
  1370. try
  1371. {
  1372. showsupply = Convert.ToBoolean(args[1]);
  1373. set("LustyMap", "ShowSupply", showsupply);
  1374. string disabled = "Disabled";
  1375. if (showsupply) { disabled = "Enabled"; }
  1376. playerMsg(player, string.Format(txtCmtSupply, disabled));
  1377. return;
  1378. }
  1379. catch
  1380. {
  1381.  
  1382. }
  1383. }
  1384. playerMsg(player, txtInvalid + txtCmdSupply);
  1385. }
  1386. else if (args[0].ToLower() == "showdebris")
  1387. {
  1388. if (args.Length > 1)
  1389. {
  1390. try
  1391. {
  1392. showdebris = Convert.ToBoolean(args[1]);
  1393. set("LustyMap", "ShowDebris", showdebris);
  1394. string disabled = "Disabled";
  1395. if (showdebris) { disabled = "Enabled"; }
  1396. playerMsg(player, string.Format(txtCmtDebris, disabled));
  1397. return;
  1398. }
  1399. catch
  1400. {
  1401.  
  1402. }
  1403. }
  1404. playerMsg(player, txtInvalid + txtCmdDebris);
  1405. }
  1406. else if (args[0].ToLower() == "showplayers")
  1407. {
  1408. if (args.Length > 1)
  1409. {
  1410. try
  1411. {
  1412. showplayers = Convert.ToBoolean(args[1]);
  1413. set("LustyMap", "ShowPlayers", showplayers);
  1414. string disabled = "Disabled";
  1415. if (showplayers) { disabled = "Enabled"; }
  1416. playerMsg(player, string.Format(txtCmtPlayers, disabled));
  1417. return;
  1418. }
  1419. catch
  1420. {
  1421.  
  1422. }
  1423. }
  1424. playerMsg(player, txtInvalid + txtCmdPlayers);
  1425. }
  1426. else if (args[0].ToLower() == "debug")
  1427. {
  1428. if (args.Length > 1)
  1429. {
  1430. try
  1431. {
  1432. debug = Convert.ToBoolean(args[1]);
  1433. set("LustyMap", "Debug", debug);
  1434. playerMsg(player, "Debug: " + debug);
  1435. return;
  1436. }
  1437. catch
  1438. {
  1439.  
  1440. }
  1441. }
  1442. playerMsg(player, txtInvalid + txtCmdMonuments);
  1443. }
  1444. else if (args[0].ToLower() == "admin")
  1445. {
  1446. MapUser user = getUser(player);
  1447. if (user.adminView)
  1448. {
  1449. user.adminView = false;
  1450. playerMsg(player, string.Format(txtCmtAdmin, "Disabled"));
  1451. return;
  1452. }
  1453. else
  1454. {
  1455. user.adminView = true;
  1456. playerMsg(player, string.Format(txtCmtAdmin, "Enabled"));
  1457. return;
  1458. }
  1459. }
  1460. else if (args[0].ToLower() == "rustiofriends")
  1461. {
  1462. if (rustio)
  1463. {
  1464. if (args.Length > 1)
  1465. {
  1466. try
  1467. {
  1468. rustiofriends = Convert.ToBoolean(args[1]);
  1469. set("LustyMap", "RustIOFriends", rustiofriends);
  1470. if (!runningfriends) { UpdateFriendsTimer(); }
  1471. string disabled = "Disabled";
  1472. if (rustiofriends) { disabled = "Enabled"; }
  1473. playerMsg(player, string.Format(txtCmtIOFriends, disabled));
  1474. return;
  1475. }
  1476. catch
  1477. {
  1478.  
  1479. }
  1480. }
  1481. if (debug)
  1482. {
  1483. playerMsg(player, "RustIOFriends: " + rustiofriends);
  1484. }
  1485. else
  1486. {
  1487. playerMsg(player, txtInvalid + txtCmdIOFriends);
  1488. }
  1489. }
  1490. else
  1491. {
  1492. rustiofriends = false;
  1493. playerMsg(player, "RustIO not detected...");
  1494. }
  1495. }
  1496. else if (args[0].ToLower() == "friendsapifriends")
  1497. {
  1498. if (friendapi)
  1499. {
  1500. if (args.Length > 1)
  1501. {
  1502. try
  1503. {
  1504. friendsapifriends = Convert.ToBoolean(args[1]);
  1505. set("LustyMap", "FriendsAPIFriends", friendsapifriends);
  1506. if (!runningfriends) { UpdateFriendsTimer(); }
  1507. string disabled = "Disabled";
  1508. if (friendsapifriends) { disabled = "Enabled"; }
  1509. playerMsg(player, string.Format(txtCmtAPIFriends, disabled));
  1510. return;
  1511. }
  1512. catch
  1513. {
  1514.  
  1515. }
  1516. }
  1517. playerMsg(player, txtInvalid + txtCmdAPIFriends);
  1518. }
  1519. else
  1520. {
  1521. friendsapifriends = false;
  1522. playerMsg(player, "FriendsAPI not detected...");
  1523. }
  1524. }
  1525. else if (args[0].ToLower() == "add")
  1526. {
  1527. if (args.Length > 2)
  1528. {
  1529. if (addLocation(player, args[1], args[2].ToLower()))
  1530. {
  1531. playerMsg(player, "location added");
  1532. }
  1533. else
  1534. {
  1535. playerMsg(player, "location already in list");
  1536. }
  1537. }
  1538. else if (args.Length > 1)
  1539. {
  1540. if (addLocation(player, args[1]))
  1541. {
  1542. playerMsg(player, "location added");
  1543. }
  1544. else
  1545. {
  1546. playerMsg(player, "location already in list");
  1547. }
  1548. }
  1549. else
  1550. {
  1551. playerMsg(player, txtInvalid + txtCmdLocation);
  1552. }
  1553. }
  1554. else if (args[0].ToLower() == "remove")
  1555. {
  1556. if (args.Length > 1)
  1557. {
  1558. if (removeLocation(args[1].ToLower()))
  1559. {
  1560. playerMsg(player, "location removed");
  1561. }
  1562. else
  1563. {
  1564. playerMsg(player, "location not in list");
  1565. }
  1566. }
  1567. else
  1568. {
  1569. playerMsg(player, txtInvalid + txtCmdLocation);
  1570. }
  1571. }
  1572. else if (args[0].ToLower() == "images")
  1573. {
  1574. playerMsg(player, "Reloading image cache...");
  1575. cacheImages();
  1576. }
  1577. else if (args[0].ToLower() == "addimage")
  1578. {
  1579. if (args.Length > 1)
  1580. {
  1581. if (addCustom(args[1].ToLower()))
  1582. {
  1583. playerMsg(player, "Image added");
  1584. cacheImages();
  1585. }
  1586. else
  1587. {
  1588. playerMsg(player, "Image already in list");
  1589. }
  1590. }
  1591. else
  1592. {
  1593. playerMsg(player, txtInvalid + txtCmdImage);
  1594. }
  1595. }
  1596. else if (args[0].ToLower() == "removeimage")
  1597. {
  1598. if (args.Length > 1)
  1599. {
  1600. if (removeCustom(args[1].ToLower()))
  1601. {
  1602. playerMsg(player, "Image removed");
  1603. }
  1604. else
  1605. {
  1606. playerMsg(player, "Image not in list");
  1607. }
  1608. }
  1609. else
  1610. {
  1611. playerMsg(player, txtInvalid + txtCmdImage);
  1612. }
  1613. }
  1614. else
  1615. {
  1616. playerMsg(player, txtUnknown);
  1617. }
  1618. }
  1619. }
  1620. }
  1621.  
  1622. // Console commands
  1623. [ConsoleCommand("LustyMap")]
  1624. private void lustyConsole(ConsoleSystem.Arg arg)
  1625. {
  1626. var player = arg.Player();
  1627.  
  1628. if (arg.Args == null || arg.Args.Length == 0)
  1629. {
  1630. PrintToConsole(player, Title + " v" + Version);
  1631. }
  1632. else
  1633. {
  1634. try
  1635. {
  1636. if (arg.Args[0].ToLower() == "close")
  1637. {
  1638. MapUser user = getUser(player);
  1639. user.minimapReOpen = false;
  1640. user.minimap = false;
  1641. user.minimapRefresh = true;
  1642. CuiHelper.DestroyUi(player, "Minimap");
  1643. CuiHelper.DestroyUi(player, "MinimapBG");
  1644. CuiHelper.DestroyUi(player, "MinimapHUD");
  1645. minimapGUI(player);
  1646. }
  1647. else if (arg.Args[0].ToLower() == "open")
  1648. {
  1649. MapUser user = getUser(player);
  1650. user.minimapReOpen = true;
  1651. user.minimap = true;
  1652. user.minimapRefresh = true;
  1653. minimapGUI(player);
  1654. }
  1655. else if (arg.Args[0].ToLower() == "map")
  1656. {
  1657. mapToggle(player);
  1658. }
  1659. else if (arg.Args[0].ToLower() == "return")
  1660. {
  1661. mapClose(player);
  1662. }
  1663. else if (arg.Args[0].ToLower() == "zoomin")
  1664. {
  1665. MapUser user = getUser(player);
  1666. // Check if at max zoom
  1667. if (user.minimapZoom > 1)
  1668. {
  1669. user.minimapZoom--;
  1670. user.minimapRefresh = true;
  1671. }
  1672. }
  1673. else if (arg.Args[0].ToLower() == "zoomout")
  1674. {
  1675. MapUser user = getUser(player);
  1676. // Check if at min zoom
  1677. if (user.minimapZoom < 4)
  1678. {
  1679. user.minimapZoom++;
  1680. user.minimapRefresh = true;
  1681. }
  1682. }
  1683. }
  1684. catch
  1685. {
  1686.  
  1687. }
  1688. }
  1689. }
  1690.  
  1691. void mapToggle(BasePlayer player)
  1692. {
  1693. MapUser user = getUser(player);
  1694. if (user.map)
  1695. {
  1696. mapClose(player);
  1697. }
  1698. else
  1699. {
  1700. mapOpen(player);
  1701. }
  1702. }
  1703.  
  1704. void mapOpen(BasePlayer player)
  1705. {
  1706. MapUser user = getUser(player);
  1707. user.minimap = false;
  1708. CuiHelper.DestroyUi(player,"Minimap");
  1709. CuiHelper.DestroyUi(player,"MinimapBG");
  1710. CuiHelper.DestroyUi(player,"MinimapHUD");
  1711. user.map = true;
  1712. user.minimapRefresh = true;
  1713. user.mapRefresh = true;
  1714. minimapGUI(player);
  1715. mapGUI(player);
  1716. }
  1717.  
  1718. void mapClose(BasePlayer player)
  1719. {
  1720. MapUser user = getUser(player);
  1721. if (user.map)
  1722. {
  1723. user.map = false;
  1724. user.minimapRefresh = true;
  1725. user.mapRefresh = false;
  1726. CuiHelper.DestroyUi(player,"MapGUI");
  1727. CuiHelper.DestroyUi(player,"MapGUIBG");
  1728. if (user.minimapReOpen)
  1729. {
  1730. user.minimap = true;
  1731. minimapGUI(player);
  1732. }
  1733. }
  1734. }
  1735.  
  1736. // User settings
  1737. private class MapUser
  1738. {
  1739. public ulong userid { get; set; }
  1740. public bool minimap { get; set; }
  1741. public bool minimapStart { get; set; }
  1742. public bool minimapReOpen { get; set; }
  1743. public bool minimapLeft { get; set; }
  1744. public bool minimapRefresh { get; set; }
  1745. public int minimapZoom { get; set; }
  1746. public bool compass { get; set; }
  1747. public bool map { get; set; }
  1748. public bool mapGrid { get; set; }
  1749. public bool mapCustom { get; set; }
  1750. public bool mapMonuments { get; set; }
  1751. public bool mapCaves { get; set; }
  1752. public bool mapHeli { get; set; }
  1753. public bool mapPlane { get; set; }
  1754. public bool mapSupply { get; set; }
  1755. public bool mapDebris { get; set; }
  1756. public bool mapRefresh { get; set; }
  1757. public bool mapMode { get; set; }
  1758. public bool mapNames { get; set; }
  1759. public bool adminView { get; set; }
  1760. public int mapx { get; set; }
  1761. public int mapz { get; set; }
  1762. public Dictionary<ulong, string> friends { get; set; }
  1763. }
  1764.  
  1765. Dictionary<ulong, MapUser> mapUsers = new Dictionary<ulong, MapUser>();
  1766.  
  1767. private MapUser getUser(BasePlayer player) => getUser(player.userID);
  1768. private MapUser getUser(ulong userid)
  1769. {
  1770. // Find player...
  1771. MapUser user;
  1772. return mapUsers.TryGetValue(userid, out user) ? user : newUser(userid);
  1773. }
  1774.  
  1775. private MapUser newUser(ulong userid)
  1776. {
  1777. MapUser user = new MapUser
  1778. {
  1779. userid = userid,
  1780. minimap = startopen,
  1781. minimapReOpen = startopen,
  1782. minimapLeft = left,
  1783. compass = compass,
  1784. map = false,
  1785. mapGrid = true,
  1786. mapCustom = true,
  1787. mapMonuments = showmonuments,
  1788. mapCaves = showcaves,
  1789. mapHeli = showheli,
  1790. mapPlane = showplane,
  1791. mapSupply = showsupply,
  1792. mapDebris = showdebris,
  1793. mapNames = shownames,
  1794. mapx = 0,
  1795. mapz = 0,
  1796. minimapRefresh = true,
  1797. minimapZoom = 1,
  1798. friends = new Dictionary<ulong, string>(),
  1799. mapMode = mapmode,
  1800. adminView = false
  1801. };
  1802. mapUsers.Add(userid, user);
  1803. return user;
  1804. }
  1805.  
  1806. // Player Join
  1807. [HookMethod("OnPlayerInit")]
  1808. void OnPlayerInit(BasePlayer player)
  1809. {
  1810. OnPlayerReady(player);
  1811. }
  1812.  
  1813. private void OnPlayerReady(BasePlayer player)
  1814. {
  1815. if (player.HasPlayerFlag(BasePlayer.PlayerFlags.ReceivingSnapshot))
  1816. {
  1817. timer.In(1, () => OnPlayerReady(player));
  1818. }
  1819. else
  1820. {
  1821. InitUser(player);
  1822.  
  1823. }
  1824. }
  1825.  
  1826. void InitUser(BasePlayer player)
  1827. {
  1828. // Keybinds
  1829. player.Command("bind m \"LustyMap map\"");
  1830.  
  1831. // Variables
  1832. MapUser user = getUser(player);
  1833. user.minimapRefresh = true;
  1834.  
  1835. // Make sure no exiting map gui exists (in case of disconnect with map open)
  1836. mapClose(player);
  1837. }
  1838.  
  1839. // Player Disconnect
  1840. void OnPlayerDisconnected(BasePlayer player)
  1841. {
  1842. playerLocations.Remove(player.userID);
  1843. }
  1844.  
  1845. // Map GUI
  1846. private void mapGUI(BasePlayer player)
  1847. {
  1848. MapUser user = getUser(player);
  1849. if (user.map)
  1850. {
  1851. if (user.mapRefresh)
  1852. {
  1853. GUIv4 gui = new GUIv4();
  1854. gui.add("MapGUIBG", false, "0.2271875 0.015", "0.7728125 0.985", "0 0 0 1");
  1855. gui.png("{parent}", "Map", fetchImage("mapimage"), "0 0", "1 1");
  1856. gui.text("{parent}", "Ver", TextAnchor.LowerRight, "<size=10>" + Title + " v" + Version + "</size>", "0.8 0.01", "0.99 0.1");
  1857.  
  1858. bool grid = false;
  1859.  
  1860. if (grid)
  1861. {
  1862. int rows = 25;
  1863. for (int i = 1; i < 25; i++)
  1864. {
  1865. double s = ((1f / rows) * i) - 0.000001f;
  1866. double e = ((1f / rows) * i) + 0.000001f;
  1867.  
  1868. gui.box("{parent}", "X" + i, s + " 0", e + " 1", "0.2 0.2 0.2 8");
  1869. gui.box("{parent}", "Y" + i, "0 " + s, "1 " + e, "0.2 0.2 0.2 8");
  1870. }
  1871. }
  1872.  
  1873. double iconsize = 0.01f;
  1874. if (showmonuments && user.mapMonuments)
  1875. {
  1876. foreach (MapLocation location in mapMonuments)
  1877. {
  1878. if (location.name == "Cave" && !showcaves) { continue; }
  1879. if (location.name == "Cave" && !user.mapCaves) { continue; }
  1880. gui.png("{parent}", "Mon" + DateTime.Now.Ticks, fetchImage(location.icon), (location.percentX - iconsize) + " " + (location.percentZ - iconsize), (location.percentX + iconsize) + " " + (location.percentZ + iconsize));
  1881. gui.text("{parent}", "TxT" + DateTime.Now.Ticks, TextAnchor.UpperCenter, "<size=10>" + location.name + "</size>", (location.percentX - 0.1) + " " + (location.percentZ - iconsize - 0.05), (location.percentX + 0.1) + " " + (location.percentZ - iconsize));
  1882. }
  1883. }
  1884. if (user.mapCustom)
  1885. {
  1886. foreach (MapLocation location in mapCustom)
  1887. {
  1888. gui.png("{parent}", "Cus" + DateTime.Now.Ticks, fetchImage(location.icon), (location.percentX - iconsize) + " " + (location.percentZ - iconsize), (location.percentX + iconsize) + " " + (location.percentZ + iconsize));
  1889. gui.text("{parent}", "TxT" + DateTime.Now.Ticks, TextAnchor.UpperCenter, "<size=10>" + location.name + "</size>", (location.percentX - 0.1) + " " + (location.percentZ - iconsize - 0.05), (location.percentX + 0.1) + " " + (location.percentZ - iconsize));
  1890. }
  1891. }
  1892. gui.send(player);
  1893. user.mapRefresh = false;
  1894. }
  1895. }
  1896. // Live Map
  1897. if (user.map)
  1898. {
  1899. // Player Direction
  1900. string direction = null;
  1901. double lookRotation = player.eyes.rotation.eulerAngles.y;
  1902. int playerdirection = (Convert.ToInt16((lookRotation - 5) / 10 + 0.5) * 10);
  1903. if (lookRotation >= 355) playerdirection = 0;
  1904. if (lookRotation > 337.5 || lookRotation < 22.5) { direction = txtCpsN; }
  1905. else if (lookRotation > 22.5 && lookRotation < 67.5) { direction = txtCpsNE; }
  1906. else if (lookRotation > 67.5 && lookRotation < 112.5) { direction = txtCpsE; }
  1907. else if (lookRotation > 112.5 && lookRotation < 157.5) { direction = txtCpsSE; }
  1908. else if (lookRotation > 157.5 && lookRotation < 202.5) { direction = txtCpsS; }
  1909. else if (lookRotation > 202.5 && lookRotation < 247.5) { direction = txtCpsSW; }
  1910. else if (lookRotation > 247.5 && lookRotation < 292.5) { direction = txtCpsW; }
  1911. else if (lookRotation > 292.5 && lookRotation < 337.5) { direction = txtCpsNW; }
  1912.  
  1913. double mapX = GetMapPos(player.transform.position.x);
  1914. double mapZ = GetMapPos(player.transform.position.z);
  1915.  
  1916. GUIv4 gui = new GUIv4();
  1917. gui.add("MapGUI", false, "0.2271875 0.015", "0.7728125 0.985", "0 0 0 0");
  1918.  
  1919. bool grid = false;
  1920.  
  1921. double iconsize = 0.02f;
  1922. if (activeEntities.Count > 0)
  1923. {
  1924. foreach (ActiveEntity entity in activeEntities)
  1925. {
  1926. if ((entity.isplane && showplane && user.mapPlane) || (entity.isheli && showheli && user.mapHeli) || (entity.issupply && showsupply && user.mapSupply) || (entity.issupply && showsupply && user.mapSupply) || (entity.isdebris && showdebris && user.mapDebris))
  1927. {
  1928. if (entity.percentX >= 0 && entity.percentX <= 1 && entity.percentZ >= 0 && entity.percentZ <= 1)
  1929. {
  1930. gui.png("{parent}", "Ent" + DateTime.Now.Ticks.ToString(), fetchImage(entity.icon), (entity.percentX - iconsize) + " " + (entity.percentZ - iconsize), (entity.percentX + iconsize) + " " + (entity.percentZ + iconsize));
  1931. }
  1932. }
  1933. }
  1934. }
  1935.  
  1936. if (showplayers)
  1937. {
  1938. // Admin View, just add everyone...
  1939. if (user.adminView)
  1940. {
  1941. foreach (BasePlayer other in BasePlayer.activePlayerList)
  1942. {
  1943. // Skip self
  1944. if (other.userID == player.userID) { continue; }
  1945.  
  1946. MapLocation otherEntity;
  1947. if (!playerLocations.TryGetValue(other.userID, out otherEntity)) { continue; }
  1948.  
  1949. if (otherEntity.percentX >= 0 && otherEntity.percentX <= 1 && otherEntity.percentZ >= 0 && otherEntity.percentZ <= 1)
  1950. {
  1951. gui.png("{parent}", "Fnd" + DateTime.Now.Ticks, fetchImage(otherEntity.icon.Replace("{icon}", "other")), (otherEntity.percentX - (iconsize / 1.5)) + " " + (otherEntity.percentZ - (iconsize / 1.5)), (otherEntity.percentX + (iconsize / 1.5)) + " " + (otherEntity.percentZ + (iconsize / 1.5)));
  1952. if (user.mapNames)
  1953. {
  1954. gui.text("{parent}", "Nm" + DateTime.Now.Ticks, TextAnchor.LowerCenter, "<size=8><color=#00ffffff>" + otherEntity.name + "</color></size>", (otherEntity.percentX - 0.1) + " " + (otherEntity.percentZ + (iconsize / 1.5)), (otherEntity.percentX + 0.1) + " " + (otherEntity.percentZ + (iconsize / 1.5) + 0.1));
  1955. }
  1956. }
  1957. }
  1958. }
  1959. // Check for Friends...
  1960. else if (user.friends.Count > 0)
  1961. {
  1962. foreach (KeyValuePair<ulong, string> pair in user.friends)
  1963. {
  1964. MapLocation friendEntity;
  1965. if (!playerLocations.TryGetValue(pair.Key, out friendEntity)) { continue; }
  1966.  
  1967. if (friendEntity.percentX >= 0 && friendEntity.percentX <= 1 && friendEntity.percentZ >= 0 && friendEntity.percentZ <= 1)
  1968. {
  1969. gui.png("{parent}", "Fnd" + DateTime.Now.Ticks, fetchImage(friendEntity.icon.Replace("{icon}", pair.Value)), (friendEntity.percentX - (iconsize / 1.5)) + " " + (friendEntity.percentZ - (iconsize / 1.5)), (friendEntity.percentX + (iconsize / 1.5)) + " " + (friendEntity.percentZ + (iconsize / 1.5)));
  1970. if (user.mapNames)
  1971. {
  1972. gui.text("{parent}", "Nm" + DateTime.Now.Ticks, TextAnchor.LowerCenter, "<size=8><color=#00ffffff>" + friendEntity.name + "</color></size>", (friendEntity.percentX - 0.1) + " " + (friendEntity.percentZ + (iconsize / 1.5)), (friendEntity.percentX + 0.1) + " " + (friendEntity.percentZ + (iconsize / 1.5) + 0.1));
  1973. }
  1974. }
  1975. }
  1976. }
  1977. gui.png("{parent}", "Player", fetchImage("self" + playerdirection), (mapX - (iconsize / 1.5)) + " " + (mapZ - (iconsize / 1.5)), (mapX + (iconsize / 1.5)) + " " + (mapZ + (iconsize / 1.5)));
  1978. if (user.mapNames)
  1979. {
  1980. gui.text("{parent}", "Pn" + DateTime.Now.Ticks, TextAnchor.LowerCenter, "<size=8><color=#00ff00ff>" + RemoveSpecialCharacters(player.displayName) + "</color></size>", (mapX - 0.1) + " " + (mapZ + (iconsize / 1.5)), (mapX + 0.1) + " " + (mapZ + (iconsize / 1.5) + 0.1));
  1981. }
  1982. }
  1983. gui.text("{parent}", "Direction", TextAnchor.UpperRight, "<size=16>" + txtCpsHead + " " + direction + "</size>\n<size=12>" + player.transform.position + "</size>", "0.6 0.9", "0.99 0.99");
  1984. gui.send(player);
  1985. }
  1986. }
  1987.  
  1988. // Minimap Menu
  1989. private void minimapGUI(BasePlayer player)
  1990. {
  1991. MapUser user = getUser(player);
  1992. int mapslices = 32;
  1993.  
  1994. // Minimap open / allowed?
  1995. if (minimap)
  1996. {
  1997. // 16:9 Ratio
  1998. double width = 0.13 * scale;
  1999. double height = 0.2301 * scale;
  2000.  
  2001. double startx = 0 + offsetSide;
  2002. double endx = startx + width;
  2003.  
  2004. double endy = 1 - offsetTop;
  2005. double starty = endy - height;
  2006.  
  2007. // Map alignment
  2008. if (!left)
  2009. {
  2010. endx = 1 - offsetSide;
  2011. startx = endx - width;
  2012. }
  2013.  
  2014. // Minimap Hud
  2015. if (user.minimapRefresh)
  2016. {
  2017. GUIv4 gui = new GUIv4();
  2018. gui.add("MinimapHUD", false, startx + " " + (endy - 0.02), endx + " " + endy, "0 0 0 0");
  2019.  
  2020. if (left)
  2021. {
  2022. if (user.minimap)
  2023. {
  2024. gui.button("{parent}", "MinimapClose", TextAnchor.MiddleCenter, "<size=12><<<</size>", true, "LustyMap close", "1 0", "1.15 1", "0 0 0 0.6");
  2025. if (mapmode)
  2026. {
  2027. gui.button("{parent}", "MinimapIn", TextAnchor.MiddleCenter, "<size=12>+</size>", false, "LustyMap zoomin", "1 -1.1", "1.1 -0.1", "0 0 0 0.6");
  2028. gui.button("{parent}", "MinimapOut", TextAnchor.MiddleCenter, "<size=12>-</size>", false, "LustyMap zoomout", "1 -2.2", "1.1 -1.2", "0 0 0 0.6");
  2029. }
  2030. }
  2031. else
  2032. {
  2033. gui.button("{parent}", "MinimapOpen", TextAnchor.MiddleCenter, "<size=12>>>></size>", true, "LustyMap open", "0 0", "0.15 1", "0 0 0 0.6");
  2034. if (mapmode)
  2035. {
  2036. gui.button("{parent}", "MinimapIn", TextAnchor.MiddleCenter, "<size=12>+</size>", false, "LustyMap zoomin", "0 -1.1", "0.1 -0.1", "0 0 0 0.6");
  2037. gui.button("{parent}", "MinimapOut", TextAnchor.MiddleCenter, "<size=12>-</size>", false, "LustyMap zoomout", "0 -2.2", "0.1 -1.2", "0 0 0 0.6");
  2038. }
  2039. }
  2040. }
  2041. else
  2042. {
  2043. if (user.minimap)
  2044. {
  2045. gui.button("{parent}", "MinimapClose", TextAnchor.MiddleCenter, "<size=12>>>></size>", true, "LustyMap close", "-0.15 0", "0 1", "0 0 0 0.6");
  2046. if (mapmode)
  2047. {
  2048. gui.button("{parent}", "MinimapIn", TextAnchor.MiddleCenter, "<size=12>+</size>", false, "LustyMap zoomin", "-0.15 -1.1", "0 -0.1", "0 0 0 0.6");
  2049. gui.button("{parent}", "MinimapOut", TextAnchor.MiddleCenter, "<size=12>-</size>", false, "LustyMap zoomout", "-0.15 -2.2", "0 -1.2", "0 0 0 0.6");
  2050. }
  2051. }
  2052. else
  2053. {
  2054. gui.button("{parent}", "MinimapOpen", TextAnchor.MiddleCenter, "<size=12><<<</size>", true, "LustyMap open", "0.85 0", "1 1", "0 0 0 0.6");
  2055. if (mapmode)
  2056. {
  2057. gui.button("{parent}", "MinimapIn", TextAnchor.MiddleCenter, "<size=12>+</size>", false, "LustyMap zoomin", "0.85 -1.1", "1 -0.1", "0 0 0 0.6");
  2058. gui.button("{parent}", "MinimapOut", TextAnchor.MiddleCenter, "<size=12>-</size>", false, "LustyMap zoomout", "0.85 -2.2", "1 -1.2", "0 0 0 0.6");
  2059. }
  2060. }
  2061. }
  2062. gui.send(player);
  2063. }
  2064.  
  2065. // Minimap Simple Mode - Background
  2066. if (user.minimapRefresh && user.minimap)
  2067. {
  2068. if (!mapmode)
  2069. {
  2070. GUIv4 gui = new GUIv4();
  2071. gui.add("MinimapBG", false, startx + " " + starty, endx + " " + endy, "0 0 0 1");
  2072. gui.png("{parent}", "Map", fetchImage("mapimage"), "0 0", "1 1");
  2073.  
  2074. if (showmonuments && user.mapMonuments)
  2075. {
  2076. double iconsize = 0.02f;
  2077. foreach (MapLocation location in mapMonuments)
  2078. {
  2079. if (location.name == "Cave" && !showcaves) { continue; }
  2080. if (location.name == "Cave" && !user.mapCaves) { continue; }
  2081. gui.png("{parent}", "Mon" + DateTime.Now.Ticks, fetchImage(location.icon), (location.percentX - iconsize) + " " + (location.percentZ - iconsize), (location.percentX + iconsize) + " " + (location.percentZ + iconsize));
  2082. }
  2083. }
  2084. if (user.mapCustom)
  2085. {
  2086. double iconsize = 0.02f;
  2087. foreach (MapLocation location in mapCustom)
  2088. {
  2089. gui.png("{parent}", "Cus" + DateTime.Now.Ticks, fetchImage(location.icon), (location.percentX - iconsize) + " " + (location.percentZ - iconsize), (location.percentX + iconsize) + " " + (location.percentZ + iconsize));
  2090. }
  2091. }
  2092.  
  2093. gui.send(player);
  2094. }
  2095. }
  2096.  
  2097. // Minimap Complex Mode - Background Refresh
  2098. if (mapmode && user.minimap)
  2099. {
  2100. // Get zoom level for user
  2101. if (user.minimapZoom == 4)
  2102. {
  2103. mapslices = 6;
  2104. }
  2105. else if (user.minimapZoom == 3)
  2106. {
  2107. mapslices = 12;
  2108. }
  2109. else if (user.minimapZoom == 2)
  2110. {
  2111. mapslices = 26;
  2112. }
  2113.  
  2114. // Get center map part
  2115. double x = player.transform.position.x + mapSize / 2f;
  2116. double z = player.transform.position.z + mapSize / 2f;
  2117. var mapres = mapSize / mapslices;
  2118. int currentx = Convert.ToInt32(Math.Ceiling(x / mapres)) - 2;
  2119. int currentz = mapslices - Convert.ToInt32(Math.Ceiling(z / mapres)) - 1;
  2120.  
  2121. // Check if it has changed
  2122. if (user.mapx != currentx || user.mapz != currentz || user.minimapRefresh)
  2123. {
  2124. user.mapx = currentx;
  2125. user.mapz = currentz;
  2126.  
  2127. // Start creating GUI
  2128. GUIv4 gui = new GUIv4();
  2129. gui.add("MinimapBG", false, startx + " " + starty, endx + " " + endy, "0 0 0 0");
  2130.  
  2131. // Map parts
  2132. int row = 3;
  2133. int col = 3;
  2134. for (int r = 0; r < row; r++)
  2135. {
  2136. for (int c = 0; c < col; c++)
  2137. {
  2138. string maplink = "map-" + mapslices + "-" + (currentz + r) + "-" + (currentx + c);
  2139. string sx = Convert.ToSingle(c * (1f / col)).ToString();
  2140. string sy = Convert.ToSingle(1 - ((1f / row) * (r + 1))).ToString();
  2141. string ex = Convert.ToSingle(((c + 1) * (1f / col)) - 0.0005f).ToString();
  2142. string ey = Convert.ToSingle((1 - ((1f / row) * (r + 1)) + (1f / row)) - 0.0004f).ToString();
  2143.  
  2144. if ((currentz + r) >= 0 && (currentz + r) < mapslices && (currentx + c) >= 0 && (currentx + c) < mapslices)
  2145. {
  2146. gui.png("{parent}", "Map" + DateTime.Now.Ticks, fetchImage(maplink), sx + " " + sy, ex + " " + ey, "0.9");
  2147. }
  2148. else
  2149. {
  2150. gui.png("{parent}", "Map" + DateTime.Now.Ticks, fetchImage("mapbg"), sx + " " + sy, ex + " " + ey, "0.9");
  2151. }
  2152. if (showmonuments && user.mapMonuments)
  2153. {
  2154. double iconsize = 0.05f;
  2155. foreach (MapLocation location in mapMonuments)
  2156. {
  2157. if (location.name == "Cave" && !showcaves) { continue; }
  2158. if (location.name == "Cave" && !user.mapCaves) { continue; }
  2159.  
  2160. int lrow = (Convert.ToInt16(Math.Floor(mapslices * location.percentX)));
  2161. int lcolumn = ((mapslices - 1) - Convert.ToInt16(Math.Floor(mapslices * location.percentZ)));
  2162.  
  2163. if (lcolumn == (currentz + r) && lrow == (currentx + c))
  2164. {
  2165. double _sx = Convert.ToSingle(c * (1f / col));
  2166. double _sy = Convert.ToSingle(1 - ((1f / row) * (r + 1)));
  2167. double _ex = Convert.ToSingle(((c + 1) * (1f / col)) - 0.005f);
  2168. double _ey = Convert.ToSingle((1 - ((1f / row) * (r + 1)) + (1f / row)) - 0.004f);
  2169. double mapX = (location.percentX * mapslices) - lrow;
  2170. double mapZ = ((1 - location.percentZ) * mapslices) - lcolumn;
  2171. double _xd = _ex - _sx;
  2172. mapX = (mapX * _xd) + _sx;
  2173. double _yd = _ey - _sy;
  2174. mapZ = _ey - (mapZ * _yd);
  2175.  
  2176. gui.png("{parent}", "Mon" + DateTime.Now.Ticks, fetchImage(location.icon), (mapX - iconsize) + " " + (mapZ - iconsize), (mapX + iconsize) + " " + (mapZ + iconsize), "1");
  2177. }
  2178. }
  2179. }
  2180. if (user.mapCustom)
  2181. {
  2182. double iconsize = 0.05f;
  2183. foreach (MapLocation location in mapCustom)
  2184. {
  2185. int lrow = (Convert.ToInt16(Math.Floor(mapslices * location.percentX)));
  2186. int lcolumn = ((mapslices - 1) - Convert.ToInt16(Math.Floor(mapslices * location.percentZ)));
  2187.  
  2188. if (lcolumn == (currentz + r) && lrow == (currentx + c))
  2189. {
  2190. double _sx = Convert.ToSingle(c * (1f / col));
  2191. double _sy = Convert.ToSingle(1 - ((1f / row) * (r + 1)));
  2192. double _ex = Convert.ToSingle(((c + 1) * (1f / col)) - 0.005f);
  2193. double _ey = Convert.ToSingle((1 - ((1f / row) * (r + 1)) + (1f / row)) - 0.004f);
  2194. double mapX = (location.percentX * mapslices) - lrow;
  2195. double mapZ = ((1 - location.percentZ) * mapslices) - lcolumn;
  2196. double _xd = _ex - _sx;
  2197. mapX = (mapX * _xd) + _sx;
  2198. double _yd = _ey - _sy;
  2199. mapZ = _ey - (mapZ * _yd);
  2200.  
  2201. gui.png("{parent}", "Cus" + DateTime.Now.Ticks, fetchImage(location.icon), (mapX - iconsize) + " " + (mapZ - iconsize), (mapX + iconsize) + " " + (mapZ + iconsize), "1");
  2202. }
  2203. }
  2204. }
  2205. }
  2206. }
  2207. gui.send(player);
  2208. }
  2209. }
  2210.  
  2211. // Static GUI done
  2212. if (user.minimapRefresh) { user.minimapRefresh = false; }
  2213.  
  2214. // Minimap Player / Entity Locations
  2215. if (user.minimap)
  2216. {
  2217. // Player Direction
  2218. string direction = null;
  2219. double lookRotation = player.eyes.rotation.eulerAngles.y;
  2220. int playerdirection = (Convert.ToInt16((lookRotation - 5) / 10 + 0.5) * 10);
  2221. if (lookRotation > 337.5 || lookRotation < 22.5) { direction = txtCpsN; }
  2222. else if (lookRotation > 22.5 && lookRotation < 67.5) { direction = txtCpsNE; }
  2223. else if (lookRotation > 67.5 && lookRotation < 112.5) { direction = txtCpsE; }
  2224. else if (lookRotation > 112.5 && lookRotation < 157.5) { direction = txtCpsSE; }
  2225. else if (lookRotation > 157.5 && lookRotation < 202.5) { direction = txtCpsS; }
  2226. else if (lookRotation > 202.5 && lookRotation < 247.5) { direction = txtCpsSW; }
  2227. else if (lookRotation > 247.5 && lookRotation < 292.5) { direction = txtCpsW; }
  2228. else if (lookRotation > 292.5 && lookRotation < 337.5) { direction = txtCpsNW; }
  2229.  
  2230. // Player Location
  2231. double x = player.transform.position.x + mapSize / 2f;
  2232. double z = player.transform.position.z + mapSize / 2f;
  2233.  
  2234. // Player location in percent
  2235. double mapX = GetMapPos(player.transform.position.x);
  2236. double mapZ = GetMapPos(player.transform.position.z);
  2237.  
  2238. // GUI
  2239. GUIv4 gui = new GUIv4();
  2240. gui.add("Minimap", false, startx + " " + starty, endx + " " + endy, "0 0 0 0");
  2241.  
  2242. double iconsize = 0.05f;
  2243. if (mapmode)
  2244. {
  2245. var mapres = mapSize / mapslices;
  2246. int currentx = Convert.ToInt32(Math.Ceiling(x / mapres)) - 2;
  2247. int currentz = mapslices - Convert.ToInt32(Math.Ceiling(z / mapres)) - 1;
  2248.  
  2249. // Map parts
  2250. int row = 3;
  2251. int col = 3;
  2252. for (int r = 0; r < row; r++)
  2253. {
  2254. for (int c = 0; c < col; c++)
  2255. {
  2256. // Planes / Helis / Supply Drops Etc...
  2257. if (activeEntities.Count > 0)
  2258. {
  2259. foreach (ActiveEntity entity in activeEntities)
  2260. {
  2261. if ((entity.isplane && showplane && user.mapPlane) || (entity.isheli && showheli && user.mapHeli) || (entity.issupply && showsupply && user.mapSupply) || (entity.isdebris && showdebris && user.mapDebris))
  2262. {
  2263. int erow = (Convert.ToInt16(Math.Floor(mapslices * entity.percentX)));
  2264. int ecolumn = ((mapslices - 1) - Convert.ToInt16(Math.Floor(mapslices * entity.percentZ)));
  2265.  
  2266. if (ecolumn == (currentz + r) && erow == (currentx + c))
  2267. {
  2268. double _sx = Convert.ToSingle(c * (1f / col));
  2269. double _sy = Convert.ToSingle(1 - ((1f / row) * (r + 1)));
  2270. double _ex = Convert.ToSingle(((c + 1) * (1f / col)) - 0.005f);
  2271. double _ey = Convert.ToSingle((1 - ((1f / row) * (r + 1)) + (1f / row)) - 0.004f);
  2272. double mapXX = (entity.percentX * mapslices) - erow;
  2273. double mapZZ = ((1 - entity.percentZ) * mapslices) - ecolumn;
  2274. double _xd = _ex - _sx;
  2275. mapXX = (mapXX * _xd) + _sx;
  2276. double _yd = _ey - _sy;
  2277. mapZZ = _ey - (mapZZ * _yd);
  2278.  
  2279. gui.png("{parent}", "Ent" + DateTime.Now.Ticks, fetchImage(entity.icon), (mapXX - iconsize) + " " + (mapZZ - iconsize), (mapXX + iconsize) + " " + (mapZZ + iconsize), "1");
  2280. }
  2281. }
  2282. }
  2283. }
  2284.  
  2285. if (showplayers)
  2286. {
  2287. // Admin View, just add everyone...
  2288. if (user.adminView)
  2289. {
  2290. foreach (BasePlayer other in BasePlayer.activePlayerList)
  2291. {
  2292. // Skip self
  2293. if (other.userID == player.userID) { continue; }
  2294.  
  2295. MapLocation otherEntity;
  2296. if (!playerLocations.TryGetValue(other.userID, out otherEntity)) { continue; }
  2297.  
  2298. int erow = (Convert.ToInt16(Math.Floor(mapslices * otherEntity.percentX)));
  2299. int ecolumn = ((mapslices - 1) - Convert.ToInt16(Math.Floor(mapslices * otherEntity.percentZ)));
  2300.  
  2301. if (ecolumn == (currentz + r) && erow == (currentx + c))
  2302. {
  2303. double _sx = Convert.ToSingle(c * (1f / col));
  2304. double _sy = Convert.ToSingle(1 - ((1f / row) * (r + 1)));
  2305. double _ex = Convert.ToSingle(((c + 1) * (1f / col)) - 0.005f);
  2306. double _ey = Convert.ToSingle((1 - ((1f / row) * (r + 1)) + (1f / row)) - 0.004f);
  2307. double mapXX = (otherEntity.percentX * mapslices) - erow;
  2308. double mapZZ = ((1 - otherEntity.percentZ) * mapslices) - ecolumn;
  2309. double _xd = _ex - _sx;
  2310. mapXX = (mapXX * _xd) + _sx;
  2311. double _yd = _ey - _sy;
  2312. mapZZ = _ey - (mapZZ * _yd);
  2313.  
  2314. gui.png("{parent}", "Fnd" + DateTime.Now.Ticks, fetchImage(otherEntity.icon.Replace("{icon}", "other")), (mapXX - iconsize) + " " + (mapZZ - iconsize), (mapXX + iconsize) + " " + (mapZZ + iconsize), "1");
  2315. }
  2316. }
  2317. }
  2318. // Friends
  2319. else if (user.friends.Count > 0)
  2320. {
  2321. foreach (KeyValuePair<ulong, string> pair in user.friends)
  2322. {
  2323. MapLocation friendEntity;
  2324. if (!playerLocations.TryGetValue(pair.Key, out friendEntity)) { continue; }
  2325.  
  2326. int erow = (Convert.ToInt16(Math.Floor(mapslices * friendEntity.percentX)));
  2327. int ecolumn = ((mapslices - 1) - Convert.ToInt16(Math.Floor(mapslices * friendEntity.percentZ)));
  2328.  
  2329. if (ecolumn == (currentz + r) && erow == (currentx + c))
  2330. {
  2331. double _sx = Convert.ToSingle(c * (1f / col));
  2332. double _sy = Convert.ToSingle(1 - ((1f / row) * (r + 1)));
  2333. double _ex = Convert.ToSingle(((c + 1) * (1f / col)) - 0.005f);
  2334. double _ey = Convert.ToSingle((1 - ((1f / row) * (r + 1)) + (1f / row)) - 0.004f);
  2335. double mapXX = (friendEntity.percentX * mapslices) - erow;
  2336. double mapZZ = ((1 - friendEntity.percentZ) * mapslices) - ecolumn;
  2337. double _xd = _ex - _sx;
  2338. mapXX = (mapXX * _xd) + _sx;
  2339. double _yd = _ey - _sy;
  2340. mapZZ = _ey - (mapZZ * _yd);
  2341.  
  2342. gui.png("{parent}", "Fnd" + DateTime.Now.Ticks, fetchImage(friendEntity.icon.Replace("{icon}", pair.Value)), (mapXX - iconsize) + " " + (mapZZ - iconsize), (mapXX + iconsize) + " " + (mapZZ + iconsize), "1");
  2343. }
  2344. }
  2345. }
  2346.  
  2347. // Player
  2348. int prow = (Convert.ToInt16(Math.Floor(mapslices * mapX)));
  2349. int pcolumn = ((mapslices - 1) - Convert.ToInt16(Math.Floor(mapslices * mapZ)));
  2350.  
  2351. if (pcolumn == (currentz + r) && prow == (currentx + c))
  2352. {
  2353. double _sx = Convert.ToSingle(c * (1f / col));
  2354. double _sy = Convert.ToSingle(1 - ((1f / row) * (r + 1)));
  2355. double _ex = Convert.ToSingle(((c + 1) * (1f / col)) - 0.005f);
  2356. double _ey = Convert.ToSingle((1 - ((1f / row) * (r + 1)) + (1f / row)) - 0.004f);
  2357. double mapXX = (mapX * mapslices) - prow;
  2358. double mapZZ = ((1 - mapZ) * mapslices) - pcolumn;
  2359. double _xd = _ex - _sx;
  2360. mapXX = (mapXX * _xd) + _sx;
  2361. double _yd = _ey - _sy;
  2362. mapZZ = _ey - (mapZZ * _yd);
  2363.  
  2364. gui.png("{parent}", "Player" + DateTime.Now.Ticks, fetchImage("self" + playerdirection), (mapXX - iconsize) + " " + (mapZZ - iconsize), (mapXX + iconsize) + " " + (mapZZ + iconsize));
  2365. }
  2366. }
  2367. }
  2368. }
  2369. }
  2370. else
  2371. {
  2372. if (activeEntities.Count > 0)
  2373. {
  2374. foreach (ActiveEntity entity in activeEntities)
  2375. {
  2376. if ((entity.isplane && showplane && user.mapPlane) || (entity.isheli && showheli && user.mapHeli) || (entity.issupply && showsupply && user.mapSupply) || (entity.isdebris && showdebris && user.mapDebris))
  2377. {
  2378. if (entity.percentX >= 0 && entity.percentX <= 1 && entity.percentZ >= 0 && entity.percentZ <= 1)
  2379. {
  2380. gui.png("{parent}", "Ent" + DateTime.Now.Ticks, fetchImage(entity.icon), (entity.percentX - iconsize) + " " + (entity.percentZ - iconsize), (entity.percentX + iconsize) + " " + (entity.percentZ + iconsize));
  2381. }
  2382. }
  2383. }
  2384. }
  2385. if (showplayers)
  2386. {
  2387. // Admin View, just add everyone...
  2388. if (user.adminView)
  2389. {
  2390. foreach (BasePlayer other in BasePlayer.activePlayerList)
  2391. {
  2392. // Skip self
  2393. if (other.userID == player.userID) { continue; }
  2394.  
  2395. MapLocation otherEntity;
  2396. if (!playerLocations.TryGetValue(other.userID, out otherEntity)) { continue; }
  2397.  
  2398. if (otherEntity.percentX >= 0 && otherEntity.percentX <= 1 && otherEntity.percentZ >= 0 && otherEntity.percentZ <= 1)
  2399. {
  2400. gui.png("{parent}", "Fnd" + DateTime.Now.Ticks, fetchImage(otherEntity.icon.Replace("{icon}", "other")), (otherEntity.percentX - iconsize) + " " + (otherEntity.percentZ - iconsize), (otherEntity.percentX + iconsize) + " " + (otherEntity.percentZ + iconsize));
  2401. }
  2402. }
  2403. }
  2404. // Check for Friends...
  2405. else if (user.friends.Count > 0)
  2406. {
  2407. foreach (KeyValuePair<ulong, string> pair in user.friends)
  2408. {
  2409. MapLocation friendEntity;
  2410. if (!playerLocations.TryGetValue(pair.Key, out friendEntity)) { continue; }
  2411.  
  2412. if (friendEntity.percentX >= 0 && friendEntity.percentX <= 1 && friendEntity.percentZ >= 0 && friendEntity.percentZ <= 1)
  2413. {
  2414. gui.png("{parent}", "Fnd" + DateTime.Now.Ticks, fetchImage(friendEntity.icon.Replace("{icon}", pair.Value)), (friendEntity.percentX - iconsize) + " " + (friendEntity.percentZ - iconsize), (friendEntity.percentX + iconsize) + " " + (friendEntity.percentZ + iconsize));
  2415. }
  2416. }
  2417. }
  2418. gui.png("{parent}", "Player" + DateTime.Now.Ticks, fetchImage("self" + playerdirection), (mapX - iconsize) + " " + (mapZ - iconsize), (mapX + iconsize) + " " + (mapZ + iconsize));
  2419. }
  2420. }
  2421. if (user.compass)
  2422. {
  2423. gui.text("{parent}", "Location", TextAnchor.UpperCenter, "<size=12>" + txtCpsHead + " " + direction + "\n" + player.transform.position + "</size>", "0 -0.2", "1 0");
  2424. }
  2425. gui.send(player);
  2426. }
  2427. }
  2428. }
  2429.  
  2430. // Remove Special Characters
  2431. public static string RemoveSpecialCharacters(string str)
  2432. {
  2433. StringBuilder sb = new StringBuilder();
  2434. foreach (char c in str)
  2435. {
  2436. if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= 'А' && c <= 'Я') || (c >= 'а' && c <= 'я') || c == '.' || c == '_')
  2437. {
  2438. sb.Append(c);
  2439. }
  2440. }
  2441. return sb.ToString();
  2442. }
  2443.  
  2444. // GUI Class
  2445. private class GUIv4
  2446. {
  2447. string guiname { get; set; }
  2448. CuiElementContainer container = new CuiElementContainer();
  2449.  
  2450. public void add(string uiname, bool mouse, string start, string end, string colour)
  2451. {
  2452. guiname = uiname;
  2453. if (mouse)
  2454. {
  2455. CuiElement element = new CuiElement
  2456. {
  2457. Name = guiname,
  2458. Parent = "HUD/Overlay",
  2459. FadeOut = 0.0f,
  2460. Components =
  2461. {
  2462. new CuiImageComponent
  2463. {
  2464. Color = colour
  2465. },
  2466. new CuiRectTransformComponent
  2467. {
  2468. AnchorMin = start,
  2469. AnchorMax = end
  2470. },
  2471. new CuiNeedsCursorComponent()
  2472. }
  2473. };
  2474. container.Add(element);
  2475. }
  2476. else
  2477. {
  2478. CuiElement element = new CuiElement
  2479. {
  2480. Name = guiname,
  2481. Parent = "HUD/Overlay",
  2482. FadeOut = 0.0f,
  2483. Components =
  2484. {
  2485. new CuiImageComponent
  2486. {
  2487. Color = colour
  2488. },
  2489. new CuiRectTransformComponent
  2490. {
  2491. AnchorMin = start,
  2492. AnchorMax = end
  2493. }
  2494. }
  2495. };
  2496. container.Add(element);
  2497. }
  2498. }
  2499.  
  2500. public void box(string uiparent, string uiname, string start, string end, string colour)
  2501. {
  2502. if (uiparent == "{parent}") { uiparent = guiname; } else { uiparent += "{rand}"; }
  2503.  
  2504. CuiElement element = new CuiElement
  2505. {
  2506. Name = uiname + "{rand}",
  2507. Parent = uiparent,
  2508. FadeOut = 0.0f,
  2509. Components =
  2510. {
  2511. new CuiImageComponent
  2512. {
  2513. Color = colour
  2514. },
  2515. new CuiRectTransformComponent
  2516. {
  2517. AnchorMin = start,
  2518. AnchorMax = end
  2519. }
  2520. }
  2521. };
  2522. container.Add(element);
  2523. }
  2524.  
  2525. public void text(string uiparent, string uiname, UnityEngine.TextAnchor textalign, string uitext, string start, string end)
  2526. {
  2527. if (uiparent == "{parent}") { uiparent = guiname; } else { uiparent += "{rand}"; }
  2528.  
  2529. CuiElement element = new CuiElement
  2530. {
  2531. Name = uiname + "{rand}",
  2532. Parent = uiparent,
  2533. FadeOut = 0.0f,
  2534. Components =
  2535. {
  2536. new CuiTextComponent
  2537. {
  2538. Text = uitext,
  2539. FontSize = 12,
  2540. Align = textalign,
  2541. FadeIn = 0.0f
  2542. },
  2543. new CuiRectTransformComponent
  2544. {
  2545. AnchorMin = start,
  2546. AnchorMax = end
  2547. }
  2548. }
  2549. };
  2550. container.Add(element);
  2551. }
  2552.  
  2553. public void png(string uiparent, string uiname, string image, string start, string end, string colour = "1 1 1 1")
  2554. {
  2555. if (string.IsNullOrEmpty(image)) return;
  2556. if (uiparent == "{parent}") { uiparent = guiname; } else { uiparent += "{rand}"; }
  2557.  
  2558. CuiElement element = new CuiElement
  2559. {
  2560. Name = uiname + "{rand}",
  2561. Parent = uiparent,
  2562. FadeOut = 0.0f,
  2563. Components =
  2564. {
  2565. new CuiRawImageComponent
  2566. {
  2567. Sprite = "assets/content/textures/generic/fulltransparent.tga",
  2568. Png = image,
  2569. FadeIn = 0.0f
  2570. },
  2571. new CuiRectTransformComponent
  2572. {
  2573. AnchorMin = start,
  2574. AnchorMax = end
  2575. }
  2576. }
  2577. };
  2578. container.Add(element);
  2579. }
  2580.  
  2581. public void button(string uiparent, string uiname, UnityEngine.TextAnchor textalign, string uitext, bool closeui, string cmd, string start, string end, string colour)
  2582. {
  2583. box(uiparent, uiname + "BoX", start, end, colour);
  2584. text(uiparent, uiname + "TxT", textalign, uitext, start, end);
  2585.  
  2586. if (uiparent == "{parent}") { uiparent = guiname; } else { uiparent += "{rand}"; }
  2587. string closegui = null;
  2588. if (closeui) { closegui = guiname; }
  2589.  
  2590. CuiElement element = new CuiElement
  2591. {
  2592. Name = uiname + "{rand}",
  2593. Parent = uiparent,
  2594. FadeOut = 0.0f,
  2595. Components =
  2596. {
  2597. new CuiButtonComponent
  2598. {
  2599. Command = cmd,
  2600. Close = closegui,
  2601. Color = "0 0 0 0"
  2602. },
  2603. new CuiRectTransformComponent
  2604. {
  2605. AnchorMin = start,
  2606. AnchorMax = end
  2607. }
  2608. }
  2609. };
  2610. container.Add(element);
  2611. }
  2612.  
  2613. public void send(BasePlayer player)
  2614. {
  2615. CuiHelper.DestroyUi(player, guiname);
  2616. CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "AddUI", new Facepunch.ObjectList(container.ToJson().Replace("{rand}", DateTime.Now.Ticks.ToString())));
  2617. }
  2618. }
  2619.  
  2620. // Player Messages
  2621. private void playerMsg(BasePlayer player, string msg)
  2622. {
  2623. SendReply(player, String.Format("<color=#008080ff>Lusty Map</color>: {0}", msg));
  2624. }
  2625.  
  2626. private void globalMsg(string msg)
  2627. {
  2628. PrintToChat(String.Format("<color=#008080ff>Lusty Map</color>: {0}", msg));
  2629. }
  2630.  
  2631. // Permissions Check
  2632. private bool isAdmin(BasePlayer player)
  2633. {
  2634. if (player.net.connection.authLevel >= 1)
  2635. {
  2636. return true;
  2637. }
  2638. return false;
  2639. }
  2640.  
  2641. // Config stuff
  2642. private void LoadDefaultConfig() { }
  2643.  
  2644. // Get config item
  2645. private object get(string item, string subitem)
  2646. {
  2647. try
  2648. {
  2649. if (Config[item, subitem] != null)
  2650. {
  2651. return Config[item, subitem];
  2652. }
  2653. }
  2654. catch
  2655. {
  2656. return null;
  2657. }
  2658. return null;
  2659. }
  2660.  
  2661. // Set config item
  2662. private void set(string item, string subitem, object data, bool overwrite = true)
  2663. {
  2664. try
  2665. {
  2666. if (!overwrite & Config[item, subitem] == null)
  2667. {
  2668. Config[item, subitem] = data;
  2669. }
  2670. else if (overwrite)
  2671. {
  2672. Config[item, subitem] = data;
  2673. }
  2674. SaveConfig();
  2675. }
  2676. catch
  2677. {
  2678.  
  2679. }
  2680. }
  2681.  
  2682. // Clear config item
  2683. private void clear(string item, string subitem)
  2684. {
  2685. try
  2686. {
  2687. Config[item, subitem] = null;
  2688. SaveConfig();
  2689. }
  2690. catch
  2691. {
  2692.  
  2693. }
  2694. }
  2695. }
  2696. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement