ID:1136999
 
Keywords: code, help, verb
(See the best response by A.T.H.K.)
hey everyone... I just wanted to know if it's possible to create a verb which creates another verb?
The idea is that on game I would be able to give someone a verb which I'd choose its name, but its function would be basically always the same. For example...
mob/verb/Give_Spell()
...
src << You gave [usr] the spell [verbname]!
...
Verb on use:
view() << "[usr] used [spell]"

That would do it. Sorry for bad english, I'd appreciate any help or comment... thanks!
Best response
You can achieve this by adding the spell verb to the user with src.verbs += /mob/verb/spell

Or something around those lines death the forums for verbs+= also this should be in Developer Help :)
Well, the best way I see to go about this is using special verb datums. This is the basic idea:

_verb
parent_type = /obj
var
cmd

New(cd)
.=..()
cmd=cd
verbs += new/_verb/proc/use(src,cmd) // this will change the name of the verb to cmd
// before adding it to this datum's verbs list

proc/use()
set src in usr // this means that the verb will show up when
// this object is inside a mob's contents list
usr.test_proc(cmd)

// [EDIT] Note that use() must be a /proc and not a /verb
// because then it would be in the datum's verbs list by default

mob/proc/test_proc(c)
src << "You used [c]!"

mob/verb/add_verb(t as text)
contents += new/_verb(t)


Let us know if you have any questions. :)
Thanks a lot for the help. I'd still like to know if there's a way to add a "mana cost" var to the verb, so that one would give the verb to somebody (or even everybody in his view()), and at the same time pick how much mana it would cost.
As far as I'm aware, verbs cannot have their own variables so you wouldn't be able to assign a var to one of your given verbs.

Two options come to mind, though I'm sure there are other answers outside of these ideas.
1.) Assign a variable to each mob that would be paired with the verb that you are giving out. The verb could then check the mob's variable and act accordingly.

2.) Instead of giving the mobs new verbs, give them an obj that has the verb you want to give them. That way, the obj can hold as many variables as you need it to, and the player will still have the verb in their verb list and will be able to macro it.
The only issue is that I'm not sure if you could then rename the verb that would be on the obj that you would give them.
In response to Dipic
Dipic wrote:
As far as I'm aware, verbs cannot have their own variables so you wouldn't be able to assign a var to one of your given verbs.

Two options come to mind, though I'm sure there are other answers outside of these ideas.
1.) Assign a variable to each mob that would be paired with the verb that you are giving out. The verb could then check the mob's variable and act accordingly.

2.) Instead of giving the mobs new verbs, give them an obj that has the verb you want to give them. That way, the obj can hold as many variables as you need it to, and the player will still have the verb in their verb list and will be able to macro it.
The only issue is that I'm not sure if you could then rename the verb that would be on the obj that you would give them.

I really liked your second idea, it looks a lot easier than what I was thinking of... I could give 'em a kind of book instead that would keep the variables indefinitely.
Thanks a lot for the help...
In response to Victor_3250
Glad I could help. Good luck and happy programming!