ID:1976641
 
(See the best response by Konlet.)
What would be the appropriate syntax if I wanted to put on a suit at once rather than equipping each part of the suit one click at a time? For example at the moment I have
obj
clothes
School
icon='Schoolhat.dmi'
icon='Schoolvest.dmi'
icon='Schoolslacks.dmi'
icon='Schoolshoes.dmi'
Best response
Huh.. I don't REALLY understand, but I can give a few examples.

If you wanted to be able to equip/unequip different articles of clothing simultaneously, you'll need to make them into diferent objects.

obj/clothes/School
hat/icon = 'Schoolhat.dmi'
vest/icon = 'Schoolvest.dmi'
slacks/icon = 'Schoolslacks.dmi'
shoes/icon = 'Schoolshoes.dmi'


To create an equipping system, you could do something like this:
obj/clothes/School
var
is_on = FALSE
Click()
..()
if(!is_on)is_on = TRUE
else is_on = FALSE
usr.updateOverlays() //For removing/adding overlays.


mob/proc/updateOverlays()
src.overlays = null
for(var/obj/clothes/School/A in src)
if(A.is_on)src.overlays += A


But, if you wanted to equip all in your person at once, you could do something like this at the simplest:
mob/verb/equip_all()
for(var/obj/clothes/School/A in src)
if(!A.is_on)A.Click()
So, what I have is:
obj
Clothes
Suit
SchoolHat
icon='SchoolHat.dmi'
SchoolVest
icon='SchoolVest.dmi'
SchoolSlacks
icon='SchoolSlacks.dmi'
SchoolShoes
icon='SchoolShoes.dmi'
var worn=0 //Represent it is off
verb
wear()
set src in usr
if(src.worn==1)
usr<<"you're alreadying wearing the [src]"
return 0
else
usr.orverlays+=src //to put the src on usr
src.worn=1
usr<<"You put on the [src]."
takeoff()
//I won't go in further since it's not relevant.
mob/verb
PutOnSuit()
//This is currently working as a pickup/summon verb
usr.contents+=new/obj/Clothes/Suit/School

This is what I have prior to adding any new codes. It works with individual items, but then after figuring out how to edit your codes to mine, it doesn't seem to fully work. Also, I'm assuming A is atom.
mob/verb
equip_all()
for(var/obj/Clothes/Suit/School/A in src)
if(!A.worn)
A.wear()
As Konlet mentioned you should ideally use overlays for clothes as this will allow you to add multiple individual parts to the player's icon.

You mention that you want a single item that causes the player to have multiple overlays at the same time.

A rough version of that approach would look like this:

// clothes.dm

/obj/clothes
var/worn = FALSE // TRUE if worn, FALSE if not

// This should return a list of overlays to apply to the player
/obj/clothes/proc/GetOverlays()

/obj/clothes/verb/wear() // TODO: create a nicer-looking way of allowing players to wear things
set src in usr.contents

src.worn = !src.worn
usr.UpdateOverlays()

// TODO: prevent players from dropping clothes they are currently wearing (or "unwear" them prior to dropping)
// TODO: prevent players from wearing conflicting clothing articles

/obj/clothes/School
icon = 'Schoolvest.dmi' // pick one icon to represent the suit

/obj/clothes/School/GetOverlays()
return list(image(icon = 'Schoolhat.dmi'), image(icon = 'Schoolvest.dmi'), image(icon = 'Schoolslacks.dmi'), image(icon = 'Schoolshoes.dmi'))

...
// mob.dm

/mob/proc/UpdateOverlays()
// Clear overlays.
src.overlays = list()

// Apply overlays based on what the player is wearing.
var/list/L
for (var/obj/clothes/obj in src.contents)
if (obj.worn)
L = obj.GetOverlays()

if (L && L.len)
src.overlays.Add(L)

