ID:166296
 
this is one of the hats


obj
bluepiratebandana
name = "blue pirate bandana"
icon = 'bpb.dmi'

DblClick()
if(src.loc == usr)
if(usr.hatequipped==1)
usr.hatequipped = 0
usr.overlays -= 'bpb.dmi'
usr.Def -= 5
usr.Str -= 18
src.suffix = ""

return
else
usr.hatequipped = 1
usr.overlays += 'bpb.dmi'
usr.Def += 5
usr.Str += 18
src.suffix = "Equipped"

return


with this kind of equipped code how can i make it so one and only one thing is equipped at a time?

heres the other thing almost the same thing exept for the stat +


obj
redpiratebandana
name = "red pirate bandana"
icon = 'rpb.dmi'
DblClick()
if(src.loc == usr)
if(usr.hatequipped==1)
usr.hatequipped = 0
usr.overlays -= 'rpb.dmi'
usr.Def -= 12
usr.Str -= 9
src.suffix = ""

return
else
usr.hatequipped = 1
usr.overlays += 'rpb.dmi'
usr.Def += 12
usr.Str += 9
src.suffix = "Equipped"

return



when i equip both at the same time and unequip them all the str and def get a major mess up i get in the -30 def and stuff so it would work if only one could be equipped at a time.
Where you get dat code from?
mob/var
redhatequipped
bluehatequipped
obj
redpiratebandana
name = "red pirate bandana"
icon = 'rpb.dmi'
DblClick()
if(src.loc == usr)
if(usr.redhatequipped)
usr.redhatequipped = 0
usr.overlays -= 'rpb.dmi'
usr.Def -= 12
usr.Str -= 9
src.suffix = ""
return
else
if(!usr.bluehatequipped)
usr.redhatequipped = 1
usr.overlays += 'rpb.dmi'
usr.Def += 12
usr.Str += 9
src.suffix = "Equipped"
return

bluepiratebandana
name = "blue pirate bandana"
icon = 'bpb.dmi'

DblClick()
if(src.loc == usr)
if(usr.bluehatequipped)
usr.bluehatequipped = 0
usr.overlays -= 'bpb.dmi'
usr.Def -= 5
usr.Str -= 18
src.suffix = ""
return
else
if(!usr.redhatequipped)
usr.bluehatequipped = 1
usr.overlays += 'bpb.dmi'
usr.Def += 5
usr.Str += 18
src.suffix = "Equipped"
return
In response to Kore2
Good gads man, never try to help someone fix their broken code by supplying worse code. If you don't know what you're doing yet, this is not the time for you to offer someone help. Otherwise it's the blind leading the blind.

Having a var set to just 1 or 0 to say if something is equipped is completely bogus. There are many right ways to create an equipment system, but all of them have one thing in common: A var (or list) belonging to the mob points to the object that is equipped, or null if none. The equipment itself does not keep track of whether it's equipped, and the mob must have more information than "Gee, I'm using something but I don't know what." E.g.:
mob
var/obj/item/weapon/weapon // set this to the weapon itself

Boraken's hatequipped var would have worked but for one problem: He was setting it to 1 and 0, not to an object and null. He had the setup mostly right but wasn't giving it the right information. If he set it to the exact hat he had equipped, he wouldn't have had such a problem.

Having a separate var for each possible sub-type of equipment however is ridiculous beyond the pale. Of all the equipment system methods I've ever seen on these forums, you have managed to come up with the absolute worst. Not only is it the pinnacle of bad design, but it doesn't even solve Boraken's problem! The two items can still be equipped at the same time. Unless the vars represent separate equipment slots, there's no reason to have two of them. One slot, one var.

It's okay to be new to this and not know where to go next. Really it is. It's fine if your own code is a mess, because you can post here and get help with it. But if someone else tries to answer your question with something that will throw you off track because it's dead wrong (or worse, works under some conditions but introduces a dozen new bugs), they've done you a disservice. For the sake of the others who use this forum, I implore you not to post code help until you're in a position to do so.

Lummox JR
In response to Lummox JR
so would it be

mob
var/obj/item/hat/redpiratehat


if you could just give me a little more info i think i could get it but i have never seen it done like this anywhere.
thanks
In response to Boraken
No. It would be:

mob
var/obj/item/hat/hatslot


Assuming you have a /obj/item/hat path defined, in which all your hats reside.

Then, instead of setting a 'I have a hat equipped' variable to one, you set the hatslot variable to the hat you have equipped - you keep a reference.
In response to Jp
wait i find my self getting more and more lost
so it would be

mob
var/obj/item/hat/hatslot


but what var do i use if i dont use =1 or =0?

i was gona look at other demos but they make it harder becouse they have alot of different ways of doing it all.


or hatslot=0
and hatslot=1?
In response to Boraken
you're supposed to set the item equipped to the slot.

e.g.
mob
var/obj/bellyfood = null

