ID:175605
 
Im trying to make a proc that cycles through all of the mobs in the world, then randomly puts them on two teams: red and blue. I can't quite figure it out, since i get a type mismatch runtime error when i put the mobs in lists. Can someone help?





-Peoples
var/list/B=list()
var/list/R=list()
for(var/mob/M in world)
if(M.blue)
B+=M
else
R+=M


Hope that helps
Aleis wrote:
Im trying to make a proc that cycles through all of the mobs in the world, then randomly puts them on two teams: red and blue. I can't quite figure it out, since i get a type mismatch runtime error when i put the mobs in lists. Can someone help?

The problem is that you're not initializing the list. The var you're using will start out as null, so when you try to add a mob to it you get an error.

You didn't mention anything about balancing the teams, but I'll assume you wanted to do so.
team
var/list/members
var/name
var/color // an HTML color

New(nm,c)
name=nm
color=c?(c):name
members=new

proc/Join(mob/M)
if(M.team) M.team.Leave(M)
members+=M
M.team=src
world << ColorText("[M.name] joins [name].")

proc/Leave(mob/M)
members-=M
M.team=null
world << ColorText("[M.name] leaves [name].")

proc/ColorText(txt)
return "<FONT COLOR=[c]>[txt]</FONT>"

mob
var/team/team

var/list/teams

proc/PutPlayersOnTeams()
var/team/T
teams=list()
teams+=new/team("the red team","red")
teams+=new/team("the blue team","blue")
// I chose this 2-stage approach so the client list doesn't dictate who
// goes where; mobs are picked at random from a list, not in order
// of their clients.
var/playerlist=new
for(var/client/C)
playerlist+=C.mob
var/mob/M
while(playerlist.len)
M=pick(playerlist)
if(!M) continue
T=SmallestTeam()
T.Join(M)

proc/SmallestTeam()
var/list/best
var/size=-1
for(T)
// if bigger than the smallest team(s), skip it
if(size>=0 && T.members.len>size) continue
// if smaller, reset the list of smallest teams
if(size<0 || T.members.len<size)
size=T.members.len
best=new
best+=T
return pick(best)
The code in this example can be extended to more than two teams; I had it automatically create two teams, but you can move the team creation elsewhere to pick even more. If players join the game later on, they'll be added to the smallest team available. If the smallest teams are balanced, one will be picked at random.

Lummox JR
In response to Lummox JR
Thank you Lummox, i posted with aleis before, but disregard that.

Drag0n Pr0ductions thanks you.