Resource Spawner

MasterPeace

Retired Staff
Retired Staff
Feb 2, 2015
269
68
28
44
Poland
Resource spawner is easy as shit (remember my loot crates and flares?) the problem is when you want to have spawn points, not just commands. If someone kill chicken, respawn it somewhere else after some time. If someone find loot crate respawn it. Then it getting hard :)

Because how many time you will use some resource spawner what needs your commands and being online to work?

But if we could have
Code:
On_CrateOpened (and disappear, even better wow)
  Get crate ID
  Datastore crate_ID = 0

Timer 30 minutes
  if crate_ID = 0
    respawn
 

hunternope3

Plugin Developer
Plugin Developer
Mar 22, 2015
36
46
8
35
Resource spawner is easy as shit (remember my loot crates and flares?) the problem is when you want to have spawn points, not just commands. If someone kill chicken, respawn it somewhere else after some time. If someone find loot crate respawn it. Then it getting hard :)

Because how many time you will use some resource spawner what needs your commands and being online to work?

But if we could have
Code:
On_CrateOpened (and disappear, even better wow)
  Get crate ID
  Datastore crate_ID = 0

Timer 30 minutes
  if crate_ID = 0
    respawn
it's possible to modify the DatablockDictionary._lootSpawnLists. By doing you can modify the item dorp table of a chest.
 
Last edited:

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,066
4,462
113
At your house.
github.com
Resource spawner is easy as shit (remember my loot crates and flares?) the problem is when you want to have spawn points, not just commands. If someone kill chicken, respawn it somewhere else after some time. If someone find loot crate respawn it. Then it getting hard :)

Because how many time you will use some resource spawner what needs your commands and being online to work?

But if we could have
Code:
On_CrateOpened (and disappear, even better wow)
  Get crate ID
  Datastore crate_ID = 0

Timer 30 minutes
  if crate_ID = 0
    respawn
I dunno if this was a flaming but I never said that doing a resource spawner is hard.
 

MasterPeace

Retired Staff
Retired Staff
Feb 2, 2015
269
68
28
44
Poland
@DreTaX - I'm just talking. I saw thread with resource spawning topic so I posted one of my old problems - maybe some day it will be possible with FG, or it will inspire you to do this function in your plugin, whatever. We just talking here. Don't think that I'm your hater or something haha :p

@hunternope3 - You mean we can do that already? Like set loot spawn and make it respawn after some time BUT only when it has been taken? Could you show some example?
 
  • Like
Reactions: DreTaX

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,066
4,462
113
At your house.
github.com
Turns out .NET 3.5 fucked me up. I literally solved the problem by getting the IronPython.Modules referenced, but that requires an mscorlib.dll reference. Its not a problem but 3.5 doesn't contain a class that It needs....

This shit could have solved the imports of the py files and dlls....-.-
 

hunternope3

Plugin Developer
Plugin Developer
Mar 22, 2015
36
46
8
35
Wait you are telling that you can hook inside there and get a chest open event without adding an extra hook?
^^
No I haven't found a way to get a chest open event. but you can modify the lootspawntable
----
let's assume that you will only use the standard ammo/wood/med/wep boxes (and the ones you spawn with world.spawn). you can modify the item drop table.

DatablockDictionary._lootSpawnLists

