ID:263129
 
Code:
        equip()
switch(alert("Would you like to eguip this to your Main Hand or Off Hand?","Equip","Main Hand","Off Hand"))
if("Main Hand")
if(usr.armr!=0)
usr << "You cannot equip this to this arm."
else if(suffix=="Equipped")
usr << "This is already equipped."
else
suffix = "Equipped"
usr.overlays += /obj/sr
usr.armr = 1
usr.armrn = src.name
if("Off Hand")
if(usr.arml!=0)
usr << "You cannot equip this to this arm."
else if(suffix=="Equipped")
usr << "This is already equipped."
else
suffix = "Equipped"
usr.overlays += /obj/sl
usr.arml = 1
usr.armln = src.name
unequip()
if(usr.armrn!=src.name)
if(usr.armln!=src.name)
usr << "You do not have this equipped."
else
suffix = null
usr.overlays -= /obj/sl
usr.arml = 0
usr.armln = ""
else
suffix = null
usr.overlays -= /obj/sr
usr.armr = 0
usr.armrn = ""

axe
icon = 'Weapons.dmi'
icon_state = "Axe1"
name = "Starter Axe"
sr
icon = 'Weapons.dmi'
icon_state = "Axe2"
layer = MOB_LAYER + 20
sl
icon = 'Weapons.dmi'
icon_state = "Axe3"
layer = MOB_LAYER + 20
shield
icon = 'Weapons.dmi'
icon_state = "9"
mob
var
armr = 0
armrn = ""
arml = 0
armln = ""


Problem description: Very odd glitch/bug... When unequipping the item that is in the offhand while both axes are equipped, it removes the main hand axe. Then, to more extent, when I unequip the same axe again... it removes the off hand axe. So basically here's what it looks like... (All Messages in parentheses are not what they look like ingame, they are purely for informational purposes)

Axe > Equipped (Mainhand)
Axe > Equipped (Offhand)

USER --> Unequip Axe (Offhand)

(Ingame, Mainhand becomes unequipped)

Axe > Equipped (Mainhand)
Axe > (Offhand)

USER -- Unequip Axe (Again) (Offhand)

(Ingame, Offhand becomes unequipped)

Axe > Equipped (Mainhand)
Axe > (Offhand)

