ID:2321845
 
How-To:
I'm trying to create a game where each race has a specific set of abilities, but I can't seem to figure out how to give the player that is that specific race the race's set of abilities. Any and all help is welcome!

Example:
  • Pyromancer = Fireball
  • Siren = Sing
  • Vampire = Bite
This is pretty much a copy of Deadron's character handling library. You should check that out, although I'm not sure if it's outdated by now. So I simplified his code for this situation.

mob
var
race
Login()
..()
//code for assigning races
var/new_mob

if(race == "pyromancer")//if they selected pyromancer
new_mob = new /mob/race/pyromancer() //create a new mob type

usr.client.mob = new_mob //make the player the new mob
mob
race
pyromancer
verb
fireball()

vampire
verb
bite()
What if that race has sub-races, like:

Pyromancer
-Starter (Fireball)
-Pyro (Fire Form)
Isn't Pyromancer more of a profession than a race?
In response to Bubbabears
Go full modular. It'll make things a bit complex (what vars belong to the mob and what to the datum?), but allows for more flexibility than straight up inheritance plays on the mob class. Though note, this is way more complex than the above proposed solution, and a bit more prone to shenaniganry.

/datum/race
var/name ///< Name of the race.
var/list/abilities ///< A list of mob/procs which are attributed to
// a mob that's assigned to this race.

/**
* @brief Applies this race's abilities to the mob as verbs, and adds the
* race pointer.
*
* @param M The mob that we're applying the race to.
*/

/datum/race/proc/apply(mob/M)
if (!M || !abilities)
return

M.race = src
M.verbs += abilities

/**
* @brief Inverse of apply: removes any abilities this race and sets race pointer
* back to null.
*
* @param M The mob to clear.
*/

/datum/race/proc/unapply(mob/M)
if (!M || !abilities)
return

M.race = null
M.verbs -= abilities

/datum/race/pyromancer
name = "Pyromancer Starter"
abilities = list(
/mob/proc/fireball
)

/datum/race/pyromancer/adept
name = "Pyromancer Adept"
abilities = list(
/mob/proc/fireball,
/mob/proc/fireform
)

var/list/datum/race/g_races = list()

/world/New()
. = ..()

// Handle race caching/generation. Note potential race conditions in mobs
// being created before this list is initialized!
for (var/rr in (typesof(/datum/race) - /datum/race))
var/datum/race/R = new rr()
global.g_races[R.name] = R

/mob
var/datum/race/race ///< Race datum for this mob.

/mob/Login()
..()
// You want to handle this logic somewhere else. But you should get the idea.
if (!race)
var/datum/race/R = global.g_races["Pyormancer Adept"]
R.apply(src)

/mob/proc/fireball()
set name = "Fireball"

/mob/proc/fireform()
set name = "Fire Form"