example:
http://oxidemod.org/plugins/loot-spawn-lists.5/download?version=4865
(code)
C#:
        void OnServerInitialized()
        {
            SpawnLists = LoadDefaultSpawnlists();
            CheckCfg<Dictionary<string, object>>("Spawnlists", ref SpawnLists);
            SaveConfig();
            PatchNewSpawnlists();
        }
        static Dictionary<string, object> LoadDefaultSpawnlists()
        {
            var tblspawnlists = new Dictionary<string, object>();
            var spawnlists = DatablockDictionary._lootSpawnLists as Dictionary<string,LootSpawnList>;
            foreach (KeyValuePair<string, LootSpawnList> pair in spawnlists)
            {
                var spawnlist = new Dictionary<string, object>();
                spawnlist.Add("min", pair.Value.minPackagesToSpawn);
                spawnlist.Add("max", pair.Value.maxPackagesToSpawn);
                spawnlist.Add("nodupes", pair.Value.noDuplicates);
                spawnlist.Add("oneofeach", pair.Value.spawnOneOfEach);
                var packages = new List<object>();
                foreach(LootSpawnList.LootWeightedEntry entry in pair.Value.LootPackages)
                {
                    var tblentry = new Dictionary<string, object>();
                    if (!entry.obj)
                        continue;
                    else
                        tblentry.Add("object", entry.obj.name);
                    tblentry.Add("weight", entry.weight);
                    tblentry.Add("min", entry.amountMin);
                    tblentry.Add("max", entry.amountMax);
                    packages.Add(tblentry);
                }
                spawnlist.Add("packages", packages);
                tblspawnlists.Add(pair.Key, spawnlist);
            }
            return tblspawnlists;
        }
        void PatchNewSpawnlists()
        {
            int cnt = 0;
            var spawnlistobjects = new Dictionary<string, LootSpawnList>();
            foreach (KeyValuePair<string, object> pair in SpawnLists)
            {
                var currentspawnlist = pair.Value as Dictionary<string, object>;
                var obj = UnityEngine.ScriptableObject.CreateInstance<LootSpawnList>();
                obj.minPackagesToSpawn = Convert.ToInt32(currentspawnlist["min"]);
                obj.maxPackagesToSpawn = Convert.ToInt32(currentspawnlist["max"]);
                obj.noDuplicates = Convert.ToBoolean(currentspawnlist["nodupes"]);
                obj.spawnOneOfEach = Convert.ToBoolean(currentspawnlist["oneofeach"]);
                obj.name = pair.Key;
                spawnlistobjects.Add(pair.Key, obj);
                cnt++;
            }
            foreach (KeyValuePair<string, object> pair in SpawnLists)
            {
                var entrylist = new List<LootSpawnList.LootWeightedEntry>();
                var currentspawnlist = pair.Value as Dictionary<string, object>;
                var packages = currentspawnlist["packages"] as List<object>;
                foreach (Dictionary<string, object> entry in packages)
                {
                    var entryobj = new LootSpawnList.LootWeightedEntry();
                    entryobj.amountMin = Convert.ToInt32(entry["min"]);
                    entryobj.amountMax = Convert.ToInt32(entry["max"]);
                    entryobj.weight = Convert.ToSingle(entry["weight"]);
                    if (spawnlistobjects.ContainsKey(entry["object"].ToString()))
                    {
                        entryobj.obj = spawnlistobjects[entry["object"].ToString()];
                    }
                    else
                    {
                        entryobj.obj = DatablockDictionary.GetByName(entry["object"].ToString());
                    }
                    entrylist.Add(entryobj);
                }
                spawnlistobjects[pair.Key].LootPackages = entrylist.ToArray();
            }
            var spawnlists = DatablockDictionary._lootSpawnLists;
            spawnlists.Clear();
            foreach (KeyValuePair<string, object> pair in SpawnLists)
            {
                spawnlists.Add(pair.Key, spawnlistobjects[pair.Key]);
            }
            Puts(string.Format("{0} custom loot tables were loaded!", cnt.ToString()));
        }

    }
}

though with fougerite you have to do this after serverinit, since serverinit hooks get triggered before the server actually loaded the datadictionary.

if you want to have specific loot in only 1 instance of a crate then you need an extra hook (or by simulation with a custom spawned box).
(assuming you only want to modify 1 weapon crate at a location)

note: the code above doesn't include editing which crate has to be spawned (picked). but you can also modify this after serverinit.
 
Last edited:

hunternope3

