ID:167198
 
is it possible to locate a newly spawned mob using rand() to place them randomly from your current location? any examples?
var/x=rand(1,world.maxx)
var/y=rand(1,world.maxy)
var/z=rand(1,world.maxz)
var/mob/player=new(locate(x,y,z))
In response to Mysame
sorry i didnt explain it thoughorly. something like var/mob/player=new loc(src.x,src.y,src.z)(rand(0,3))

my method doesnt work though.
In response to Propylparaben
Editted the post, check it.
In response to Mysame
I believe you meant:

1,world.maxblahblah. =p
In response to Mysame
Mysame scribbled:
var/x=rand(0,world.maxx) // will occasionally return 0, which will crash the proc
var/y=rand(0,world.maxy) // will occasionally return 0, which will crash the proc
var/z=rand(o,world.maxz) // line won't compile
var/mob/player=new(locate(x,y,z)) // creates a new player, which is unwanted behaviour.
// Also, this will leave the old player standing
// unless it is deleted on Logout.


That's inexcusably lame, retard. Shame on you. This is far better:

proc
place_random()
var/mob/m = new()
locate_randomly(m)
locate_randomly(atom/movable/a,cap=0)
if(cap>9999) //arbitrary large number
return 0
var
x = rand(1,world.maxx) // (1,1,1) is the first
y = rand(1,world.maxy) // location on the map.
z = rand(1,world.maxz)
if(invalid(locate(x,y,z))) return locate_randomly(a,++cap)
else return a.Move(locate(x,y,z))
invalid(turf/t)
var/obj/o = new
o.density = 1
. = !(o.Move(t))
del o
In response to PirateHead
Heyhey, yours doesn't compile either. o.O
And I didn't notice I had o instead of 0 and that I had 0 instead of 1. Still, no reason to call me a retard, har har pirate. :/

And he said he wanted to create a new 'player'. Who knows it's an NPC, I don't know the hell he's doing. :/
Propylparaben wrote:
is it possible to locate a newly spawned mob using rand() to place them randomly from your current location? any examples?

Simple enough.

var/mob=new(locate(rand(src.x-5, src.x+5),rand(src.y-5,src.y+5),src.z))


What this code will do is create a new mob anywhere between five steps left of you, to five steps right of you, and five steps up from you, to five steps down from you on the same z-level of the map. (Effectively anywhere within a 5 square radius with you as its center.)

Now, I never tested if this would actually work, but in theory it will. Good luck with your game.

-- §atans §pawn --