ID:2871061
 
Three beginner questions below. Thanks for reading.

Code:
mob
pc1
pc2
pc3
pc4

mob/var
body
mind
spirit

mob/proc
charactergen()
name = pick("Aerg-Tval","Keftar","Torvul","Vatan")
var/bodygen = roll(1,6)
var/mindgen = roll(1,6)
var/spiritgen = roll(1,6)
if(bodygen > 3)
body = bodygen - 3
else
body = 0
if(mindgen > 3)
mind = mindgen - 3
else
mind = 0
if(spiritgen > 3)
spirit = spiritgen - 3
else
spirit = 0


Problem description:
I'm working on a project which has the player control a party of four characters. I have made a procedure for randomly generating character names and attributes, but I don't know how to apply it to the player character mobs instead of the user. How can I use the charactergen() procedure I made to generate attributes for other mobs?

Also, I have a feeling that pick() is the wrong procedure to use for name generation. I would like to eliminate names if they've already been assigned, so is using a list or something else better suited for this?

Lastly, if I wanted to designate these mobs as player characters for things like applying status effects, is looking into lists the direction I should be going to accomplish that?
Monkhood wrote:
Three beginner questions below. Thanks for reading.

mob
pc1
pc2
pc3
pc4

Having four pre-defined vars for your party is really not a good idea. I suggest a more robust pattern of using a list. That will allow you to loop through your party more easily, among other things.

mob
var/list/party

That list is null by default. For players, you can either initialize it to a new list in Login(), or you can just initialize it when it's needed (e.g., when they get a character to join them).

Now for generating those party members, first I'd have a global list of names you can pick through. If you're building the player's party when they log in, then I'd make a copy of that global list and remove names from it as they're picked.

var/list/gen_names = list(\
"Alice", "Bob", "Charlie", "Daniel", "Ernie",
... // more names
)
var/list/character_classes = list(\
"fighter", "mage", "rogue", "cleric"
)

mob/proc/BuildParty()
party = list() // initialize the party list

var/available_names = gen_names.Copy()
var/classes = character_classes.Copy()

for(var/n in 1 to 4)
var/mob/M = new(loc)
M.name = pick(available_names)
available_names -= M.name
M.gender = pick("male", "female")

M.class = pick(classes)
classes -= M.class
M.icon = 'party.dmi'
// party.dmi has four icons for each class/gender, e.g. "rogue_male_3"
M.icon_state = "[M.class]_[M.gender]_[rand(1,4)]"

// generate stats
M.body = max(0, roll(6) - 3)
M.mind = max(0, roll(6) - 3)
M.spirit = max(0, roll(6) - 3)

A fairer way to pick character stats might be to have a set number of skill points, assign some of them automatically based on the class, and then assign the rest at random.