Plugin Developer
Plugin Developer
Mar 22, 2015
36
46
8
35
He said (sorry that I'm replying but he was writing couple days ago on my PM) that you don't need to use fougerite or oxide to that. Showed me this plugin: http://oxidemod.org/plugins/loot-spawn-lists.5/download?version=4865 but I didn't check it yet because I think I lost my oxide account or I never created it.
i forgot to mention you wont be able to spawn extra loot crates at a loctaion with this (and keep them reappearing).
i tried calling/using the gamelogic that spawns the craets though i didn't get it to work.
however you can simulate the process with a selfwritten plugin (using a timed event for example).
 
Last edited:

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,066
4,462
113
At your house.
github.com
^^
No I haven't found a way to get a chest open event. but you can modify the lootspawntable
----
let's assume that you will only use the standard ammo/wood/med/wep boxes (and the ones you spawn with world.spawn). you can modify the item drop table.

DatablockDictionary._lootSpawnLists

example:
http://oxidemod.org/plugins/loot-spawn-lists.5/download?version=4865
(code)
C#:
        void OnServerInitialized()
        {
            SpawnLists = LoadDefaultSpawnlists();
            CheckCfg<Dictionary<string, object>>("Spawnlists", ref SpawnLists);
            SaveConfig();
            PatchNewSpawnlists();
        }
        static Dictionary<string, object> LoadDefaultSpawnlists()
        {
            var tblspawnlists = new Dictionary<string, object>();
            var spawnlists = DatablockDictionary._lootSpawnLists as Dictionary<string,LootSpawnList>;
            foreach (KeyValuePair<string, LootSpawnList> pair in spawnlists)
            {
                var spawnlist = new Dictionary<string, object>();
                spawnlist.Add("min", pair.Value.minPackagesToSpawn);
                spawnlist.Add("max", pair.Value.maxPackagesToSpawn);
                spawnlist.Add("nodupes", pair.Value.noDuplicates);
                spawnlist.Add("oneofeach", pair.Value.spawnOneOfEach);
                var packages = new List<object>();
                foreach(LootSpawnList.LootWeightedEntry entry in pair.Value.LootPackages)
                {
                    var tblentry = new Dictionary<string, object>();
                    if (!entry.obj)
                        continue;
                    else
                        tblentry.Add("object", entry.obj.name);
                    tblentry.Add("weight", entry.weight);
                    tblentry.Add("min", entry.amountMin);
                    tblentry.Add("max", entry.amountMax);
                    packages.Add(tblentry);
                }
                spawnlist.Add("packages", packages);
                tblspawnlists.Add(pair.Key, spawnlist);
            }
            return tblspawnlists;
        }
        void PatchNewSpawnlists()
        {
            int cnt = 0;
            var spawnlistobjects = new Dictionary<string, LootSpawnList>();
            foreach (KeyValuePair<string, object> pair in SpawnLists)
            {
                var currentspawnlist = pair.Value as Dictionary<string, object>;
                var obj = UnityEngine.ScriptableObject.CreateInstance<LootSpawnList>();
                obj.minPackagesToSpawn = Convert.ToInt32(currentspawnlist["min"]);
                obj.maxPackagesToSpawn = Convert.ToInt32(currentspawnlist["max"]);
                obj.noDuplicates = Convert.ToBoolean(currentspawnlist["nodupes"]);
                obj.spawnOneOfEach = Convert.ToBoolean(currentspawnlist["oneofeach"]);
                obj.name = pair.Key;
                spawnlistobjects.Add(pair.Key, obj);
                cnt++;
            }
            foreach (KeyValuePair<string, object> pair in SpawnLists)
            {
                var entrylist = new List<LootSpawnList.LootWeightedEntry>();
                var currentspawnlist = pair.Value as Dictionary<string, object>;
                var packages = currentspawnlist["packages"] as List<object>;
                foreach (Dictionary<string, object> entry in packages)
                {
                    var entryobj = new LootSpawnList.LootWeightedEntry();
                    entryobj.amountMin = Convert.ToInt32(entry["min"]);
                    entryobj.amountMax = Convert.ToInt32(entry["max"]);
                    entryobj.weight = Convert.ToSingle(entry["weight"]);
                    if (spawnlistobjects.ContainsKey(entry["object"].ToString()))
                    {
                        entryobj.obj = spawnlistobjects[entry["object"].ToString()];
                    }
                    else
                    {
                        entryobj.obj = DatablockDictionary.GetByName(entry["object"].ToString());
                    }
                    entrylist.Add(entryobj);
                }
                spawnlistobjects[pair.Key].LootPackages = entrylist.ToArray();
            }
            var spawnlists = DatablockDictionary._lootSpawnLists;
            spawnlists.Clear();
            foreach (KeyValuePair<string, object> pair in SpawnLists)
            {
                spawnlists.Add(pair.Key, spawnlistobjects[pair.Key]);
            }
            Puts(string.Format("{0} custom loot tables were loaded!", cnt.ToString()));
        }

    }
}

though with fougerite you have to do this after serverinit, since serverinit hooks get triggered before the server actually loaded the datadictionary.

if you want to have specific loot in only 1 instance of a crate then you need an extra hook (or by simulation with a custom spawned box).
(assuming you only want to modify 1 weapon crate at a location)

note: the code above doesn't include editing which crate has to be spawned (picked). but you can also modify this after serverinit.
Ah okay. I thought you were talking about the chest open event.
 

MasterPeace

Retired Staff
Retired Staff
Feb 2, 2015
269
68
28
44
Poland
@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.
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,066
4,462
113
At your house.
github.com
@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.
In your place If I knew the coordinates of the chests, I would find them by that.

If I found them I would add them to an Array.

Once i stored the entity object, i would use an entitydestroyed event.

The provided entity on entitydestroyed event will be the thing that would help us. All you have to do is check if the entity is in the entity list. If Its in, remove it from the array, spawn a new one, and re add it.
 

MasterPeace

Retired Staff
Retired Staff
Feb 2, 2015
269
68
28
44
Poland
So when player pickup crate it's EntityDestroyed? That would be easy then.

I would just add crate on plugin start on map + to list and if it gets looted EntityDestroyed ----- somehow ----- write to list that it was looted and after that timer would respawn it.
 

DreTaX

Probably knows the answer...
Administrator
Jun 29, 2014
4,066
4,462
113
At your house.
github.com
Naah! I want to make autorespawn for spawned crate! Like original crates in Rust RAD zones
Aaaaaaaaaaaaaaaaaaaaa. I see:

C#:
//Method1:
            //Todo spawn your own lootstacks by prefab names, cast them to lootableobject or find them:
            LootableObject[] objects = UnityEngine.Object.FindObjectsOfType(typeof(LootableObject)) as LootableObject[];
            //Todo: Check if the inventory is empty and if it is, respawn
            foreach (LootableObject x in objects)
            {
                x._inventory. // blabla
            }
            //Method2:
            Dictionary<string, LootSpawnList> tempspawnlist = DatablockDictionary._lootSpawnLists;
            //Todo: No idea what spawnlist names are in it you should first loop the tempspawnlist.Keys to get what you need
            //Todo: Spawn your own loots, store them, check if the DatablockDictionary._lootSpawnList contains them