ID:139306
 
Code:
var/mob/Player
equipwep=0
equiparm=0

obj
weapon
verb
equipwep()
set name = "Equip Weapon"
if (equipwep == 1)
usr<<"<b> A weapon is already equipped!"
else
equipwep += 1
usr.overlays+=src.icon
usr<<"<b> You equip a weapon!"
UnequipW()
set name = "Unequip"
if(equipwep ==0)
usr<<"<b> Equip something first!"
else
equipwep -= 1
usr.overlays-=src.icon

usr<<"<b> You un-equip your Weapon!"

obj
armor
verb
equiparm()
set name = "Equip Armor"
if(equiparm == 1)
usr<<"<b> Armor is already equipped!"
else
equiparm += 1
usr.overlays+=src.icon
usr<<"<b> You equip some armor!"
UnequipA()
set name = "Unequip"
if(equiparm ==0)
usr<<"<b> Equip something first!"
else
equiparm -= 1
usr.overlays-=src.icon

usr<<"<b> You un-equip your Armor!"


Problem description:

This is the equipment system i've developed. I am a novice programmer and this is the first equip system ive worked on. This code seems to work in game, I cant equip two different weapons or armor. but I think that if two or more players tried to equip something it wouldnt work, because I set the equiparm and wep variable in Player.I have no way of testing this, and I was just wondering if anyone could tell me if this is true or im just being paranoid.
Well, you'd be correct. The issue is how you declared the variable: with var first, you are declaring a global variable. The /mob/Player after var just declares that the variable should be treated as type /mob/Player. What you actually want is mob/Player/var/whatever. Additionally, in the equip and unequip verbs, you will have to use usr.whatever to access the variables, rather than just whatever, as the variables are no longer global.
In response to Garthor (#1)
obj
weapon
verb
equipwep()
set name = "Equip Weapon"
if (usr.equipwep == 1)
usr<<"<b> A weapon is already equipped!"
else
usr.equipwep += 1
usr.overlays+=src.icon
usr<<"<b> You equip a weapon!"
UnequipW()
set name = "Unequip"
if(usr.equipwep ==0)
usr<<"<b> Equip something first!"
else
usr.equipwep -= 1
usr.overlays-=src.icon

usr<<"<b> You un-equip your Weapon!"


obj
armor
verb
equiparm()
set name = "Equip Armor"
if(usr.equiparm == 1)
usr<<"<b> Armor is already equipped!"
else
usr.equiparm += 1
usr.overlays+=src.icon
usr<<"<b> You equip some armor!"
UnequipA()
set name = "Unequip"
if(usr.equiparm ==0)
usr<<"<b> Equip something first!"
else
usr.equiparm -= 1
usr.overlays-=src.icon

usr<<"<b> You un-equip your Armor!"



mob/Player/var
equipwep=0
equiparm=0



I made the changes you said and its still telling me that its an undefined variable :/. What else could i do to reference it?

Edit: I took the Player out of mob/Player/var and it works now. But I still think it would be sorta the same as the global variable, it would probably allow only one equip for all mobs.
In response to Boxcar (#2)
Oops, wasn't thinking: the variable usr is of type /mob, so you are unable to access any members of /mob/Player from it. Either cast it to a /mob/Player (var/mob/Player/P = usr in each verb, and use P) or move the variables to /mob.
In response to Garthor (#3)
Yeah i just got rid of player and set the variables under mob/var and it works. Thanks!