ID:154893
 
There's any better way to simplify this code ..

obj/Gear
var
LevelReq=1
Equipped=0
HeadOn=0;ChestOn=0;
PantsOn=0;ShoesOn=0;
Hand1On=0;Hand2On=0
GearStr;GearDef;
GearPow;GearPowDef;
GearAgi;GearLuck
Color="White"
verb
Equip()
set src in usr
for(var/obj/Gear/G in usr.contents)
if(G.LevelReq>usr.Level)
usr<<"Your level is to low to equip this!"
return
if(G.ChestOn==1) return
if(G.HeadOn==1) return
if(G.PantsOn==1) return
if(G.ShoesOn==1) return
if(G.Hand1On==1) return
if(G.Hand2On==1) return
if(!Equipped)
Equipped=1
usr.suffix="Equipped"
usr.Str+=G.GearStr;usr.Def+=G.GearDef;
usr.Pow+=G.GearPow;usr.PowDef+=G.GearPowDef;
usr.Agi+=G.GearAgi;usr.Luck+=G.GearLuck
usr<<"You have put on [G]"
else
Equipped=0
usr.suffix=""
usr.Str-=G.GearStr;usr.Def-=G.GearDef;
usr.Pow-=G.GearPow;usr.PowDef-=G.GearPowDef;
usr.Agi-=G.GearAgi;usr.Luck-=G.GearLuck
usr<<"You have unequipped [G]"


And if there's any error in that code I would like to know what I did wrong.
Thank you.
Bump..
Till waiting for an answer please.
Don't think so, what's wrong with that?
In response to BloodyJr
I made that code, but I think all that IF chain is nonsense.. There should be a better/simple way to do it.. I am trying to make a Slot Equipment system..
I don't understand what all of the variables are for (ex: ChestOn, HeadOn, etc.). I also don't understand why there's the for() loop - the Equip() verb is on an object, so src is the object you're equipping.

If you can explain what all of these variables are for I might be able to make sense of it and suggest some ways to improve it.
In response to Forum_account
Those variables was to make or try to make a Slot Equipment system, but I realised it now, after testing it makes nonsense ...
I was trying to make soemthing like, A head gear goes for Slot="Head" .. But if it's something already in that slot, you cannot equip..
The for loop is to check if the gear is in user's inventory.
Hope I was clear. Thank you.
You need to make sure that the item's slot isn't already filled. As it is right now, you could put some pants on, but be restricted from a shirt. You are checking everything.
In response to BloodyJr
There used to be demo of equipment system you want, I cannot seem find it now, so I'll just write pseudocode:
mob/var/list/equipment = list("Head", "Chest", "Hand")

obj/Gear
var
slot = ""
StrUp = 0
Armor
slot = "Chest"
StrUp = 5
Helmet
slot = "Head"
StrUp = 1
verb/Equip()
var/obj/Gear/CurrentlyEquipped = usr.equipment[slot]
if(CurrentlyEquipped)
CurrentlyEquipped.Unequip()
usr.Str += StrUp
usr.equipment[slot] = src
verb/Unequip()
var/obj/Gear/CurrentlyEquipped = usr.equipment[slot]
if(CurrentlyEquipped) // extra check in case someone decides to mess with verbs
usr.Str -= StrUp
usr.equipment[slot] = null
In response to Zaoshi
Thanks Zaoshi for the help, I'll make use of it even though I want to try to understand it and try to make my own.
It seems like I don't have much experience, never though of creating a list anyways..I should see more tutorials.