I hope this helps.
Alright. I'm not sure what the difference is atm, but I'll check. There was one problem with your codes, and that was defining worn for 'obj' twice. I don't believe you needed to do it twice since it was mentioned for everything within obj/clothes. I am curious, is there suppose to be a level with overlay? Say I wanted to have a shirt and then a coat or maybe a gun belt on top of that shirt.
In response to Ash Abe Add
Ash Abe Add wrote:
There was one problem with your codes, and that was defining worn for 'obj' twice.

Oops! I've edited my post.

I don't believe you needed to do it twice since it was mentioned for everything within obj/clothes

That's correct. Uh, well, you passed my test. ;P

I am curious, is there suppose to be a level with overlay? Say I wanted to have a shirt and then a coat or maybe a gun belt on top of that shirt.

By default overlays will be applied in the order that they are given. You can use the layer attribute to decide the way that overlays are ordered but for clarity I recommend adding them in the right order through code. Setting the layer variable might cause you to miss something later, but if you always send it through in the right order you'll immediately be able to fix something that isn't right.
Then is that what's happening in this code if I added a second suit? Shouldn't there be a way to remove it without removing from the inventory? This is a bit unrelated, but it happened while doing this, but is there a reason why there's sometime a, like an IE symbol next to an icon after creating it? When double clicking it leads to the window box?
In response to Ash Abe Add
Ash Abe Add wrote:
Then is that what's happening in this code if I added a second suit?

Yes, if you were to wear two suits at the same time one would be added after the other. Keep in mind that the order between suits is undefined, so they may end up being added in either order. But the individual components of the suit (hat, shirt, pants, etc.) would be added in the order provided.

Shouldn't there be a way to remove it without removing from the inventory?

In my psuedo-code you can do this by using the "wear" verb again. The UpdateOverlays() proc first removes all overlays and then adds them again. I.e., the player is stripped naked and then their clothes are (re)applied. This is how the clothes are removed.

This is a bit unrelated, but it happened while doing this, but is there a reason why there's sometime a, like an IE symbol next to an icon after creating it? When double clicking it leads to the window box?

I don't understand what you mean. An Internet Explorer icon?
I'm thinking now, as I was preparing what to write, that maybe I need to add another line of code, to tell wear() which suit is desired. On the other hand, this picture will show you what I mean. It's in the topleft corner, as you should be able to see.

http://www.picturetrail.com/sfx/album/view/24681214
  1. That behavior seems like a BYOND bug to me.
  2. You can't define icon multiple times on the same object.
  3. The wear() verb already knows which suit is desired because it's bound to a specific object. src references the clothing article which the player would like to wear in this context.
As mentioned in item no. 2 the following code is not valid:
obj
Clothes
icon = 'CSRedShirt.dmi'
icon = 'CSGreenShirt.dmi'
icon = 'CSBlueShirt.dmi'

This won't work. The sample above is structurally the same as:
obj
Clothes
icon = 'CSBlueShirt.dmi'

In other words, only the last icon will be defined, the previous lines are ignored.

You should try setting it up using my example with the AddOverlays() proc. Bear in mind it's not just something you can copy/paste -- it's intended as an example so you can learn how to do it right, not as a solution to your specific problem.

Something else you may want to try is reading the DM Guide. It's intended to explain how BYOND works for beginners and should help you understand how the structure and syntax works.
No, ignore the code, look at the side window with all of the extensions. There's a testa.dmm and underneath is a Clothes folder. If you look there's an icon that's not, for me, traditionally there.
In response to Ash Abe Add
Ash Abe Add wrote:
No, ignore the code, look at the side window with all of the extensions. There's a testa.dmm and underneath is a Clothes folder. If you look there's an icon that's not, for me, traditionally there.

Yeah. As I mentioned in item no. 1, it's probably a BYOND bug. Or an issue with Windows. I'll page Lummox JR to look at that issue, he'll probably be able to explain it.
Ah, I've seen it over the years here and there, and it's annoying. I usually just end up staring a new project and rewriting and drawing everything. The hassle. lol, but alright!