Quick Question (pertains to chainsaws)

How, what and why to code in BYOND.
Post Reply
User avatar
PKPenguin321
Site Admin
Joined: Tue Jul 01, 2014 7:02 pm
Byond Username: PKPenguin321
Github Username: PKPenguin321
Location: U S A, U S A, U S A

Quick Question (pertains to chainsaws)

Post by PKPenguin321 » #129873

Hey, I know these kinds of questions are usually asked in the IRC, but I've never bothered with using IRC and honestly can't be assed to, so I'm just gonna ask it here. Just a little bit ago I decided to look at the game's code to see if I could make a surgery that attaches an chainsaw to your arm, as has been suggested numerous times.

Considering that I've never coded before at all, I'd say I've made good progress: I've made a new object, a mounted chainsaw, that has the ABSTRACT and NODROP flags and is always on/doesn't need two hands to use, but is otherwise identical to the standard chainsaw. Basically I tried recreating the chainsaw using the flags from the armblade so that from an in-game perspective, it's "attached" to your arm.

Then I made a surgery for it, Chainsaw Augmentation. It has the same steps as an organ manipulation, but is performed on either the l_arm or r_arm and the last step is inserting a chainsaw instead of a general organ manipulation. The last step (which is probably the only step that requires any effort) was spawning a mounted chainsaw into the hand of the target mob. I really had no clue how to do this part, so I tried copying some code from changelings that gives them an armblade, and, as expected, failed miserably. In fact, I completely forgot to call a delete on the chainsaw that was inserted, so basically nothing happens.

My ingame test had the surgery work perfectly, except that once the surgery was completed, nothing happened. The mounted chainsaw did not spawn at all. Manually spawning the mounted chainsaw shows that it works pretty much perfectly (except that I forgot to add the unique hitsound).

Here's the teeny tiny 37 line .dm I wrote. Fair warning, it's probably shitcode and to anybody with any kind of coding experience, the issue and solution is probably really really obvious.

tl;dr: How do I make it so that once the surgery is completed, the chainsaw you inserted is deleted, and the new mounted chainsaw is spawned into the target's hand?

Thanks!
i play Lauser McMauligan. clown name is Cold-Ass Honkey
i have three other top secret characters as well.
tell the best admin how good he is
Spoiler:
Image
TheNightingale
Joined: Fri Mar 20, 2015 5:07 pm
Byond Username: TheNightingale

Re: Quick Question (pertains to chainsaws)

Post by TheNightingale » #129880

(I know next-to-nothing about coding, but...)

var/obj/item/weapon/mounted_chainsaw = new(target,1)
target.put_in_hands(mounted_chainsaw)
return 1

Why have it as a var, when you can just target.put_in_hands an obj/item/mounted_chainsaw and be done with it? Also, you need to delete the original chainsaw - try looking at augment code, which deletes the cyborg part and replaces the user's limb with a metal version. (I think?)

Told you I know next-to-nothing about coding!
Last edited by TheNightingale on Tue Oct 27, 2015 1:55 pm, edited 1 time in total.
User avatar
PKPenguin321
Site Admin
Joined: Tue Jul 01, 2014 7:02 pm
Byond Username: PKPenguin321
Github Username: PKPenguin321
Location: U S A, U S A, U S A

Re: Quick Question (pertains to chainsaws)

Post by PKPenguin321 » #129883

The var part is left in there, because like I said, I shamelessly copied code from the changeling false armblade sting. I'll test what happens without that line, but I suspect it's needed for actually spawning the mounted chainsaw.
That's some good thinking for the deletion part, I'll check that out.

Edit: I got the chainsaw to delete upon being inserted, but still no dice on placing the mounted chainsaw in the target's hand. Runtime logs, from what I can tell, are saying that I'm misusing the "put in hand check" proc. (proc name: put in hand check (/mob/proc/put_in_hand_check)) I could be absolutely wrong since I have pretty much no idea what these logs are saying, but that's what I'm taking from it. Here's the updated .dm: http://pastebin.com/p4qCcmhy

Edit 2: Just noticed I used the wrong item path for the part where it places the item in the target's hand. Then I found this in the code for the relevant proc: "// Currently invalid for two-handed items - call obj/item/mob_can_equip() instead."
Gonna try it again with the correct item path, since the mounted chainsaw isn't two-handed.

Edit 3: Still nothing. I really have no idea what to use for this part.
i play Lauser McMauligan. clown name is Cold-Ass Honkey
i have three other top secret characters as well.
tell the best admin how good he is
Spoiler:
Image
User avatar
Remie Richards
Joined: Thu Apr 17, 2014 7:11 pm
Byond Username: CrimsonVision
Location: England, UK, Earth, Sol, Milky Way, Local Group, Virgo Supercluster, Known Universe
Contact:

Re: Quick Question (pertains to chainsaws)

Post by Remie Richards » #129909

You're not spawning a mounted_chainsaw, you're spawning a /obj/item/weapon as a variable CALLED mounted_chainsaw.
add /dicks onto the end of your variable so it's var/obj/item/weapon/mounted_chainsaw/dicks = new(src,1)
then make it target.put_in-hands(dicks)

then go back over it and replace dicks with something like MC, for mounted_chainsaw.

hinty hint hint:

Code: Select all

/datum/surgery_step/chainsaw/success(mob/user, mob/living/carbon/target, target_zone, obj/item/tool, datum/surgery/surgery)
    user.visible_message("[user] finshes installing the chainsaw!", "<span class='notice'>You install the chainsaw.</span>")
    user.unEquip(tool)
    qdel(tool)
    var/obj/item/weapon/mounted_chainsaw/dicks = new(target)
    target.put_in_hands(dicks)
    return 1
tl;dr
What Nightingale told you about the path was baaaad.
actually set the right path on your vars
user.drop_item() isn't as robust as user.unEquip(the_item)
:P
私は完璧
User avatar
oranges
Code Maintainer
Joined: Tue Apr 15, 2014 9:16 pm
Byond Username: Optimumtact
Github Username: optimumtact
Location: #CHATSHITGETBANGED

Re: Quick Question (pertains to chainsaws)

Post by oranges » #129917

man get in IRC it's a real blast!
User avatar
PKPenguin321
Site Admin
Joined: Tue Jul 01, 2014 7:02 pm
Byond Username: PKPenguin321
Github Username: PKPenguin321
Location: U S A, U S A, U S A

Re: Quick Question (pertains to chainsaws)

Post by PKPenguin321 » #129924

Ayyyy, remie's fix worked (after I PMed miauw asking him for help directly. nevermind miauw ._.)
Only problem now is that if both of your hands are full and you try to do the chainsaw augmentation surgery again, it spawns the mounted chainsaw on the floor... I need to check if the targets hands are full when attempting the "installing the chainsaw" step of the surgery.
I'll check back on it tomorrow, thanks for the help!

And oranges, I don't even know how to use IRC properly, to be honest. I tried connecting to #coderbus earlier with a web-based IRC client but I don't think it worked. :?
i play Lauser McMauligan. clown name is Cold-Ass Honkey
i have three other top secret characters as well.
tell the best admin how good he is
Spoiler:
Image
newfren
Joined: Tue May 12, 2015 12:57 pm
Byond Username: Newfren

Re: Quick Question (pertains to chainsaws)

Post by newfren » #129931

https://client01.chat.mibbit.com/?url=i ... 2Fcoderbus

Follow that link, type "newfrenismyhero" where it asks for a name then hit go and wait for a little bit while it loads shit for you.
Post Reply

Who is online

Users browsing this forum: No registered users