1. Hey. I want to spawn an item at a random location. How to randomize coordinates?
     
  2. new Vector3(Oxide.Core.Random.Range(-worldSize^2/2, worldSize^2/2), 1000, Oxide.Core.Random.Range(-worldSize^2/2, worldSize^2/2)).
    Then raycast from your Vector3, to Vector3.Down, to find terrain point and spawn it here.

    It can be underwater, but you check it, if point.y<0, then make again while point .y >0
     
  3. You can use TerrainMeta.HeightMap.GetHeight(position) to get the terrain height (y) for a position, then use WaterLevel.Test(position) to check for water. You don't have to deal with a raycast this way, and I believe WaterLevel.Test also detects rivers (not just ocean).
     
  4. Alright thanks guys :)
     
  5. How exactly do I use the WaterLevel.Test though?
     
  6. I'm pretty sure that if you pass a point to it and it returns true then that point is under water, but I can't recall if it looks at the xyz or just the xz coordinates... You'll have to test it out to confirm, or maybe check if the code gives more insight...
     
  7. Got it working using

    Code:
    bool wtest = WaterLevel.Test(pos);
                  
                    if (wtest == false) {
                   Do stuff
                   }
                  else return;
    
    Thanks for your help. :)
     
  8. How can I make it so the random location I generate isn't near monuments?
     
  9. Code:
                Vector3 pos = new Vector3(); // your random position
                bool isNearMonument = false;
                foreach (MonumentInfo monument in UnityEngine.Object.FindObjectsOfType<MonumentInfo>().OrderBy(o => o.name))
                {
                    float distance = Vector3.Distance(pos, monument.transform.position);
                    if (distance < 10)
                    {
                        isNearMonument = true;
                        break;
                    }
                }            if (isNearMonument)
                {
                    // TODO try another position
                }
     
  10. Thanks dude :)

    Is there also a way to avoid spawning near cliffs?
     
    Last edited by a moderator: Mar 21, 2018
  11. Solved.