ID:1879806
 
(See the best response by Ter13.)
I was trying to get an example of how I could create characters that a player could choose from. The characters would have preset stats and abilities that the player would be able to use for the duration of the match. I've been playing around with DM for a while now, and even have a (very) basic setup that allows players to join a player list, and start the game, and teleport to the starting positions, but now I really want to understand how I can allow a player to pick a character to play with.

I was reading Ter's thread here on "It's not a damn database!" becauuse I thought it was somewhat similar to what I was thinking... I had considered doing what was "wrong", but I don't know why it's wrong since I'm new to DM. Thread link:
http://www.byond.com/forum/?post=1626900

Thanks to anyone who has advice!
I think you'd receive more clear answers if you posted a code snippet of what you're trying to do, it's easier to tell you what you're doing wrong if we know what you're doing.

I also don't think that you are "wrong", there is probably better ways to do things but I find that doing something is better than doing nothing and even if you're not at a level where you understand Ter13's post doing what you're capable of is enough, however, looking for improvements is not bad (as long as you understand the improvement)

You can always read this comment by Ter13, it helps explains further what not to do.

My initial idea was to create a list of procs that handle how the types of abilities/attacks would work. There would also be a list of available characters that the players can choose from, each with defined verbs that reference the procs that are associated with it (one attack might use two procs, such as a push (step_away, I suppose would work), and a damage, or a slow status affect, etc).
What I wanted was to have the player click the character from a list, and when the game starts the information about that character gets pushed onto the player's mob so that he/she can use the verbs associated with that character, and gains its strengths/weaknesses, gains the icon, and all that good stuff. I don't have any code set up yet for this so I'll just whip up some hypotheticals:

proc
killMob(m as mob)
//some proc to remove a character from game
dmgMob(m as mob)
m.hp -= src.pwr
if(m.hp < 1)
view() << "[m] dies!"
killMob(m)
dmgMobBump(m as Mob)
// Handle bump damage here for if character is pushed into a wall
slowMob(m as mob,slow as num)
// something here
pushMob(m as Mob)
if(m.hp) //If the player is still alive...
var d = get_dir(src.loc,mob.loc)
if(!step(m,d)) //push the character in the direction
dmgMobBump(m)


mob
hp = 0 // just to initialize - gets changed to equal max_hp later when the character is chosen
verb
fireball(m as mob)
dmgMob(m)
pushMob(m)
stun(m as mob)
slowMob(m,1)
chars
char1
icon='char1.dmi'
max_hp = 100
pwr = 5
verbs = (Not sure how to specify which verbs should be allowed)
char2
icon='char2.dmi'
max_hp = 150
pwr = 3
verbs = (Not sure how to specify which verbs should be allowed)
char3
icon='char3.dmi'
max_hp = 120
pwr = 4
verbs = (Not sure how to specify which verbs should be allowed)


I had to wrap this up because my 9 year old son is being a pain in the butt... I know the code is dirty and needs cleaning but hopefully it paints the picture of what I was intending.... thank you.
Take your time, there's no need to rush this. I'm sure someone will reply even tomorrow with advice.

Looking at what you want to accomplish, I don't think Ter13's post is too relevent, personally I wouldn't use subtypes to define different characters unless I was planning to attach processes and verbs to the characters and adding/overiding them as I see fit for sub types.

For example:
mob
hp = 0 // just to initialize - gets changed to equal max_hp later when the character is chosen
chars
verb
fireball(m as mob)
dmgMob(m)
pushMob(m)
stun(m as mob)
slowMob(m,1)
char1 // char1 also stuns with his fireballs, he's skilled that way, he doesn't however push them.
fireball(m as mob)
dmgMob(m)
slowMob(m,1)

char2 // char1 also stuns with his fireballs, he's skilled that way, he also pushes them.
fireball(m as mob)
..(m) // call parent
slowMob(m,1)

You can also attach damage and stun process to /mob/char, it may be more handy.

In my opinion, which may be wrong, I believe that if you're going to be having this structure where you changes how certain things work for every character, it'd be a beautiful object oriented code.

However if all processes are the same, it may be wiser to just have a variable control who gets what.

As for adding/removing verbs, if the verb is defined under the character type they should have it, you can also hide verbs for certain characters by using "set hidden = 1".

