ID:178983
 
As the topic says, I'm only trying to allow a particular class to equip an item. My idea is to have a list (or as I'm used to calling it, an array) to hold the information as to if a class can equip the item, with a 0 not allowing it, and a 1 to allow it. Here is my code:

-------
obj
var
strbonus
classallow[2]
weapons
icon = 'weapons.dmi'
verb
get()
set src in oview(0)
src.Move(usr)
equip()
set src in usr
if (classallow[usr.classnum] == 1)
if (!usr.weapon)
usr.strequip += src.strbonus
src.verbs += /obj/weapons/proc/unequip
src.verbs -= /obj/weapons/verb/equip
src.suffix += "Equipped"
usr.weaponname = "[src.name]"
usr.weapon = 1
else
usr << "You already have a weapon equiped"
else
usr << "You can't equip this"
drop()
set src in usr
if (src.suffix == "Equipped")
usr << "item is equipped, can't drop"
else
del (src)
proc
unequip()
set src in usr
if (!usr.weapon)
usr << "You don't have anything equiped"
else
usr.strequip -= src.strbonus
src.verbs -= /obj/weapons/proc/unequip
src.verbs += /obj/weapons/verb/equip
src.suffix = ""
usr.weaponname = ""
usr.weapon = 0
stick
icon_state = "stick"
name = "Stick"
strbonus = 5
classallow[1] = 1 // <--- Error Here
classallow[2] = 0 // <--- Error Here
sword
icon_state = "sword"
name = "Sword"
strbonus = 10
classallow[1] = 1 // <--- Error Here
classallow[2] = 0 // <--- Error Here

------
Here are the errors that I'm getting

------
weapons.dm:47:error:classallow:left-hand side must be an object variable
weapons.dm:48:error:classallow:left-hand side must be an object variable
weapons.dm:53:error:classallow:left-hand side must be an object variable
weapons.dm:54:error:classallow:left-hand side must be an object variable

New world chat.dmb - 4 errors, 0 warnings (double-click on an error to jump to it)
-------

I've looked for a while to see if there were any messages with this subject, and haven't found any. If there is one, I'm sorry, I must have overlooked it. I'm not trying to just get by with having other people do the coding. I have been stuck with this idea for a few days now, and haven't come up with a way to resolve it.

Also, the code does work with equipping and removing of items before i tried to implement this.

Thank you for any help that you may give in advance.
Rubius wrote:
classallow[1] = 1 // <--- Error Here
classallow[2] = 0 // <--- Error Here

You can't set list elements like this in the var declaration; you can only use that kind of statement in a proc. The correct declaration would look like this:
var
list/classallow=list(1,0)

However, using simple numerical values for this is a really bad way to go. I suggest pointing each weapon to the classes who can use it--or better yet, pointing each class to the weapons (or types of weapons) they can use.

For example, suppose your list looked like this:
var
list/classallow=list(/mob/warrior,/mob/soldier)

Then all you have to do is check:
if(usr.type in weapon.classallow)
...

But better still is this strategy:
... // equip verb (src=weapon)
var/thetype
var/mob/M=usr
for(thetype in M.weapontypes)
if(istype(src.type,thetype)) break
if(!thetype)
usr << "You can't equip [src]."
return
... // go ahead and equip it

In this scenario, every mob has a var/list/weapontypes that looks like this:
mob/warrior
weapontypes=list(/obj/item/weapon) // all weapons

mob/rogue
weapontypes=list(/obj/item/weapon/knife,
/obj/item/weapon/mace,
/obj/item/weapon/sword/onehanded)

Lummox JR
In response to Lummox JR
Ohhhhh. That was my idea, but i was completely lost on where to go from there. Thank you for the help. Now I think that I can go on with this. Again, thank you.