ID:268937
 
How do I assign a player a random color when they log in and noone else could get that color unless the person who has the color leaves?

The colors are: ("Red","Yellow","Green","Blue","Cyan","Purple","Orange","Gray")
Skye Reaver wrote:
How do I assign a player a random color when they log in and noone else could get that color unless the person who has the color leaves?

[EDIT]

You would do it like this

var/list/colors=list()

mob
var/color

Login()
..()
var/R=rand(1,255)
var/G=rand(1,255)
var/B=rand(1,255)
colors+="[src.GetColor()]"

Logout()
colors-=src.color

proc/GetColor()
var/R=rand(1,255)
var/G=rand(1,255)
var/B=rand(1,255)
if("[R] [G] [B]" in colors)
spawn()
GetColor()
else
src.color="[R] [G] [B]"
return "[R] [G] [B]"

In response to Wizkidd0123
That isnt what he wants..
In response to Dession
Dession wrote:
That isnt what he wants..

*Rereads his post*

Oops: I'll edit my post.
In response to Wizkidd0123
Uhm, I dont want it like that :( I put a list of colors I want it to choose from
Try this(Untested)
mob/var/Color
var/list/Colors=list("Red","Yellow","Green","Blue","Cyan","Purple","Orange","Gray")
mob/Login()
src.Color = pick(Colors)
Colors-=src.Color

I'm not sure if it'll work but it's worth a try.
In response to Artekia
Well errm this is what I have done myself, Would it work?

mob
var
list
Colors=list()
Color
Login()
Colors+="[src.GetColor()]"
world << "[usr] has joined as [src.Color]"
Logout()
Colors-=src.Color
proc
GetColor()
var/Color=pick("Red","Yellow","Green","Blue","Cyan","Purple","Orange","Gray")
if("[Color]" in Colors)
spawn()
GetColor()
else
src.Color="[Color]"
return "[Color]"
In response to Skye Reaver
NO.

First, if GetColor fails, it returns nothing, and you get a blank entry in the list. If GetColor() gets spawn'd(), it has no one to return to.

Second, I don't like "if("[Color]" in Colors)". I doubt that will work. Try if(Colors.Find("[Color]"))

I'd change Login() to merely call GetColor, and move the Colors+= and world << lines to GetColor.
In response to Nova2000
Be careful you don't make an endless loop once all the colors are taken!