(Notice also that the Mainhand axe doesn't remove the suffix either.)

Thanks so much if you can help me.


Well, let's start by fixing the obvious problem first: Your equipment system is done wrong. You have the usr.armr var which is just set to 1 or 0, which is a complete waste, and then the totally extraneous usr.armrn var to keep track of the armor's name.

The correct way to implement an equipment system is for the mob to have a var pointing to the object itself, or null if none is equipped. Hence, usr.armor=src to equip.

Lummox JR
In response to Lummox JR
I'm not sure what/where you are talking about (Chibi=n00b coder).

If it's not too much trouble for you, can you use an example in the code?
In response to Chibi_Gohan111
obj/item
var
two_handed=FALSE
mob
var/obj/item
main_hand
off_hand
verb
hold(obj/o in src)
if(!find("[o.type],"obj/item")) return
else
var/obj/item/i = o
if(i.two_handed)
main_hand = i
off_hand = i
else
var/hand = alert(src,"Hold [o] in which hand?","Hold [o]","Main Hand","Off Hand")
switch(hand)
if("Main Hand") main_hand=o
if("Off Hand") off_hand=o
view() << "[name] holds [o]."
stow(i as null|anything in list("main hand","off hand"))
if(!i)
if(main_hand)
if(off_hand) view() << "[name] puts [main_hand] and [off_hand] away."
else view() << "[name] puts [main_hand] away."
else if(off_hand) view() << "[name] puts [off_hand] away."
main_hand = null
off_hand = null
else switch(i)
if("main hand")
view() << "[name] puts [main_hand] away."
main_hand = null
if("off hand")
view() << "[name] puts [off_hand] away."
off_hand = null


Is that the sort of thing you're looking for?
In response to PirateHead
friggin.... uber coders and their abilities to create code out of thin air...

No seriously, I appreciate it a lot that you spent that much time creating code for the problem. If you aren't that busy, do you think you can explain what some of that means sometime?
In response to Chibi_Gohan111
Please give us some specifics with what ya wanna know

Also, you might wanna read this before asking for the clarification >.>

- GhostAnime
In response to PirateHead
PirateHead wrote:
obj/item
> var
> two_handed=FALSE
> mob
> var/obj/item
> main_hand
> off_hand
> verb
> hold(obj/o in src)
> if(!find("[o.type],"obj/item")) return
> else
> var/obj/item/i = o
> if(i.two_handed)
> main_hand = i
> off_hand = i
> else
> var/hand = alert(src,"Hold [o] in which hand?","Hold [o]","Main Hand","Off Hand")
> switch(hand)
> if("Main Hand") main_hand=o
> if("Off Hand") off_hand=o
> view() << "[name] holds [o]."
> stow(i as null|anything in list("main hand","off hand"))
> if(!i)
> if(main_hand)
> if(off_hand) view() << "[name] puts [main_hand] and [off_hand] away."
> else view() << "[name] puts [main_hand] away."
> else if(off_hand) view() << "[name] puts [off_hand] away."
> main_hand = null
> off_hand = null
> else switch(i)
> if("main hand")
> view() << "[name] puts [main_hand] away."
> main_hand = null
> if("off hand")
> view() << "[name] puts [off_hand] away."
> off_hand = null

Is that the sort of thing you're looking for?

The part with "holds [o]" i mean.... What does the letter o have to do with anything, and the letter i. It really confuses me, the guide that GhostAnime gave me was great for the Boolean stuff, but this part confuses me.
In response to Chibi_Gohan111
Single letters are somthing that are very commonly used for a variable in a proc. They are short, and can generally relate to something (a = area, m = mob, o = obj, t = turf, and so on). And unless you've used them earlier in a proc, you can be sure to use them, because they aren't built-in variables, except for x,y, and z.
In response to Chibi_Gohan111
o is used to refer to an obj. You could use anything, but o is easy to type and it reminds you that you're working with an obj. I used i becase it corresponds to an obj/item, which has the two-handed variable (whereas normal objs don't).

In general, one or two-letter variables are used because they can be typed quickly. Generally, the longer and more complicated the procedure, the longer the variable names are, since it's easier to make sense of longer and more descriptive names.

As far as pulling code out of thin air... man, it really must suck not being able to just put a process into code. Kinda like not being able to talk. If all you can do is piece snippets together, it's sort of like pantomime.

To become a code "wizard", you really need to just write code all the time. Pick some little thing, and do a proof of concept project just to prove to yourself that you can figure out how to do it. After doing a few dozen of those, you'll find that you are capable of writing pretty much anything, given enough background information and logical thinking skills.
In response to PirateHead
PirateHead wrote:
obj/item
> var
> two_handed=FALSE
> mob
> var/obj/item
> main_hand
> off_hand
> verb
> hold(obj/o in src)
> if(!find("[o.type],"obj/item")) return
> else
> var/obj/item/i = o
> if(i.two_handed)
> main_hand = i
> off_hand = i
> else
> var/hand = alert(src,"Hold [o] in which hand?","Hold [o]","Main Hand","Off Hand")
> switch(hand)
> if("Main Hand") main_hand=o
> if("Off Hand") off_hand=o
> view() << "[name] holds [o]."
> stow(i as null|anything in list("main hand","off hand"))
> if(!i)
> if(main_hand)
> if(off_hand) view() << "[name] puts [main_hand] and [off_hand] away."
> else view() << "[name] puts [main_hand] away."
> else if(off_hand) view() << "[name] puts [off_hand] away."
> main_hand = null
> off_hand = null
> else switch(i)
> if("main hand")
> view() << "[name] puts [main_hand] away."
> main_hand = null
> if("off hand")
> view() << "[name] puts [off_hand] away."
> off_hand = null

Is that the sort of thing you're looking for?

Yes, I will try to do "proofs" and such.. but for the time being... I receive a few errors after trying to add this to my code...

World of Warcraft.dm:186:error:obj:undefined var
World of Warcraft.dm:186:error:item:undefined var
World of Warcraft.dm:186:error:find:undefined proc

World of Warcraft.dmb - 3 errors, 0 warnings (double-click on an error to jump to it)

Line 186 = if(!find("[o.type]",obj/item)) return

Sorry if I seem like a pest..
In response to Chibi_Gohan111
1. You probably don't have obj/item defined.
2. It's <code>if(!(Find("[o.type]","obj/item"))</code>
In response to Mysame
That fixed it, Thanks!... Now... it just says:

loading World of Warcraft.dme
World of Warcraft.dm:186:error:find:undefined proc

World of Warcraft.dmb - 1 error, 0 warnings (double-click on an error to jump to it)

Line 186 : if(!find("[o.type]","obj/item")) return


How do I define find... because I think that is a built in thing... no?
In response to Chibi_Gohan111
Why not Search and find out?
In response to Chibi_Gohan111
It should have been findtext(). I really botched that line of code up -- sorry! When I write code on the forums, I usually don't use a compiler. Good practice for you to do some debugging through. :-)

I think the line should be:

if(!findtext("[o.type]","/obj/item")) return


The purpose of the line is to make sure that the obj they're trying to hold is an item, not a tree or whatever other sorts of objs that you might use in your game.
In response to PirateHead
Pirate, do you have AIM or MSN?
In response to Chibi_Gohan111
I sent you an email. The information is there.
In response to PirateHead
Thanks d00d.