ID:1107673
 
Hello BYOND, I feel like putting something on BYOND. I'm going to do a couple of Spawn Point examples. It's not the best coding, there is probably a better way to do these, but I'm explaining my ways.

Example #1

I learned this method from Falacy, whenever I was viewing his source codes.
mob
proc/Locate(var/Location)
switch(Location)
if("Shop") src.loc = locate(rand(1, 2), rand(1, 2), 1)
if("Village") src.loc = locate(rand(4, 5), rand(4, 5), 1)
if("Dojo") src.loc = locate(rand(6, 7), rand(1, 2), 1)
if("Tent") src.loc = locate(rand(8, 9), rand(4, 5), 1)

verb/Random_Location()
src.Locate(pick("Shop", "Village", "Dojo", "Tent"))


Example #2

This method, I used numbers instead of text for some reason?? But, it still works pretty good. Whenever you place SpawnPoint down on the map, you'll have to edit it, and find SpawnN and, change it to the Number you want for that spawn.

Image and video hosting by TinyPic
Image and video hosting by TinyPic
turf
SpawnPoint
var/SpawnN = 0
Enter(atom/A)
if(ismob(A) && A:client)
var/mob/Player = A
Player.Locate(rand(1, 5))// This is basically, spawning you randomly. you can change it to
// the spawn you want, by putting the number you named the spawn.

mob/proc
Locate(Number)
spawn() for(var/turf/SpawnPoint/Spawn in world)
if(Spawn.SpawnN != Number) continue
if(Spawn.SpawnN == Number) src.loc = locate(Spawn.x, Spawn.y, Spawn.z)
switch(Number)
// just incase you want to add certain things for spawning at a certain place?
if(1) src << "spawned in the middle of nowhere"
if(2) src << "spawned at your tent"
if(3) src << "spawned inside of the dojo"
if(4) src << "spawned by the village"
if(5) src << "spawned at the shop"
I'd want to throw out another example:
Spawn
var path
Dogs/path= mob/Dog
Cats/path= mob/Cat
Wolves/path= mob/Wolf

proc/Spawn(t)
for(var/Spawn/S in world)
if(S.path == t){.=S;break}
mob
New()
loc = locate(Spawn(type))
..()
Dog
Cat
Wolf


Also, heres the same example using numbers as well, instead of type paths:

Spawn
var index
Dogs/index = 1
Cats/index = 2
Wolves/index = 3

proc/Spawn(i)
for(var/Spawn/S in world)
if(S.index & i){.=S;break} // if(S.index & i) > if(S.index == i). As far as I know using bitflags makes your code a bit faster, jsut for those who care about such things.
mob
New()
loc = locate(Spawn(type))
..()
Dog
Cat
Wolf


Probably not the besst examples, but this is a bit simpler.
Why don't you guys use tags?

mob
Login()
src.loc = locate("start")


In map editor, right click a tile, go to edit instance, go to tag, type "start", hit ok, save, compile, run.
In response to FIREking
I never knew you could do that, that's also another great way {;
In response to Flysbad
Flysbad wrote:
I never knew you could do that, that's also another great way {;

Same.
In response to Fushimi
You misunderstand bitflags, and that code won't work as expected. For example, (1 & 3) returns 1, which is a TRUE value. Further, the equality operator (==) would actually be as fast as, if not faster than, the binary AND operator (&) in this case.

You're also both making unnecessary calls to locate().

Also, as FIREking mentioned, the tag variable is perfect for this (I would even go so far as to say designed for this).
In response to DarkCampainger
DarkCampainger wrote:
Also, as FIREking mentioned, the tag variable is perfect for this (I would even go so far as to say designed for this).

Yeah, it does pretty much does exactly the same as SpawnN basically. I know what I'll use next time whenever I need a single spawn :P
Cool stuff, just noticed you spelled encase as incase. Generally if you're gonna share programs which have comments then in my opinion it's good to put them through a spell checker.

But that's just me being me so don't worry too much, it's just one spelling error.
I see, Is there any documentation about bitflags? @ DC
In case its not already apparent, you can do this with objects, and mobs. In the documentation for locate() it discusses the tag variable in more detail.
Yeah, this tag variable simplifies this work a lot.
In response to Fushimi
It's usually best to go via wikipedia for this, and some experimentation on your own so you understand or visualise the kind of transformation at work:

http://en.wikipedia.org/wiki/Bitwise_operation
http://www.miniwebtool.com/bitwise-calculator/

I apologise for the slightly general seeming nature of the links. It's just that bitwise operations aren't really much of a BYOND specific notion so much as a binary mathematics notion.
In response to Stephen001
Stephen001 wrote:
It's usually best to go via wikipedia for this, and some experimentation on your own so you understand or visualise the kind of transformation at work:

http://en.wikipedia.org/wiki/Bitwise_operation
http://www.miniwebtool.com/bitwise-calculator/

I apologise for the slightly general seeming nature of the links. It's just that bitwise operations aren't really much of a BYOND specific notion so much as a binary mathematics notion.

Another useful concept is bit-shifting.

Edit: Ooops, looks like that article does explain bit-shifting.
Yes, the tag variable indeed is good to use.
Ahh, I see. Good Tutorial Btw.
I've experimented with a number of ways to have players spawn randomly among mapped spawn points on specific maps, and came up with a method that I always use for this situation. This is generally for action games, especially when you re-spawn multiple times throughout a match, and when you want to have teams with separate sets of spawns. It's also nice because you don't have to mess around with tags or anything - just place the spawns and you are done:

turf
spawn1 //place as many of these invisible turfs as
spawn2 //you want.

var
team1_spawns[0] //relevant spawns are maintained in
team2_spawns[0] //two lists.
map = 1 //which z-level the game is on
proc
Update_Spawns() //call this any time map changes
team1_spawns = list()
team2_spawns = list() //reset spawn lists
for(var/spawn1/S in block(locate(1,1,map), locate(world.maxx,world.maxy,map)))
team1_spawns += S
for(var/spawn2/S in block(locate(1,1,map), locate(world.maxx,world.maxy,map)))
team2_spawns += S

mob
var/team = "team1"
Login()
team = pick("team1","team2")
Update_Spawns()
Respawn()

proc/Respawn()
if(team == "team1")
loc = pick(team1_spawns)
else
loc = pick(team2_spawns)
These are great examples guys! Keep it up.