Resource Spawner

hunternope3

Plugin Developer
Plugin Developer
Mar 22, 2015
36
46
8
35
@hunternope3 - So if I understand proper you was just wrong. You can't build house like was on my server and get there automatically respawned crates. No matter if you use fougerite or not. You can loop spawning what is possible easy with fougerite, but you can't just add crates what will respawn when they are taken by player. You would need hook for that like I wrote couple post before.
as far as i know by looking at the decompiled assembly this class handles the original crate spawning:

C#:
public class LootableObjectSpawner : MonoBehaviour
{
    public ChancePick[] _lootableChances;
    [NonSerialized]
    private GameObject _mySpawnedLootable;
    public bool spawnOnStart = true;
    public float spawnTimeMax = 10f;
    public float spawnTimeMin = 5f;

    private void Awake()
    {
        if ((this._lootableChances == null) || (this._lootableChances.Length == 0))
        {
            Object.Destroy(base.gameObject);
        }
    }

    public void OnDrawGizmos()
    {
        Gizmos.color = Color.green;
        Gizmos.DrawSphere(base.transform.position, 0.5f);
        Gizmos.color = Color.blue;
        Gizmos.DrawLine(base.transform.position, base.transform.position + ((Vector3) (base.transform.forward * 1f)));
    }

    public void OnDrawGizmosSelected()
    {
        Gizmos.color = Color.yellow;
        Gizmos.DrawSphere(base.transform.position, 0.5f);
        Gizmos.color = Color.blue;
        Gizmos.DrawLine(base.transform.position, base.transform.position + ((Vector3) (base.transform.forward * 1f)));
    }

    private void OnServerLoad()
    {
        if (this.spawnOnStart)
        {
            this.SpawnLootable();
        }
        else
        {
            base.Invoke("SpawnLootable", this.spawnTimeMax * 60f);
        }
    }

    public static LootableObject RandomPick(ChancePick[] array)
    {
        float max = 0f;
        foreach (ChancePick pick in array)
        {
            max += pick.weight;
        }
        if (max == 0f)
        {
            return null;
        }
        float num3 = Random.Range(0f, max);
        foreach (ChancePick pick2 in array)
        {
            num3 -= pick2.weight;
            if (num3 <= 0f)
            {
                return pick2.obj;
            }
        }
        return array[array.Length - 1].obj;
    }

    private GameObject SpawnLootable()
    {
        Vector3 vector;
        Vector3 vector2;
        float num = Random.Range(this.spawnTimeMin, this.spawnTimeMax);
        base.CancelInvoke("SpawnLootable");
        base.Invoke("SpawnLootable", num * 60f);
        if (this._mySpawnedLootable != null)
        {
            return null;
        }
        LootableObject prefab = RandomPick(this._lootableChances);
        if (prefab == null)
        {
            Debug.Log("MAJOR WTF");
        }
        base.transform.GetGroundInfo(out vector, out vector2);
        Quaternion quaternion = Quaternion.LookRotation(vector2);
        Quaternion quaternion2 = Quaternion.Inverse(prefab.transform.GetChild(0).localRotation);
        LootableObject obj3 = NetCull.InstantiateStatic<LootableObject>(prefab, vector, quaternion * quaternion2);
        this._mySpawnedLootable = obj3.gameObject;
        return obj3.gameObject;
    }

    [Serializable]
    public class ChancePick
    {
        public LootableObject obj;
        public float weight;
    }
}
im not 100% sure that it is actually used by the game. But looking at the SpawnLootAble() method you can see that it calls the same method through monobehaivour again after a random in range time amount. (explains why the crates keep on respawning)

i tried to create a new lootableobjectspawner and calling te same method through reflection (While all values where assinged properly) but it brakes calling base.CancelInvoke().

(i will do some more tests later on)

however as i stated before a quick solution would be to simmulate the processses.
 
Last edited:

hunternope3

Plugin Developer
Plugin Developer
Mar 22, 2015
36
46
8
35
Naah! I want to make autorespawn for spawned crate! Like original crates in Rust RAD zones
to clarify, you are talking about wooden storage boxes or large wooden storage boxes?

if so then no, you cannot do this at the moment with the current hooks.
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,066
4,462
113
At your house.
github.com
as far as i know by looking at the decompiled assembly this class handles the original crate spawning:

C#:
public class LootableObjectSpawner : MonoBehaviour
{
    public ChancePick[] _lootableChances;
    [NonSerialized]
    private GameObject _mySpawnedLootable;
    public bool spawnOnStart = true;
    public float spawnTimeMax = 10f;
    public float spawnTimeMin = 5f;

    private void Awake()
    {
        if ((this._lootableChances == null) || (this._lootableChances.Length == 0))
        {
            Object.Destroy(base.gameObject);
        }
    }

    public void OnDrawGizmos()
    {
        Gizmos.color = Color.green;
        Gizmos.DrawSphere(base.transform.position, 0.5f);
        Gizmos.color = Color.blue;
        Gizmos.DrawLine(base.transform.position, base.transform.position + ((Vector3) (base.transform.forward * 1f)));
    }

    public void OnDrawGizmosSelected()
    {
        Gizmos.color = Color.yellow;
        Gizmos.DrawSphere(base.transform.position, 0.5f);
        Gizmos.color = Color.blue;
        Gizmos.DrawLine(base.transform.position, base.transform.position + ((Vector3) (base.transform.forward * 1f)));
    }

    private void OnServerLoad()
    {
        if (this.spawnOnStart)
        {
            this.SpawnLootable();
        }
        else
        {
            base.Invoke("SpawnLootable", this.spawnTimeMax * 60f);
        }
    }

    public static LootableObject RandomPick(ChancePick[] array)
    {
        float max = 0f;
        foreach (ChancePick pick in array)
        {
            max += pick.weight;
        }
        if (max == 0f)
        {
            return null;
        }
        float num3 = Random.Range(0f, max);
        foreach (ChancePick pick2 in array)
        {
            num3 -= pick2.weight;
            if (num3 <= 0f)
            {
                return pick2.obj;
            }
        }
        return array[array.Length - 1].obj;
    }

    private GameObject SpawnLootable()
    {
        Vector3 vector;
        Vector3 vector2;
        float num = Random.Range(this.spawnTimeMin, this.spawnTimeMax);
        base.CancelInvoke("SpawnLootable");
        base.Invoke("SpawnLootable", num * 60f);
        if (this._mySpawnedLootable != null)
        {
            return null;
        }
        LootableObject prefab = RandomPick(this._lootableChances);
        if (prefab == null)
        {
            Debug.Log("MAJOR WTF");
        }
        base.transform.GetGroundInfo(out vector, out vector2);
        Quaternion quaternion = Quaternion.LookRotation(vector2);
        Quaternion quaternion2 = Quaternion.Inverse(prefab.transform.GetChild(0).localRotation);
        LootableObject obj3 = NetCull.InstantiateStatic<LootableObject>(prefab, vector, quaternion * quaternion2);
        this._mySpawnedLootable = obj3.gameObject;
        return obj3.gameObject;
    }

    [Serializable]
    public class ChancePick
    {
        public LootableObject obj;
        public float weight;
    }
}
im not 100% sure that it is actually used by the game. But looking at the SpawnLootAble() method you can see that it calls the same method through monobehaivour again after a random in range time amount. (explains why the crates keep on respawning)

i tried to create a new lootableobjectspawner and calling te same method through reflection (While all values where assinged properly) but it brakes calling base.CancelInvoke().

(i will do some more tests later on)

however as i stated before a quick solution would be to simmulate the processses.
It uses It, but the loot gets in the LootSpawnList