Page 1 of 1

Shuttle Chair armrests

Posted: Wed May 16, 2018 5:50 am
by Mark9013100
I've been attempting to add a new chair variant with armrests, the first method I attempted was making it a child of the comfy chairs, but that just resulted in the armrest sprite being the comfy chair instead of the one specifically made for it.


This is my current method for implementing it, which is just straight copying the comfy chair code. Is there a more efficient method for this?
Spoiler:
/obj/structure/chair/shuttle
name = "shuttle chair"
icon_state = "shuttlechair"
buildstackamount = 2
var/mutable_appearance/armrest
item_chair = null

/obj/structure/chair/shuttle/Initialize()
armrest = mutable_appearance('icons/obj/chairs.dmi', "shuttlechair_armrest")
armrest.layer = ABOVE_MOB_LAYER
return ..()

/obj/structure/chair/shuttle/Destroy()
QDEL_NULL(armrest)
return ..()

/obj/structure/chair/shuttle/post_buckle_mob(mob/living/M)
. = ..()
update_armrest()

/obj/structure/chair/shuttle/proc/update_armrest()
if(has_buckled_mobs())
add_overlay(armrest)
else
cut_overlay(armrest)

/obj/structure/chair/shuttle/post_unbuckle_mob()
. = ..()
update_armrest()

Re: Shuttle Chair armrests

Posted: Wed May 16, 2018 6:07 am
by yorii
I'm not very well-versed with objects, but I think you can do exactly the thing you did here but replace

Code: Select all

/obj/structure/chair/shuttle
with

Code: Select all

/obj/structure/chair/comfy/shuttle
and then scrap any code that is literally identical like the post_unbuckle_mob() function.

For example as so:

Code: Select all

/obj/structure/chair/comfy/shuttle
	name = "comfy shuttle chair"
	desc = "It looks comfy."
	icon_state = "shuttlechair"

/obj/structure/chair/comfy/shuttle/Initialize()
	armrest = mutable_appearance('icons/obj/chairs.dmi', "shuttlechair_armrest")
	armrest.layer = ABOVE_MOB_LAYER
	return ..()
Someone who isn't a pretend coder can feel free to correct me if I'm wrong.

Re: Shuttle Chair armrests

Posted: Wed May 16, 2018 6:26 am
by Mark9013100
I'll try that tomorrow when I get the chance, thanks.

Re: Shuttle Chair armrests

Posted: Wed May 16, 2018 9:52 am
by DemonFiren
I read that as "shuttle chair armaments" and I'm disappointed the Captain doesn't get dual gatling lasers on his chair.

Re: Shuttle Chair armrests

Posted: Wed May 16, 2018 12:20 pm
by AnturK
You'll need to wrap the armrest creation in a function then override it or make it use a variable. Otherwise calling the parent proc with ..() will replace the image you just created.

Re: Shuttle Chair armrests

Posted: Wed May 16, 2018 4:32 pm
by Mark9013100
I'm not very code literate, is there an example of this anywhere in the code?

Re: Shuttle Chair armrests

Posted: Fri May 18, 2018 10:48 am
by yorii
AnturK wrote:You'll need to wrap the armrest creation in a function then override it or make it use a variable. Otherwise calling the parent proc with ..() will replace the image you just created.
so the armrest var that gets used in the parent proc uses the parents var instead of the childs defined armrest var?

Re: Shuttle Chair armrests

Posted: Thu May 24, 2018 1:44 pm
by AnturK

Code: Select all

/obj/structure/chair/shuttle
   var/armrest_state = "default_armrest"

/obj/structure/chair/shuttle/Initalize()
   ...
   armrest = mutable_appearance('chairs.dmi',armrest_state)
   ...

/obj/structure/chair/shuttle/whatever
    armrest_state = "whatever_armrest"
Something like this is the easiest solution.

Re: Shuttle Chair armrests

Posted: Fri May 25, 2018 11:33 pm
by Mark9013100
Alright, I'll try that when I get the time tomorrow, thank you.

Re: Shuttle Chair armrests

Posted: Sat May 26, 2018 10:22 am
by Mark9013100
AnturK wrote:

Code: Select all

/obj/structure/chair/shuttle
   var/armrest_state = "default_armrest"

/obj/structure/chair/shuttle/Initalize()
   ...
   armrest = mutable_appearance('chairs.dmi',armrest_state)
   ...

/obj/structure/chair/shuttle/whatever
    armrest_state = "whatever_armrest"
Something like this is the easiest solution.

Tried it, but this line is giving me errors:

Code: Select all

	armrest = mutable_appearance('icons/obj/chairs.dmi',armrest_state)
code\game\objects\structures\bed_chairs\chair.dm:200:error armrest: undefined var

Here's the full thing I have:

Code: Select all

/obj/structure/chair/shuttle
	name = "shuttle chair"
	icon_state = "shuttlechair"
	var/armrest_state = "shuttlechair_armrest"
	item_chair = null

/obj/structure/chair/shuttle/Initialize()
	...
	armrest = mutable_appearance('icons/obj/chairs.dmi',armrest_state)
	...

/obj/structure/chair/shuttle/armrest
	armrest_state = "shuttlechair_armrest"