ID:1589733
 
Keywords: helpcodecertain
(See the best response by Ssj4justdale.)
Code:
turf
Grass
Entered(mob/m)
if(m in m.allies)
if(prob(3) && ismob(m))
m.prevloc=m.loc
if(prob(80))
if(m.allies.len>0)
var/mob/x=m.allies[1]
x.loc=locate(3,3,2)
x.inbattle=1
if(m.allies.len>1)
var/mob/y=m.allies[2]
y.loc=locate(7,3,2)
y.inbattle=1
if(m.allies.len>2)
var/mob/z=m.allies[3]
z.loc=locate(11,3,2)
z.inbattle=1


Problem description:
I did the allies but what if i wanted a random set of enemies to appear and fight? How would i code that in?
Use rand.
Sorry, I have a pet peeve of people who use spaces rather than tabs in actual DM code. It saves a lot of time just using tabs, unless BYOND auto spaces things like other scripting IDE's.

Anyway, I would rewrite your spawn code for your allies just because that is a lot of if() statements that you can take care of with a while() statement. It'll clean up a lot of the code.

Anyway, that isn't the problem we are addressing, for your spawning issue with a random amount:

turf
Grass
Entered(mob/m)
if(m in m.allies)
if(prob(3) && ismob(m))
m.prevloc=m.loc
if(prob(80))
if(m.allies.len>0)
var/mob/x=m.allies[1]
x.loc=locate(3,3,2)
x.inbattle=1
if(m.allies.len>1)
var/mob/y=m.allies[2]
y.loc=locate(7,3,2)
y.inbattle=1
if(m.allies.len>2)
var/mob/z=m.allies[3]
z.loc=locate(11,3,2)
z.inbattle=1

//spawn_enemies
var{min_en=1;max_en=5}
var/spawn_en=rand(min_en,max_en)
while(spawn_en>0)
spawn_en--
var/mob/en=new/mob/enemy
en.loc=locate(max(1,min(usr.x+rand(-5,5),world.maxx)),max(1,min(usr.y+rand(-5,5),world.maxy)),usr.z)
^ the above code needs some adjustments to fit your games needs but that is a basic setup to spawn a random amount of enemies.
It'll also place them randomly around the user.
Doesn't spawn the enemy when I did that.
Best response
My guess is because "m" in not in "allies"
Please look at the if statement above, I put it under: if(m in allies)

Try this one:
turf
Grass
Entered(mob/m)
if(m in m.allies)
if(prob(3) && ismob(m))
m.prevloc=m.loc
if(prob(80))
if(m.allies.len>0)
var/mob/x=m.allies[1]
x.loc=locate(3,3,2)
x.inbattle=1
if(m.allies.len>1)
var/mob/y=m.allies[2]
y.loc=locate(7,3,2)
y.inbattle=1
if(m.allies.len>2)
var/mob/z=m.allies[3]
z.loc=locate(11,3,2)
z.inbattle=1

//spawn_enemies
var{min_en=1;max_en=5}
var/spawn_en=rand(min_en,max_en)
while(spawn_en>0)
spawn_en--
var/mob/en=new/mob/enemy
en.loc=locate(max(1,min(usr.x+rand(-5,5),world.maxx)),max(1,min(usr.y+rand(-5,5),world.maxy)),usr.z)


please remember that I did say that it may need some editing to fit your game.