Or you can during runtime add/remove verbs but then you'd also need to save them so this might be a lesser route.
Best response
There's nothing wrong with using different types to describe players that behave fundamentally differently. The reason that variation necessitating subtypes is wrong is because variation alone does not necessitate a new type. A new type clutters the prototype tree and complicates the process of maintaining projects at a later time.
I'm considering removing "chars" from the equation... just keep char1, char2, and char3 (in actuality these are just placeholders for the name of the characters. To be determined.)

But what I don't quite understand yet is... how do I allow the player to choose one?

How can I present a list of the characters? This was the original reason why I had it has "mob/chars" because I thought I could specify that location (It feels like a file directory?) but I didn't know how, so now I'm just kind of stuck...


verb/charSelect(mob/m as mob in newlist(typesof(/mob)))
usr = M

mob
char1
icon='char1.dmi'
max_hp = 100
pwr = 5
char2
icon='char2.dmi'
max_hp = 150
pwr = 3
char3
icon='char3.dmi'
max_hp = 120
pwr = 4


Thanks all for your time.
I believe what you're looking for is client.mob

"This is the mob to which the client is connected. The client and its connected mob have the following symmetry:

client == mob.client
client.mob == mob
client.key == mob.key"


You can assign client.mob to any other mob.

I don't know if you should drop chars because then you'd define things under /mob/ and that would include NPCs as well.
You might find one of my recent posts an interesting and helpful read. It's a somewhat lengthy post on polymorphism concepts, but it's in my opinion an excellent primer for beginning to truly understand the concept you are wrestling with right now.

http://www.byond.com/forum/?post=1869567#comment15419097

You'll notice only a handful of people in this community have ever really mentioned polymorphism, and only two or three people that have been here have really tried to teach it to anyone.

Among those who ever mentioned polymorphism:

Hiead
Schnitzelnagler
Alathon
Popisfizzy
Bandock
Crispy
Kaiochao
FKI


Literally the best programmers who have ever been a part of this community are almost all heavily represented on that list. (I don't say a part of BYOND, I'm talking the forum dweller community.)

Those that neglected to fully understand polymorphic concepts who attempted to teach have led people to some really bad assumptions about programming and ruined them potentially forever.

If you want to be a programmer in the modern era, you need to learn about polymorphism before you do anything else.

Don't get too hung up on it, though. Not doing until you are an expert can become a trap of being in a perpetual state of self refinement that never allows you to get anything done.

Learn the concepts well enough to use them, then run with them and make mistakes. Learn from those mistakes and always have an open mind to how you can move forward with saner, cleaner, and easier practices in the future.

You can't master something without doing it first.
Wow, this is great stuff. I really appreciate all the great advice from you both, and helping to steer me in the right direction. In all honesty, I'm actually surprised I've been able to get as much done by myself before I started asking for help. I just finished reading the DM guide over the last two weeks (dl'd the PDF to my phone to read while standing in long lines at Disney World).
Im off to bed for nke but I'll give that a read, Ter13. And thanks, Rotem12, for the point towards client, I'll dig into that as well.
Something that I'm still grasping at... how can I present a list of the characters that I have set up in the mob/chars location? I was hoping to make it easy to add additional characters at a later date without having to hardcode it into the verb. I have a verb created but when clicked, it doesn't do anything.
    verb/charSelect(m as mob in newlist(/mob/chars/))
client.mob = m


Thanks for your time.
mob/verb/select(var/m in typesof(/mob/chars)-/mob/chars)
client.mob = new m


I don't think you wrote the arguments properly, I should note that newlist creates a new instance of everything in the list, it's far better to only create the instance you want to use, in my code I only create an instance of the new mob I'm assigning the client to.

How do you want players to select their character? You can have them select a class, a text selection then if they've selected let's say, wizard, assign them a certain mob

There's a lot of methods to do it, via interface, inputs, clicking on screen objects etc.

You can have a few radio buttons with attached hidden command 'selectclass "power ranger"', then in the verb selectclass you do whatever.

Eventually I would like to make it more advanced, but since I'm still fairly new to DM, I'm just taking it one step at a time.
At this point I would be happy with a popup window that displays all the available characters to chose from. These are basically defaults that the player would start with, and can modify, and save to their save file.
Eventually I would like to make things far more interesting than a popup window... Like a full blown chargen menu.