ID:269491
 
Hello,

i was wondering if anyone could hlep me with my perdicament

armors.equable.Find(usr.class)

what kind of IF statement should i have once it finds usr.class in equable?
maybe

if(armors.equable.Find(usr.class))
//blah...


a guess, don't hold it against me if incorrect

--Vito
Dark_rathen wrote:
Hello,

i was wondering if anyone could hlep me with my perdicament

armors.equable.Find(usr.class)

what kind of IF statement should i have once it finds usr.class in equable?

Well, you have a bigger problem here.

First, when only searching to see if something is in a list, always use the in operator instead of Find(). It's more robust because it will work if armors.equable is accidentally null.

if(usr.class in armors.equable)


But the bigger problem is that giving a list to every piece of armor is going to potentially run you up against the list limit. There are two better ways to do this.

You could use bit flags, if you have a limited number of classes (up to 16), and give the armor a number corresponding to the classes which can use it. Each mob would also have a number telling you its class. Note that you can use hybrid classes too which count as two different types, and that wouldn't count against the 16-class limit. That would look something like this:

if(armor.classflags & usr.classflags)


Therefore if something is usable by a thief, it's usable by a rogue class that combines thief and warrior. Some games offer class combinations like this as character upgrades past a certain level. Also you can make a special flag set for items that can't be used, such as evil spells by a healer or paladin.

if(spell.forbiddenflags & usr.classflags)
usr << "You can't use [src]."


Another method, simpler in some respects than bit flags but harder to implement, is to store the equable list in an associative list. I.e., you'd load from the file:

var/savefile/F = new('equable.sav')
F["equable"] >> equable


And that file might look something like this:

equable = list(\
/obj/item/armor/scale = list("rogue","thief"),\
/obj/item/armor/plate = list("knight", "warrior"),\
...
)


To use the list you'd check the following:

if(usr.class in equable[armor.type])


I heartily recommend the bit flag approach above, because it supports up to 16 base classes with room to combine classes, plus you can make something all-usable by giving it a flag of 65535.

Lummox JR
In response to Lummox JR
That's what I meant. Yeah, that's it...

--Vito