Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Oxide.Core;
- using Newtonsoft.Json;
- using UnityEngine;
- namespace Oxide.Plugins
- {
- public class SpawnInfo
- {
- public string Name;
- public List<vec2> coords;
- public SpawnInfo()
- {
- coords = new List<vec2>();
- }
- }
- public class vec2
- {
- public float x;
- public float y;
- public vec2(float x_, float y_)
- {
- x = x_;
- y = y_;
- }
- }
- [Info("MiniPlugin", "therapy", 0.1)]
- [Description("Tool Plugin for Map Extraction")]
- class MiniPlugin : HurtworldPlugin
- {
- void RenderMap()
- {
- Dictionary<string, List<vec2>> dots = new Dictionary<string,List<vec2>>();
- for (float x = -4000.0f; x < 4000.0f; x += 2.0f)
- {
- for (float y = -4000.0f; y < 4000.0f; y += 2.0f)
- {
- RaycastHit hitInfo;
- //Send a ray from (x,y) at height 1000.0 units downwards and see what it hits
- Vector3 start = new Vector3(x, 1000.0f,y);
- if (Physics.Raycast(new Ray(start, Vector3.down), out hitInfo,2000.0f))
- {
- //Puts("Ray hit " + hitInfo.transform.name + " Collider: " + hitInfo.collider.name);
- string name = hitInfo.collider.name;
- //Exclude this collider because it appears so often that the JSON renderer will die
- //with Out Of Memory exception...
- if (name == "DesertTerrain_split0")
- continue;
- //Add pixel information for this collider to the list
- if (!dots.ContainsKey(name))
- dots[name] = new List<vec2>();
- dots[name].Add(new vec2(x, y));
- }
- }
- }
- //Write the JSON file, this is going to be huge (depending on resolution of the for-loops above, this will hit 150MB+
- Oxide.Core.Configuration.DynamicConfigFile file = Interface.GetMod().DataFileSystem.GetDatafile("map");
- file["dots"] = dots;
- file.Save();
- }
- void DumpStuff()
- {
- //Get the CreateSpawnDirector, the class responsible for deserializing the map data
- CreatureSpawnDirector spawnDirector = UnityEngine.Object.FindObjectOfType<CreatureSpawnDirector>();
- //This will contain the output
- List<SpawnInfo> output = new List<SpawnInfo>();
- //Iterate over each spawn configuration
- //Each spawn configuration represents one type of node (i.e. "IronRockResourceNodeServer") and contain a list
- //of each cell this can spawn in as well as its spawn rate (ignored here)
- foreach (SpawnConfiguration spawnConfig in spawnDirector.SpawnConfigs)
- {
- Puts("Node type: " + spawnConfig.Object.name);
- SpawnInfo info = new SpawnInfo();
- info.Name = spawnConfig.Object.name;
- //Now iterate over each cell spawn info
- foreach (KeyValuePair<int, int> spawnRate in spawnConfig.CellSpawnRates)
- {
- // Puts(" Spawning in cell " + spawnRate.Key + " with coords: " + Singleton<PlayerActivityGrid>.Instance.CellManager.GetCellCenter(spawnRate.Key));
- //Node that the actual position is randomized inside a given cell, so for mapping purposes I just get the center
- //coordinates
- UnityEngine.Vector2 foolol = Singleton<PlayerActivityGrid>.Instance.CellManager.GetCellCenter(spawnRate.Key);
- info.coords.Add(new vec2(foolol.x, foolol.y));
- }
- output.Add(info);
- }
- Oxide.Core.Configuration.DynamicConfigFile file = Interface.GetMod().DataFileSystem.GetDatafile("resource_dump");
- file["nodes"] = output;
- file.Save();
- Puts("Dumped objects.");
- }
- void OnServerInitialized()
- {
- Puts("Server ready.");
- //Uncomment whatever you want here:
- //This dumps the resource JSON
- //DumpStuff();
- //This dumps the map JSON
- //RenderMap();
- }
- }
- }
Add Comment
Please, Sign In to add comment