ID:179167
 
After reading through the guide, I couldn't figure out how to create a verb that would effect both the user and other mobs. In particular, I want to allow the user to 'cure' both himself and others.

Another problem I ran into was in trying to 'learn' the spell. I created a simple exp system with the intention of allowing players to cast cure at level 2. My code for the spell started thus:

mob
verb
cure(mob/M as mob in oview(1))
if (level >= 2)
[followed by the rest of the spell]


However, this allows the player to cast cure at any time, even though it only completes the spell when the user is above level 1. I tried to put the if statement directly after 'mob' and before 'verb,' but this resulted in a long string of errors. Is there a way to turn a verb 'off' or 'on' for a specific mob?
To answer your first question:

cure(mob/M as mob in oview(1))

Look up the definition of oview() in the Reference... you will see that it refers to the user's surroundings... oview(1) means "Everything within 1 square, excluding things in the same square as the user." This, of course, excludes the user as well. Instead of oview, just use view, which makes no such exclusion.

To answer your second question... well, you've obviously learned some things from the Guide, but you still haven't quite got a grasp on the whole object-oriented programming. The reason you can't put the if before the verb is that it would be meaningless... verbs are compiled as part of the object (mob, turf, whatever) that owns them, regardless of any variables, which don't even have any meaning at compile time.

There are quite a few ways to handle "learning spells".

One is to have the spell be represented by an obj, which would have the verb... in this case, you'd want to add the line "set src=usr.contents" to the top of the verb's code, which means that any user would automatically have this verb if the item is in its contents, without having to specify or refer to the object. Practical effect: the character has a new verb. Downside: if you treat all /obj's as items, with get() and drop() verbs defined under the top level node, spells will also be gettable and dropable... you can solve this by making two branches, obj/item (with get() and drop() verbs), and obj/spell. You'd then have obj/spell/cure, obj/item/sword, and so on.

Two is to define your spell verbs as separate procs, and then add them to the character's .verbs list at the appropriate time. If you implement character saving, you'd either have to work out a way to save these changes (such changes are temporary under the default BYOND program), or check the character's level and add appropriate spells again each time someone logs on.
In response to Lesbian Assassin
Players can now cast cure on themselves, but I ran into another problem. When I select cure, a window comes up asking who to cast the spell on. This isn't a bad thing in itself, except that one of the possible targets is the spell itself (obj/cure). Any suggestions?
In response to Gakumerasara
Really? Strange... if you have it specied "as mob", that shouldn't happen. Does it give you any error messages in the text window if you choose to cast cure on cure?
In response to Lesbian Assassin
It says that cure gains (insert number) HP every time I try it.

A few ideas I had that didn't work:

1. make the verb as such:
cure(mob/M as mob in view(1) in (M.HP<M.HPmax))

2. turning mob/obj/cure/verb into obj/cure/verb

This resulted in about 20 different errors, since the variables from mob couldn't get access to the verb. Turning the variables into global variables made even more errors since I had different numbers for HP and HPmax for each type of mob.
In response to Gakumerasara
2. turning mob/obj/cure/verb into obj/cure/verb

There's your problem... there's no such thing as a mob/obj, until you define it. What you've said is that cure is a mob of a type called obj, like making

mob/humanoid/ork

makes a type of mob called humanoid and a type of humanoid called ork.

This resulted in about 20 different errors, since the variables from mob couldn't get access to the verb.

Sure they can! There are two mobs involved in the curing operation... the curer, and the curee. When you defined the verb under mob, the mob doing the curing was the src (source) of the verb. The mob doing the curing is now only the usr (user) of it. Make the appropriate corrections in your code due to this change of perspective.

Turning the variables into global variables made even more errors since I had different numbers for HP and HPmax for each type of mob.

You really need to slow down and do a little more learning... trying things at random like this isn't a good way to make a game. Even if the result seems to work, if you don't really understand what you're doing, how can you tell if it's not doing other things you don't know about that you don't like?

Again, you've really not got a handle on the idea of object-oriented programming. The reason you don't want to define HP as a global variable isn't because it gives you a lot of errors... it's because, quite frankly, even if you write it error-free, it's a bad way to handle a value like that. Even if all mobs started with the same HP, well... you don't want everyone's HP to go down whenever anybody gets hit, right?
In response to Lesbian Assassin
It works, woo-hoo!
Thanks for all of your help.
I'm sure that I'll be back with more questions soon enough.