obj
item/redpie
str = 30
desc = "Ahoy there me matey! Would ye like to taste sum' of me pies o' value? Said billyBOB, the 'pie'rate."
verb/eat_the_pie_or_puke_out_the_pie()
set src in usr
if(!usr.bellyfood)
usr.bellyfood = src
usr.hunger -= usr.bellyfood.str
else
usr.hunger += usr.bellyfood.str
usr.bellyfood = null


In response to DivineO'peanut
mob
var/obj/hatslot = null

obj
item/redpiratebandana
str = 30//???? what is the str in my case
desc = "a red pirate hat."
verb/eat_the_pie_or_puke_out_the_pie()
set src in usr
if(!usr.hatslot)
usr.hatslot = src
usr.????? -= usr.hatslot.str//??? what does hunger =? overlay?
else
usr.????? += usr.hatslot.str
usr.hatslot = null


i get most of it but what does the hunger = if i were to go a armor equip code with it?




In response to Boraken
var/obj/redpiratehat
obj
redpiratebandana
name = "red pirate bandana"
icon = 'rpb.dmi'
DblClick()
if(src.loc == usr)
if(usr.hatequipped==redpiratehat)
usr.hatequipped = null
usr.overlays -= 'rpb.dmi'
usr.Def -= 12
usr.Str -= 9
src.suffix = ""

return
else
usr.hatequipped = null
usr.overlays += 'rpb.dmi'
usr.Def += 12
usr.Str += 9
src.suffix = "Equipped"


return



does that look right? if not what is missing also what can make it so they cant equip more than one hat at a time?
In response to Boraken
No, that isn't right. You really need to do some basic reading up in the DM Guide and the reference, because I can tell you're pretty lost here. Wizkidd0123 has a good equipment system demo as well that you can learn from.

I cannot stress enough that you should have no var named redpiratehat. Kore2's advice was bad in the extreme and you should forget that post ever existed.

What you're trying to do in this code snippet is adjust your code to handle each individual type of hat, which is wrong:
obj
redpiratebandana
name = "red pirate bandana"
icon = 'rpb.dmi'
DblClick()
if(src.loc == usr)
if(usr.hatequipped==redpiratehat)
usr.hatequipped = null
usr.overlays -= 'rpb.dmi'

Wrong. To tell if this is the object that was equipped, you need to change one line:
if(usr.hatequipped==src)

Truthfully this entire system is a bit messed up, because you're defining your equipment procs in DblClick() when they should be done in their own procs. That way you can use verbs and other methods to also handle equipping/unequipping items, for user-friendliness.
obj/item/hat
var/strbonus
var/defbonus

proc/Equip(mob/M)
if(loc!=M) return
if(M.hat) M.hat.Unequip(M)
M.hat = src
M.Str += strbonus
M.Def += defbonus
M.overlays += icon

proc/Unequip(mob/M)
if(M.hat!=src) return
M.hat = null
M.Str -= strbonus
M.Def -= defbonus
M.overlays -= icon

It's simple, it's clean, and it's not too specific so you can extend the system easily.

But you definitely need to read the Guide and Wizkidd's tutorial, because your whole approach to this problem has been wrong. Not so much the code itself, but the way you only partly read what people are saying and try to haphazardly incorporate multiple people's advice without thinking it through. (Also, following Kore2's code even a little bit after it was shown to be utterly worthless wasn't the best idea.) You need to be a little bit more methodical about your approach, not just try to slap things together at random and see if they work.

Lummox JR
In response to Lummox JR
Ok I am trying to make a more proffesional code since the last code was just thrown together.

mob/var/obj/item/hat=null // what well set our hat to
obj/var/addstr
obj/var/adddef
obj/item/hat
DblClick() //If you double click on any obj/item/hat
if(src.loc==usr) // and if the obj is in usr
if(!usr.hat) // and if the usr doesn't have a hat equipped
usr.Equip(src) //call the Equip proc
else if(usr.hat==src) // if the usr has a hat equipped and if the usr's hat is the hat we clicked on.
usr.UnEquip(src) // call the UnEquip proc
RedPirateHat
name = "Red Pirate Bandana"
icon='rpb.dmi'
addstr=18
adddef=10
BluePirateHat
name="Blue Pirate Bandana"
icon='bpb.dmi'
addstr=18
adddef=5

mob/proc/Equip(obj/O)
if(istype(O, /obj/item/hat)) //if O is under /obj/item/hat
if(!src.hat)// if the usr doesn't have an hat.
src.hat=O // changes usr's hat to O
src.str+=O.addstr // we add O's bonus strength.
src.def+=O.adddef // we add O's bonus def
src.overlays+=O // Add O's icon as an overlay
else // else if we have an hat on.
if(src.hat!=O)return // if O is not the hat we have on then return.
if(src.hat==O)src.UnEquip(O) // if the hat is O then call the Unequip proc.

