ID:180788
 
how do I make the game spawn objects at random?

I want to spawn a new obj every 5 secs, it should be placed at a random loc.
On 2/16/01 12:00 pm Kaidorin wrote:
how do I make the game spawn objects at random?

I want to spawn a new obj every 5 secs, it should be placed at a random loc.

This, like the combat question, is really about how to create a system.

I've developed a rather comprehensive spawning system that pretty much fills all needs...I'll put together a demo...um, as soon as Tom finishes the new system for uploading code samples. Yeah.

In the meantime, I'll suggest the same as I did for the combat: Put together a list of the steps you can think of for a spawning system, and then we'll help you with the individual steps...
In response to Deadron
One thing that confuses me about the spwn proc is how is it different from sleep?
Will it recreate a mob once it's dead after x amount of time?
In response to Deadron
ok here goes:

I want the game to place an obj on a random location on the map every 5 secs.

It should only place it in area1(or whatever).

thats all the steps.



(As a note: The game this is going to be used in is not Tubia, same goes for the combat question)
In response to karver
On 2/16/01 1:17 pm Karver wrote:
One thing that confuses me about the spwn proc is how is it different from sleep?
Will it recreate a mob once it's dead after x amount of time?

It's confusing terminology, but the spawn() proc has nothing to do with spawning mobs. It is for spawning a piece of code later on.
In response to Kaidorin
On 2/16/01 1:26 pm Kaidorin wrote:
ok here goes:

I want the game to place an obj on a random location on the map every 5 secs.

It should only place it in area1(or whatever).

thats all the steps.

Well not really...

Because if that's all the steps, then you are going to end up with hundreds of thousands of objects all over your map.

I'm guessing the steps are something like this...

1) every five seconds check to see if the maximum number of mobs exist

This means that you need a way of tracking how many mobs are out there, and you need to figure out what the maximum number you need is.

2) if not, create a new mob

3) place it in a random spot on the map

I don't mean to be annoying talking about steps all over the place...I'm just trying to point you in the direction of how programmers solve things. To solve something that has any complexity, you need to figure out the steps and keep breaking them down until it starts to become clear what the variables and functions are...
In response to Deadron
ok now the steps are:

every 5 secs do this:

1) check to see if obj_count(or whatever) > number of active players.

2) If it is determine a loc for a new one.

3) check to see if the loc is within area1 if not goto 2

4) spawn an obj at loc


is that good enough? ;>

could you now give me at least some code?
In response to Kaidorin
On 2/16/01 2:00 pm Kaidorin wrote:
ok now the steps are:

every 5 secs do this:

1) check to see if obj_count(or whatever) > number of active players.

2) If it is determine a loc for a new one.

3) check to see if the loc is within area1 if not goto 2

4) spawn an obj at loc


is that good enough? ;>

It's getting closer...

could you now give me at least some code?

Not at the moment, but I will try to do some combat sample code tonight or this weekend.

In the meantime, I bet you can make some progress on your own if you were to take a look at the combat code in A Step BYOND. While it doesn't have hit points and such, there is a section where bumping into the little blue guys causes them to be killed.

Also, read up on the DblClick() function.

At this point you are moving out of newbie-land, and the answers to the questions are not so simple. We need to keep adding to the tutorials and sample code to answer questions, but much more frequently now you will have to look at things like Step BYOND and read through the docs and start figuring out how to make something no one has done before work within your game.

The good news is, as soon as you do this, you are a real programmer!
In response to Deadron
I will try to figure it out.
In response to Kaidorin
is that good enough? ;>

could you now give me at least some code?

I will. But take Deadron's advice a little bit... if you don't understand it, you should practice a little while more. =)

world/New()
..()
SpawnTick()

var/obj_count = 0
var/max_obj_count = 0

proc/SpawnTick()
if(obj_count < max_obj_count)
var/obj/weapon/O = new
var/list/L = new
for(var/turf/T in locate(/area/area1))
L += T
if(L.len)
O.loc = L[rand(1,L.len)]
max_obj_count++

spawn(50) SpawnTick()


Here's how it works. If the count is less than the max_obj_count, it makes a list of turfs that are in /area/area1, then it creates a new obj on one of those turfs. After five seconds, it spawns itself again, creating another object somewhere else.
In response to Spuzzum
world/New()
..()
SpawnTick()

var/obj_count = 0
var/max_obj_count = 0

proc/SpawnTick()
if(obj_count < max_obj_count)
var/obj/weapon/O = new
var/list/L = new
for(var/turf/T in locate(/area/area1))
L += T
if(L.len)
O.loc = L[rand(1,L.len)]
max_obj_count++

spawn(50) SpawnTick()


I don't understand it at the moment but I will try to figure it out.
In response to Deadron
the spawning code is working, but I used the code supplied by Spuzzum.

does that make me a programmer or am I still a newbie?
In response to Kaidorin
On 2/17/01 10:41 am Kaidorin wrote:
the spawning code is working, but I used the code supplied by Spuzzum.

does that make me a programmer or am I still a newbie?

Well you did the combat code, so now you are a programmer!

I will still try to do a demo of combat code this weekend if I get a chance.
In response to Deadron
yippie!!! I am a programmer, that gives me the privilege to pester with my questions, all those who hang around in code problems.


yeah, this feels great!!!
In response to Kaidorin
yippie!!! I am a programmer, that gives me the privilege to pester with my questions, all those who hang around in code problems.

And, of course, to help out all the people who ask questions in the newbie forum! :) (Fortunately, as time goes by, more and more questions can be answered just by giving people a link to a previous thread.)

Also, now that you have some coding under your belt, I'd strongly recommend that you go back and re-read the online Guide with a "new set of eyes," as it were... it'll make a lot more sense now. And you might consider ordering the printed guide too. They're both very helpful, even for people who've worked with BYOND for a long time.


yeah, this feels great!!!

Good! Sometimes the programming/testing/debugging cycle is a pain in the butt, but it's great when something finally works the way you planned it.
In response to Guy T.
And, of course, to help out all the people who ask questions in the newbie forum! :) (Fortunately, as time goes by, more and more questions can be answered just by giving people a link to a previous thread.)

If I can help I will do so.


Also, now that you have some coding under your belt, I'd strongly recommend that you go back and re-read the online Guide with a "new set of eyes," as it were... it'll make a lot more sense now. And you might consider ordering the printed guide too. They're both very helpful, even for people who've worked with BYOND for a long time.

I will, but not right now.


Good! Sometimes the programming/testing/debugging cycle is a pain in the butt, but it's great when something finally works the way you planned it.

Sumo is working great, at least the updated one (wich will not be uploaded until I am 100% sure that the combat system works).