ID:164148
 
I want to know how to set up a good equip system, where if the helmet spot was open, the player could click on it and it takes the spot, but if it isn't it would provide a message to the player. So how do I make this work?
mob/var //list of mob varibles
head = 0 // The Head varible. If 0, nothing is equiped. If 1 then something is.
chest = 0 // The Chest varible. If 0, nothing is equiped. If 1 then something is.
// You can put more here, right leg, right arm, right foot, etc.

mob/verb/put_on_helmet() // a test verb for equipping something to the head.
if(src.head == 0) // If the player has nothing on their head
src.head = 1 // Set their head varible to 1, meaning something is equiped.
src <<"You pull on a shiny new helmet!" // Tell them they pull on a new object

// add overlays here, or whatever
else // if they are already wearing something
src <<"You are already wearing something on your head!" // Tell them they already have something equiped

mob/verb/take_off_helmet() // This verb will take off a helmet, this is just for test.
if(src.head == 1) // If the player has something on their head
src.head = 0 // Set their head varible to 0, meaning nothing is equiped
src <<"You take off what is on your head." // Annouce it to them that they remove the object
else // if they are not wearing anything
src <<"You are not wearing anything!" // Tell them they are not wearing anything


These are examples. Switch them over to procs, and you could do this with the slots (Which are objects in a statpanel or an overlay on someone's screen) this is an example:

mob/var //list of mob varibles
head = 0 // The Head varible. If 0, nothing is equiped. If 1 then something is.
chest = 0 // The Chest varible. If 0, nothing is equiped. If 1 then something is.
// You can put more here, right leg, right arm, right foot, etc.

mob/proc/HeadSlotAction() // the proc for adding/removing items
if(src.head == 0) // If the player has nothing on their head
src.head = 1 // Set their head varible to 1, meaning something is equiped.
src <<"You pull on a shiny new helmet!" // Tell them they pull on a new object
// add overlays here, or whatever. Ask them what object they wish to equip.
else // if they are already wearing something
src.head = 0 // Set their head varible to 0, meaning nothing is equiped
src <<"You take off what is on your head." // Annouce it to them that they remove the object
// remove overlays here, or whatever

obj/headslot // The headslot
icon = 'icon.dmi' // set these to your pref
icon_state = "icon" // set these to your pref

Click() // When it is clicked
usr.HeadSlotAction() // Run the process to figure out whether to remove/equip


Then you could add in input boxes to allow them to select what object to equip to the head part. Add a var to object called type and set all helmets and whatnot to "helmet", run an if conditional and see if the object they want to equip is an object that can be equiped to the head, then equip it.

I would recommend when you click the head slot with an item equipped you ask for confirmation to see if the user really wants to remove the item. Much like so:

mob/proc/HeadSlotAction() // the proc for adding/removing items
if(src.head == 0) // If the player has nothing on their head
src.head = 1 // Set their head varible to 1, meaning something is equiped.
src <<"You pull on a shiny new helmet!" // Tell them they pull on a new object
// add overlays here, or whatever
else // if they are already wearing something
switch(alert("Are you sure you want to remove this item?",,"Yes","No"))// Ask them for confirmation
if("Yes") // If they really want to remove the item:
src.head = 0 // Set their head varible to 0, meaning nothing is equiped
src <<"You take off what is on your head." // Annouce it to them that they remove the object
// remove overlays here, or whatever
if("No")
return //Do nothing. Leave it untouched.


Have fun,
Siientx
In response to Siientxx
You should really look up on how to use boolean.. that way, you can set the variables to the object itself and say thing like "[Head.name] is already equipped!"

I made an equipment demo a while ago but it could be greatly improved. ID:556577
In response to GhostAnime
Yeah my last time coding was a year or two ago, so it might be amateur and outdated.
In response to Siientxx
Siientxx wrote:
mob/var //list of mob varibles
head = 0 // The Head varible. If 0, nothing is equiped. If 1 then something is.
chest = 0 // The Chest varible. If 0, nothing is equiped. If 1 then something is.
// You can put more here, right leg, right arm, right foot, etc.


There's really no way to sugarcoat this: That's truly horrible code. It's not merely one of the many wrong ways to do equipment; it's one of the wrongest.

The standard wrong way to do equipment is to give each obj a var that says it's equipped or not. Then at least you can go through your objects to tell which ones are equipped. Having to do that loop process is why this method is wrong.

What makes your method even wronger is that the mob knows something is equipped, but it has no way at all to tell what is equipped.

The correct way to do equipment is to keep vars or a list with the mob, but instead of using 1 and 0, point to the actual object itself.

mob/var
var/obj/item/weapon/weapon
var/obj/item/armor/amror


When equipping a weapon, you'd set mob.weapon=item. To unequip it, you'd set mob.weapon=null. if(mob.weapon) tells you if a weapon in use.

There are other good ways to handle equipment, but they all keep the information with the mob, and they all involve using references to the equipped objects themselves.

Other problems in your code:

  • You're using if(var==1) and if(var==0) to check the status of true/false vars. That should be if(var) and if(!var).
  • The potential preponderance of verbs is a bad, bad thing. You shouldn't have separate verbs for helmets, armor, boots, underwear, etc. Just use an Equip() verb and an Unequip() verb. Having them for each slot tends to annoy players who have to type in the command.

    Lummox JR
In response to Lummox JR
Siientxx wrote:
Yeah my last time coding was a year or two ago, so it might be amateur and outdated.

=P
In response to Lummox JR
What I mean it is like an inventory system but like:
Helm: (image and name)
Body: (image and name)
Legs: (image and name)
so forth......

Silent made it sound really good, but I need to figure out how to do what I want it to do.
In response to DadGun
DadGun wrote:
What I mean it is like an inventory system but like:
Helm: (image and name)
Body: (image and name)
Legs: (image and name)
so forth......

Silent made it sound really good, but I need to figure out how to do what I want it to do.

You can't make such use out of Siientxx's code, because it blows. It will not help you. There are some actual good demos for equipment systems online. Check out the one by Wizkidd0123.

Lummox JR
In response to Siientxx
Siientxx wrote:
Siientxx wrote:
Yeah my last time coding was a year or two ago, so it might be amateur and outdated.

=P

Amateur and outdated would be bad, but far better than sloppy and wrong. To say your code was outdated would be to suggest that approach was ever a good idea. I can see easily forgetting syntax, but design flaws are easy to recognize.

Lummox JR
In response to Lummox JR
Thanks man.