mob/proc/UnEquip(obj/O)
if(istype(O, /obj/item/hat))
if(src.hat==O)
src.hat=null
src.str-=O.addstr
src.def-=O.adddef
src.overlays-=O


Also tested and it works for me.

Edit: Added istype() procs in the Equip and Unequip procs to avoid some bugs.
In response to Kore2
ok thanks alot Lummox JR a little after this post fell under all of the other posts i found a equip code im using now but the one u just showed saves me time i think i will use that one :) kore i cant tell if that one is right i will wait till see what lummox JR says about it.
thanks


one last thing will that not alow people to equip more than one thing like 3 hats at a time?
but i want them to be able to use
1-hat
1-body
1-leg
1-shield

or anything else i wanted to add like ring or somthing.

Boraken-
In response to Boraken
also this thing

obj/clothes

Blue_pirate_bandana
name = "Blue pirate bandana"
icon = 'bpb.dmi'
density = 0

worn = 0
// value = 2000

var
hat = 'bpb.dmi'
def = 17

DblClick()

if(usr.hatslot == 0)
if(usr.hat == 0)
usr.overlays += hat
usr << "<font size = -1><font size = -1>You have equiped the: <u>[src]</u>."
suffix = "(Worn)"
usr.hat = 1
usr.hatslot = 1
src.worn = 1
usr.Def += 11
else
usr.overlays += hat
usr << "<font size = -1><font size = -1>You have equiped the: <u>[src]</u>."
suffix = "(Worn)"
usr.hat = 1
usr.hatslot = 1
src.worn = 1
usr.Def += 11
else

if(usr.hat == 1)
if(src.worn == 1)
usr.overlays -= hat
usr << "<font size = -1>You have unequip the: <u>[src]</u>."
suffix = null
usr.hat = 0
usr.hatslot = 0
src.worn = 0
usr.Def -= 11
else

usr << "<font size = -1><B><font size = -1>Error: </b>You may only have one of: <u>[src.name]</u> equiped."
return


verb

Pick_Up()
set src in oview(0)
set category = null
if(Move(usr))
usr << "<font size = -1>You have picked up the: <u>[src]</u>."
else
usr << "<font size = -1>You are unable to pick up the: <u>[src]</u>."

Drop()
set category = null
if(src.worn == 0)
src.loc = usr.loc
usr << "<font size = -1>You have dropped the: <u>[src]</u>."
else
usr << "<font size = -1>You are unable to drop: <u>[src.name]</u>, it's already equipped."
for some reason it says src.worn:undefined var but i did define it with mob/var/worn = 0 my friend said this is a good one to use if i want somthing that does not let ppl equiped alot of this why does it say that i did not define it?
i know it was somthing to do with src. and a way i defined it wrong but i just dont know im still learing this kind of stuff.
In response to Boraken
worn was defined for mobs, not for objs.
In response to Boraken
Well one thing you don't need is the worn var. An object should not be responsible for keeping track of whether it's in use; that's the mob's job.

As for your question about using multiple slots, there are two general ways to do this and probably more. There's the simple way:
mob
var/obj/item/hat/hat
var/obj/item/armor/armor
var/obj/item/greaves/greaves // leg protection
var/obj/item/shield/shield

Then there's the less simple but more extensible way:
obj/item
var/slot // the equipment slot this item uses

// the item type should have get, drop, etc. verbs
// if equippable, it should have Equip() and Unequip() verbs

mob
var/list/equipment

proc/EquipItem(obj/item/O)
if(!O.slot || O.loc != src) return 0
if(!equipment) equipment = new
else if(equipment[slot])
if(!UnequipItem(slot))
// let the proc return 0 if it can't be unequipped, like if it is cursed
return 0
equipment[slot] = O

// here you would add to stats for this item, add overlay, etc.
// ...

return 1

proc/UnequipItem(slot)
if(!equipment || !equipment[slot]) return 0
var/obj/O = equipment[slot]
// here you would check for curses, return 0 if it can't be removed
// but otherwise...
equipment[slot] = null

// here you would subtract from stats for this item, remove overlay, etc.
// ...

return 1

The list-based slot system has several advantages. One minor disadvantage however is that it does not easily allow for multiple-use items or for multiple similar slots (e.g., putting a ring on the left or right hand).

Lummox JR
In response to Lummox JR
ok i got it to work good now and also put every piece of info u guys gave on paper so i refer to it later on
thanks guys. :)
In response to Lummox JR
You could have multiple slots used for equipment using an associative list system, it's just a little more complex.

The slot variable could be either a text string or a list of text strings. You can check what it is in the equip proc, if it's a text string, handle as normal, if it's a list, just use all the slots in the list. Not massively difficult.

There might be some problems with the number of lists if every two-handed sword in the world has one associated it, so maybe you should have a GetSlot() proc on the equipment that returns the slot it uses, rather then a slot variable. Now that I think about it, this could make a good library...