Shuttle Chair armrests

How, what and why to code in BYOND.
Post Reply
User avatar
Mark9013100
Joined: Sat Dec 27, 2014 6:06 pm
Byond Username: Mark9013100

Shuttle Chair armrests

Post by Mark9013100 » #410746

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()
Image
User avatar
yorii
Github User
Joined: Fri Jan 05, 2018 1:13 am
Byond Username: Yorpan
Github Username: yorii

Re: Shuttle Chair armrests

Post by yorii » #410748

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.
User avatar
Mark9013100
Joined: Sat Dec 27, 2014 6:06 pm
Byond Username: Mark9013100

Re: Shuttle Chair armrests

Post by Mark9013100 » #410754

I'll try that tomorrow when I get the chance, thanks.
Image
User avatar
DemonFiren
Joined: Sat Dec 13, 2014 9:15 pm
Byond Username: DemonFiren

Re: Shuttle Chair armrests

Post by DemonFiren » #410764

I read that as "shuttle chair armaments" and I'm disappointed the Captain doesn't get dual gatling lasers on his chair.
Image
Image
Image
ImageImageImageImageImage

non-lizard things:
Spoiler:
Image
AnturK
Code Maintainer
Joined: Fri Apr 18, 2014 4:42 pm
Byond Username: Anturke

Re: Shuttle Chair armrests

Post by AnturK » #410777

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.
User avatar
Mark9013100
Joined: Sat Dec 27, 2014 6:06 pm
Byond Username: Mark9013100

Re: Shuttle Chair armrests

Post by Mark9013100 » #410825

I'm not very code literate, is there an example of this anywhere in the code?
Image
User avatar
yorii
Github User
Joined: Fri Jan 05, 2018 1:13 am
Byond Username: Yorpan
Github Username: yorii

Re: Shuttle Chair armrests

Post by yorii » #411350

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?
AnturK
Code Maintainer
Joined: Fri Apr 18, 2014 4:42 pm
Byond Username: Anturke

Re: Shuttle Chair armrests

Post by AnturK » #412666

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.
User avatar
Mark9013100
Joined: Sat Dec 27, 2014 6:06 pm
Byond Username: Mark9013100

Re: Shuttle Chair armrests

Post by Mark9013100 » #413075

Alright, I'll try that when I get the time tomorrow, thank you.
Image
User avatar
Mark9013100
Joined: Sat Dec 27, 2014 6:06 pm
Byond Username: Mark9013100

Re: Shuttle Chair armrests

Post by Mark9013100 » #413149

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"
Image
Post Reply

Who is online

Users browsing this forum: No registered users