ID:266641
 
How would I add verbs to a usr without having to write usr.verbs += /mob/verbs/verb/Whatever over and over and over for each verb?
for(var/T in typesof(/mob/proc/verbstoadd))
src.verbs += T

In response to Nadrew
Nadrew wrote:
for(var/T in typesof(/mob/proc/verbstoadd))
src.verbs += T

One thing I should add, here: This works most of the time, but I've had it fail in testing for some projects while it worked for others. In some cases, it seems typesof() returns nothing for a verb list; I've never figured out why.

Apparently this is a nonstandard syntax, and wasn't meant to work at all even though it usually does. If it works for you, though, that's great. If it doesn't, here's an alternative you can try:
var/list/adminverbs=list(/mob/admin/verb/Boot,
/mob/admin/verb/Ban,
/mob/admin/verb/Mute)

mob
Login()
..()
if(ishost || isadmin) // set these vars yourself
client.verbs+=adminverbs

Lummox JR
In response to Lummox JR
Lummox JR wrote:
One thing I should add, here: This works most of the time, but I've had it fail in testing for some projects while it worked for others. In some cases, it seems typesof() returns nothing for a verb list; I've never figured out why.

Apparently this is a nonstandard syntax, and wasn't meant to work at all even though it usually does. If it works for you, though, that's great. If it doesn't, here's an alternative you can try:
var/list/adminverbs=list(/mob/admin/verb/Boot,
> /mob/admin/verb/Ban,
> /mob/admin/verb/Mute)
>
> mob
> Login()
> ..()
> if(ishost || isadmin) // set these vars yourself
> client.verbs+=adminverbs

Lummox JR

I've had the same problem, and have also come up blank. Here's yet another way:

mob/Login()
..()
if(you_are_the_admin)
var/mob/admin/M = new
for(var/verb/v in M.verbs)
if(!(v in src.verbs)) src.verbs += v
del M

This allows for dynamic addition/removal of verbs, so you don't have to manually add or remove them from lists.
In response to Alathon
mob
verb
Add_Verbs()
verbs += typesof(/mob/admin/verb) - /mob/admin/verb
admin
verb
admin1()
admin2()
admin3()

That has always worked for me. I'll go run some tests because that could mean some problems for some of my projects if it doesn't work. Well, not that much trouble, just inconvenience :p
In response to Alathon
Alathon wrote:
I've had the same problem, and have also come up blank. Here's yet another way:

mob/Login()
..()
if(you_are_the_admin)
var/mob/admin/M = new
for(var/verb/v in M.verbs)
if(!(v in src.verbs)) src.verbs += v
del M

This allows for dynamic addition/removal of verbs, so you don't have to manually add or remove them from lists.

I used to do that myself before I found that typesof() worked; now I use that. The only problem is, there are times when it doesn't. No idea why.

Lummox JR