ID:1693571
 
So, i'm a zombie survival inspired by DayZ and i want to make a system like DayZ that spawns a object in the map every so to say 10 minutes. What are the ways i can do this. I've been thinking world procs but also turf procs can do the same thing. So, which way is best and why?
I think you'd want to create invisible objects called spawners. Spawners have a variable called drops. Drops of course is a list of what it can drop.

Now you'd edit Spawner/New() so that you can run a loop that spawns objects when a Spawner is created.
A spawner might be a good idea to implement. If an object was randomly spawned anywhere in the world, it could spawn in walls and unreachable areas.

You could also use the /area datum and change the areas of which you would like to have as places to spawn things. Then, iterate through area.contents for the turfs and randomly pick one of those.

global.SpawnObject() can be placed in a world ticker (which you could make sleep every ten minutes).

proc/SpawnObject(T)
var/area/spawnable/a = locate(/area/spawnable)
a.SpawnObject(T)

area
spawnable
proc/SpawnObject(T)
var/list/l = new()
for (var/turf/t in contents)
l += t

if (l.len)
var/d = rand(1, l.len)
var/turf/t = l[d]
new T(t)
There are several ways to approach this.


One good method I can think of is manually placing nodes on the map, that way you have control over where they'll spawn, so they don't spawn somewhere ridiculous like on the roof.

Another way of doing this is placing all of the tiles you want into a global list, and then choose a random tile from that list to spawn said item.
In response to Mr_Goober
Mr_Goober wrote:
A spawner might be a good idea to implement. If an object was randomly spawned anywhere in the world, it could spawn in walls and unreachable areas.

You could also use the /area datum and change the areas of which you would like to have as places to spawn things. Then, iterate through area.contents for the turfs and randomly pick one of those.

global.SpawnObject() can be placed in a world ticker (which you could make sleep every ten minutes).

> proc/SpawnObject(T)
> var/area/spawnable/a = locate(/area/spawnable)
> a.SpawnObject(T)
>
> area
> spawnable
> proc/SpawnObject(T)
> var/list/l = new()
> for (var/turf/t in contents)
> l += t
>
> if (l.len)
> var/d = rand(1, l.len)
> var/turf/t = l[d]
> new T(t)
>


This code, doesn't seem like it will make me choose what to spawn.
In his example, you call SpawnObject, and pass in the type of object you want to spawn.
so like?
var/list/l = new(/obj/Food/TacticalBacon)
SpawnObject(/mob/zombie) // considering /mob/zombie needs to be defined first
Oh understood thank you very much! Goober.
The code doesn't really work.
Do you have the spawnable area defined and placed?
In response to Mightymo
Mightymo wrote:
Do you have the spawnable area defined and placed?

Indeed in order to have them spawn in the map there needs to be some sort of region of /area/spawnable.
I did have them but they didn't spawn at all.
In response to Mr_Goober
> proc/SpawnObject(T)
> var/area/spawnable/a = locate(/area/spawnable)
> a.SpawnObject(T)
>
> area
> spawnable
> proc/SpawnObject(T)
> var/list/l = new()
> for (var/turf/t in src)
> l += t
>
> if (l.len)
> new T(pick(l))
>


Slightly shrank the code a bit.

Ztars: Are you placing the /area/spawnable in your map where you want items to spawn? Do items properly show up/display if you place them in manually in the map editor?

How are you calling SpawnObject()?
world
proc
GenerateItms()
var/PS = pick(/obj/Clothing/SwatHelmet,/obj/Misc/Empty_Blood_Bag,/obj/Clothing/BlueBeanie)
SpawnObject(PS)
Hey, can I play too?

Where are you calling GenerateItms()?
Guys, can we forget this, i made a easier Generating system with objects instead of areas. I think that the problem was with the area not the programming. Also, anyone has ideas on how to add a prob to a pick prob? Like a prob to generate a Swat helmet.
In response to FallenZtars
Are you asking for a "weighted pick", where each item has a certain weight that can make one item more rare/common than the others? I'm pretty sure I've seen that before. I suggest using the forum search.
Yeah. Thanks, i'll search the forum.
Thanks, Kaiochao. I found it.