The Grapple Hook

C++ Got ya down? Half-Life 2 Coding Related.
Post Reply
stephends
Pixel
Posts: 1
Joined: Thu May 05, 2011 11:36 pm

The Grapple Hook

Post by stephends »

Hey Guys

I am currently testing ideas for a modification i am soon to create and i came acroos your grapple hook code. I am building for the single player version of hl2 (2007 build) and i am wondering what I would have to change in order for this to work in my mod. Credits will be added upon completion.
http://developer.valvesoftware.com/wiki/Grapple_Hook

"The weapon is designed for multiplayer, but should work fine in a single player mod once you swap out references to hl2mp. It uses the crossbow model."

Its the single player reference I dont know or to change.

Thanks
User avatar
Neico
Lead Coder
Lead Coder
Posts: 1799
Joined: Tue Aug 15, 2006 3:39 pm
Location: Germany
Contact:

Re: The Grapple Hook

Post by Neico »

Do I really have to explain that?
Seriously, if you can't figure that simply thing out then you might stay away from things like coding? (Hint: "HL2MP" -> "HL2" or was it "HL2SP", no idea, but I'm not really here to solve that for you...)
Image
User avatar
TESLA-X4
Former Developer
Former Developer
Posts: 570
Joined: Wed Jul 01, 2009 3:26 pm
Location: $Recycle.Bin

Re: The Grapple Hook

Post by TESLA-X4 »

I'd change the code for you, but doing so on a screen this size (it's a smartphone) will blind me, so I'll only be able do that when I get home.

Off the top of my head, you'll need to change references to HL2MP to HL2 (sometimes even HL), or in some cases remove it entirely. Common places to look at are header includes and class inheritances (whoa, is that even a word?).

Edit:
Also, since it's a singleplayer mod, you could attach the rope to the viewmodel instead of the weapon since it looks significantly better that way (can't do that in multiplayer because it looks really ugly for other players).

Edit 2:
Well, I've done edits to make it compile without errors in Episodic (Single Player).
Here they are: weapon_grapple.cpp and weapon_grapple.h. Place both of these files into the server/hl2/ folder and add them to the Server project in Visual Studio. You will most likely need to create a client-side version for this entity, see c_weapon_crossbow.cpp in the Client project for a quick example.
Keep in mind that the edits are rather very crude since I didn't have much spare time to work on it (also, I didn't actually test them out in-game, only checked that they compiled). Also, the grapple hook code on the Valve Wiki is actually derived from the Episode 1 (maybe even earlier!) version of weapon_crossbow, so I don't really recommend using these files as a long term solution until you've verified that you can ignore whatever has been changed.

Sorry that I couldn't do more, I'm really tight on time.
Apparently, Valve can't make games beyond the number 2.
I think the only time we'll get a Source SDK code update is when it starts having purchasable hats integrated, i.e. hatconomy.

Please do not make assumptions you are not knowledgeable enough to make - that just backfires on yourself.
Tick me off, and I'll be sure to give you the golden treatment. Haven't you heard? Silence is golden.
Bovine
Pixel
Posts: 3
Joined: Mon May 16, 2011 2:07 pm

Re: The Grapple Hook

Post by Bovine »

This is only partially related to the topic, but the grapple works really weirdly whenever I try to use it. Does it still use the code linked above?
User avatar
TESLA-X4
Former Developer
Former Developer
Posts: 570
Joined: Wed Jul 01, 2009 3:26 pm
Location: $Recycle.Bin

Re: The Grapple Hook

Post by TESLA-X4 »

I think so - the last time I tested a binary compiled with the provided grappling hook code, it behaved in the exact same way as it did in OC. That weirdness in movement is caused by use of IPhysicsSpring, but I don't know of any others that would be more suitable for this purpose... Yet.
Apparently, Valve can't make games beyond the number 2.
I think the only time we'll get a Source SDK code update is when it starts having purchasable hats integrated, i.e. hatconomy.

Please do not make assumptions you are not knowledgeable enough to make - that just backfires on yourself.
Tick me off, and I'll be sure to give you the golden treatment. Haven't you heard? Silence is golden.
Bovine
Pixel
Posts: 3
Joined: Mon May 16, 2011 2:07 pm

Re: The Grapple Hook

Post by Bovine »

You may want to try setting the player origin every frame as well as the spring length. I think the current version is that of a spring that doesn't let the hook side rotate.

If you want the spring movement stuff outside of the physics system I have some code that should properly do the spring stuff.
Post Reply