Valve Source Code 2013 Tutorial (Episode 2): Fixing the Physgun
Ойындар
Hello everyone and welcome to a new (probably short) series of videos I do involving the source code from Valve for Half-Life 2, and some guides on how to do stuff with this code. In this episode, I go over how to implement the Half-Life 2 Beta weapon called the Physgun, and inform you of the problems you may encounter when using this cut weapon. I have to thank KZread user Tingtom for uploading a video along with the source code for a GMOD style Physgun to be used in a Half-Life 2 mod, which was the basis for this video. Please let me know what you think and see you for whatever I decide to do next, thanks for watching!
Tingtom video inspiration: • HL2 Modding - Physgun
► Follow me on Twitch here: / themaster974streams
► Follow me on Twitter here: / thethemaster974
► Subscribe to my stream archive channel here: / @themaster974streams
Пікірлер: 121
I'm using your tutorials for my own hl2 beta mod! keep up the good work!
@TheMaster974
6 ай бұрын
Thank you for the comment, good luck with the mod!
I'm getting an error saying that there is no weapon data file for the physgun and it shows up in my inventory but I cannot select it (I put the script in the wrong script folder and now its fixed)
Bummer I was hoping this would help me do the opposite of this.. In getting the in getting the phys cannon into Gmod... From the sound of it the guys that did the super gravity gun had to go through a similar process.. I'm hoping this one's easier, as their process was complex on account of getting the rag dolls to work.. whereas I'm trying to do the opposite LOL.. pretty much the only functionality that I haven't been able to mess with on account that you can't actually mess with things in Gmod that are defaults apparently.. LOL... So excited that what I can do with it if I can get it working.. especially with that guy who rigged the c_hands into a animated grab hold replacement.. already worth its weight just for that even if it doesn't animate right with any of the full body awareness.. or any other procedural animation.. But if I can get it there.. well the first thing that goes is that stupid glow Sprite.. like I usually turn off any HDR adjustments because well I have eyes, and they adjust for me usually.. I really don't need the equivalent of eye doctor sunglasses as soon as I look at a slightly bright object LOL I'm not sure where that becoming trend but it it.. it needs to die forever.. it's lived already too long, and you think in the world of HDR like actual HDR it would it would have gone away.. or not have been a problem in the first place cuz you know your minimum levels would have been balanced to basic color correction values that you went through the entire map within the first place LOL.. but that stupid glow Sprite, possibly one of the worst offenders LOL especially if you're trying to see in the dark.. suppose that's just wonderfully ironic LOL... Gahh you think with everything that works on eye angles and I traces around this game.. you think they would have at at least bound like the tone mapper to the eye angles.. or maybe it is and it's just a giant box LOL.. either way you think that they would have noticed that their feature weapon that's going to be used throughout every single aspect of any of the HDR maps they were working on was causing that thing to give Gordon glaucoma in a dark tunnel.. he was already having trouble in the regular bright sand LOL... Then the cool stuff gets done.. Gordon may have used to be ambidextrous.. before they patch that command out, but now he's a right-handed man.. going to show Clive Barker what's up.
hey, quick question, is there an way to prevent the physgun from grabbing sertain entity's i have noticed that it seems to crash whenever trying to hold the manhack, just askin if there is a way and if ya could tell me, just askin
@TheMaster974
3 ай бұрын
There is, however it won't really help you with the situation you are providing. From my testing, the game crashes because of the SoundUpdate function, with a variable called pPhys being null when a manhack is grabbed. My solution would be to do: float fade = ; then remove the float from the existing fade definition and contain that line inside of an if(pPhys) statement, then you should no longer experience crashes. Let me know if this is helpful!
@grubasekpl9254
3 ай бұрын
@@TheMaster974 huh, implementing your fix seemed to make the manhack die, well i guess its better than crashing, thanks
hello, I want to ask if you know how I can do the freezing and rotation like you have in garrys mod with physgun, it would be useful for me as a debug weapon in my mod
@TheMaster974
4 ай бұрын
I think I would be able to demonstrate how to freeze objects like in Garry's Mod, however I don't know how to rotate objects.
How do I add a new NPC zombie?
Im getting the error - "DataTable warning: No matching RecvTable for SendTable ", am i missing something?
@TheMaster974
2 жыл бұрын
Sounds like you're missing the Client code, which is in c_weapon_gravitygun.cpp. It could be possible that you put that file in the wrong project, like the HL2 version of the Client code instead of the Episodic version or vice versa. Because of this, the code will compile without any errors but will not be playable, giving you that error message. Hope this helps!
hey, can you say wat to do if it works but it's invisible in weapons tab(idk how to named it)
@TheMaster974
4 ай бұрын
I would check to see if you have a weapon script for the weapon in the mod's scripts folder, and if you do, make sure the bucket and bucket position values do not match a weapon that already exists. You should get warning messages in the developer console about this stuff if one of these suggestions that I've outlined is the source of your problem.
@user-gl6jd3pe8c
4 ай бұрын
thx@@TheMaster974
could you possibly compile this to an Garry's Mod workshop addon or SWEP? would be really amazing! I know Garry's Mod has it's own physgun but this is different enough to be worth it. I suck at coding myself, so I would have literally no idea what to do with this or if this could ever possibly work in modern Source version. I didn't see ANYONE attempt to bring HL2 beta physgun into garry's mod which really, really sucks.
@TheMaster974
2 жыл бұрын
I'm in the same boat (about not knowing how to code this) unfortunately, the Physgun code is complex and would need to be rewritten to work using lua instead of C++, which isn't as easy as it sounds. It may be possible to do, I'm just not the right person to go to in order for this to be achieved. Apologies! Maybe, one day, someone with the right knowledge will come around and figure this out.
@LugiDergX
2 жыл бұрын
@@TheMaster974 No issue really, but thanks for reminding me that this needs to be lua. If you could possibly provide fixed C++ code and files on Discord or somewhere, however, I could try to look for someone to pay for rewriting and uploading the addon into Gmod.
@TheMaster974
2 жыл бұрын
Apologies for the late response, I've uploaded the client and server Physgun code to Dropbox so you can download it (hopefully), best wishes in regards to finding someone who can adapt the code for a Garry's Mod addon. Dropbox link: www.dropbox.com/sh/k6e72nc1d3inxvm/AAB08VaUHQZJpHAjxrkFAn4fa?dl=0
not working? Error 1 error C1083: Cannot open include file: 'hud.h': No such file or directory f:\source sdk\source-sdk-2013-MW2019-master\sp\src\game\client\hl2\c_weapon_gravitygun.cpp 9 1 Server (Episodic)
@TheMaster974
2 ай бұрын
That's strange, it sounds like the hud.h file isn't being located properly. The only thing I can recommend is removing the space from the "source sdk" folder and see if that resolves the issue, or maybe try moving the code to a different folder entirely.
Could u please do a video fixing the unused moltolv weapon
@TheMaster974
Жыл бұрын
Sure, I can look into it.
@WadDeIz
Жыл бұрын
@@TheMaster974 thanks man
Does Anyone Have A Mod For Source SDK Base 2013? It Did Not Work For Me :(
@TheMaster974
Жыл бұрын
You can use the Mapbase mod: www.moddb.com/mods/mapbase
Hey I am getting a assertion error (i >= 0 && i < 32), any help would be very much appreciated. (I fixed it, thank you of the tutorial they are very helpful.)
@TheMaster974
9 күн бұрын
Thanks for the comment!
Hey, i love the tutorial! But may i ask for the viewmodel file? I cant find any. Im making a seperate mod. Also how do i remove the welding mechanism? I dont understand the coding at all.
@TheMaster974
3 жыл бұрын
Thanks for the comment! To answer your first question, the viewmodel is from a mod called Missing Information, you can just copy/paste the models + materials/models files (of course, ask before you release your mod if it's ok to use them!) I would argue using the default gravity gun model is ok, if you don't want to/know how to do what I just suggested. In regards to the welding functionality, I'll interpret it literally which means you would want to comment out the section in physgun.cpp that says "bool MakeConstraint..." (you can type /* in the line above and */ the line below the closing } ). This will throw up an error in WeaponIdle, just comment out (by using what I just stated) the stuff from CBaseEntity *pObject to the last } after the m_activepellets line. You can then build the solution and see if it does what you want it to. Hopefully this helps!
ok so i wrote the code and compiled the dll's to my mod. now, how do i use the gun? how do i spawn it to use it?
@TheMaster974
8 ай бұрын
You should be able to do: give weapon_physgun and you should get the Physgun in-game.
Is there a way to weld object when right click like in gmod?
@TheMaster974
Жыл бұрын
If you mean to freeze an object in place, then yes there is, the user I thanked in the video (Tingtom) implemented something like that. To add this kind of functionality, in EffectUpdate() and in the if(m_useDown) section, inside if(pOwner->m_afButtonPressed & IN_USE) add these lines: IPhysicsObject *pPhys = pObject->VPhysicsGetObject(); pPhys->EnableMotion(true); DetachObject(); AttachObject(pObject, start, tr.endpos, distance); then in the else statement, inside of the if statement here, add the lines: IPhysicsObject *pPhys = pObject->VPhysicsGetObject(); pPhys->EnableMotion(false); By doing this, when you hold an object, pressing the use key will freeze it in the air and pressing the use key again will allow it to move. Hopefully this is helpful (and credit to Tingtom for this addition)!
@goldtherealmc905
Жыл бұрын
@@TheMaster974 thanks you!
@RModOfficial
7 ай бұрын
@@TheMaster974 how i change the bind key into right click?
Is there a way to make it rotate objects when holding e?
@TheMaster974
Жыл бұрын
I'm sure there is, but I wouldn't know how to do it. Setting up a condition that checks if the player is pressing the E key (+use) is easy, it's rotating the object that's the hard part. You would have to somehow come up with a way to map mouse movement (or something else) to the rotation of the attached object, which I cannot tell you how to do. Apologies!
when i got a healthpack/battery/ammou box when i get them the physgun can't find them anymore and so the game will crash any fix for this?
@TheMaster974
Жыл бұрын
From my experimentation, it seems as if the game crashes when an item is on the floor and you pick it up while it is being held by the Physgun, but this crash is uncommon. The offending line (at least for me) seems to be the definition of two parameters called *pPhys and fade inside of the Physgun's SoundUpdate function. Usually, you can bring items towards you and collect them without any problems (default is scroll wheel down). If what I just outlined is the case for you, my suggestion would be to contain the fade parameter definition inside of an if statement to test if pPhys is not null (and set up a stock fade parameter above the if statement), otherwise set the value of fade to 0. Otherwise, I don't know what to suggest!
@amirlator
Жыл бұрын
@@TheMaster974 now I check if pPhys isn't null and then fade is set to 0 but still when entity is grabbed by physgun and when it destroy the game is gone. Don't know how to fix it and it doesn't matter that much. I had. Request that you make a tutorial about how add costume shaders to source sdk , thanks for helps!
@TheMaster974
Жыл бұрын
Strange, your game shouldn't be crashing when collecting items with the Physgun, so I have no idea why that's happening. You can check out my coding tutorial playlist for a couple of shader-related videos and see if they are of any use to you: kzread.info/head/PL8tDEPB6h7Lk0YtRtt4k1h_Thgj1ZA2dX
this work too in Source SDK Base 2013 Multiplayer?
@TheMaster974
Жыл бұрын
It should do.
object of abstract class type "C_BeamQuadratic" is not allowed
@TheMaster974
2 ай бұрын
You need to follow what I do from 3:09.
"ERROR: Weapon (weapon_physgun) using undefined secondary ammo type (Gravity)" The weld alt-fire ammo is missing help
@TheMaster974
Жыл бұрын
The Gravity ammo type should be defined already in hl2_gamerules.cpp, at least for a Singleplayer mod. If you're doing this for a Multiplayer mod, you would have to go to hl2mp_gamerules.cpp and add the definition for the Gravity ammo type here (it should be around line 925 or so). By default, the definition is like this: def.AddAmmoType("Gravity", DMG_CLUB, TRACER_NONE, 0, 0, 8, 0, 0 ); Alternatively, you can go into the weapon_physgun.txt file and change the ammo type to something else. Hopefully this helps!
@PracticeMedicine
Жыл бұрын
@@TheMaster974 My mod was MP, i'll try add that to the hl2mp_gamerules.cpp. Gee, thanks! Edit: It works for now! Thanks! You're a W!
Error error LNK2005: "void __cdecl CC_CollisionTest(class CCommand const &)" (?CC_CollisionTest@@YAXABVCCommand@@@Z) already defined in physgun.obj C:\sourcesandbox\sp\src\game\server\util.obj Server (HL2)
@TheMaster974
4 ай бұрын
I show the fix at 5:39 in the video.
@pepsifan64
4 ай бұрын
@TheMaster974 Thanks, I didn't notice
for me it just dosent work (dosen't recognize the thing) using sp btw
@TheMaster974
Жыл бұрын
It's not recognising the Physgun? Have you added the Physgun code to the right project (i.e. you accidentally added it to HL2 instead of Episodic), included a weapon script or is the mod even using the correct .dll files? Those are the only things I can think of that would give this sort of error.
i keep getting errors anytime i put the code in source 2013 multiplayer:Attempted to create unknown entity type weapon_physgun! NULL Ent
@TheMaster974
4 ай бұрын
This is probably happening because the code is not being added correctly for some reason, if the Physgun code has been added to the Server and Client projects (I mention the file names in the video) and both projects compile without any issues after making the changes I outline, plus if you are launching into the correct mod, you should not be experiencing any issues. This is all I can think of in regards to the solution for this problem.
I implimented the code and fixed the client side just as in the tutorial, but when i run the game, it states that such entity does not exsist. Do you have any idea about whats going on?
@TheMaster974
Жыл бұрын
Are you spelling weapon_physgun correctly? Or launching into the correct mod? It's all I can think of, if you did what I suggested in the video, you shouldn't have any problems.
@action-soft
Жыл бұрын
I did everything exactly as in the video, only thing I can think of is moving the script from hl2_dll to Portal\Weapons because I’m using the portal 2013 src for the mod (it’s a portal mod)
@TheMaster974
Жыл бұрын
I don't think that would change anything, as I've managed to do something similar to what you want to do and not had any issues. If the console is saying weapon_physgun does not exist, there must be an issue with your code (but I don't know what it could be?). Otherwise, if the console does not show any errors, but giving the Physgun doesn't immediately cause something to happen, it could be that you need to give the player the suit. Either way, I uploaded the Physgun files here as a reference: www.dropbox.com/sh/k6e72nc1d3inxvm/AAB08VaUHQZJpHAjxrkFAn4fa?dl=0
@action-soft
Жыл бұрын
Thanks, I’ll compare the files and see if there are differences. Then I’ll try the file you uploaded to see if it works. I’ll let you know if it works. Also another question, a few tutorials for adding new weapons have said that the weapon name should be declared in c_weapon__stubs_hl2.cpp (in my case its c_weapon_stubs_Portal.cpp) but for some reason, both the beta physgun, Portal gun, and gravity gun are not declared in c_weapon_stubs_Portal.cpp or c_weapon__stubs_hl2.cpp. Could that maybe have something to do with it?
@action-soft
Жыл бұрын
It didn't work.
is this video outdated now? i go into SERVER(HL2) and i cant find the hl2 folder the closest thing is HL2 DLL inside SERVER(HL2)
@TheMaster974
Жыл бұрын
HL2 DLL is exactly the same as the hl2 folder.
@twilightbob
Жыл бұрын
@@TheMaster974 alright
@twilightbob
Жыл бұрын
@@TheMaster974 do i need to do any else to add this to hl2mp
@TheMaster974
Жыл бұрын
I think everything I outline in the video applies to Source 2013 Multiplayer, with the only difference being that you want to add the Gravity ammo type to hl2mp_gamerules.cpp instead.
@twilightbob
Жыл бұрын
@@TheMaster974 on what line and give me the code
TYSM i will credit you in my mod
@TheMaster974
22 күн бұрын
Thank you for the comment!
@guestsneezeplayz
5 күн бұрын
@@TheMaster974 should i use e3 or HL2 Sandbox physgun to get my game to steam?
@guestsneezeplayz
5 күн бұрын
could you leave the link for the source code?
@TheMaster974
4 күн бұрын
I'm not sure about which Physgun model you should use, but whatever you decide, be sure to credit the source! I've left the Physgun code here: www.dropbox.com/sh/k6e72nc1d3inxvm/AAB08VaUHQZJpHAjxrkFAn4fa?dl=0
@guestsneezeplayz
2 күн бұрын
@@TheMaster974 tysm
How did you get the physgun model?
@TheMaster974
9 ай бұрын
I got it from the Missing Information mod, which can be found here: www.moddb.com/mods/missing-information/downloads/missing-information-16-full
@RModOfficial
9 ай бұрын
@@TheMaster974 TYSM, You deserved 20K SUbs :D
@RModOfficial
9 ай бұрын
@@TheMaster974 Oh yeah Can you please make video how to fix hl2 Tau Cannon too?, i'll subs and like
@TheMaster974
9 ай бұрын
The problem with doing a video about the Tau Cannon is that I would have to get the weapon code from the leaked Half-Life 2 Beta source code, and I feel conflicted about whether I should recommend viewers to use leaked code, or if I should repost any leaked code. It's something for me to contemplate doing, maybe eventually I'll do a poll and see what the viewers of the channel have to say about it (using/distributing leaked code, not a video about the Tau Cannon, to avoid any confusion!).
@MazdoTheWolf
8 ай бұрын
@@TheMaster974 Good news Gareth, the Tau Cannon code is available in the official 2004 sdk of half-life 2 (so no need to use leaked code)
Will we ever get an updated version that fixes the weld crash?
@TheMaster974
Жыл бұрын
Probably, but I won't be the one doing it since I have no idea how!
@Stongg
Жыл бұрын
@@TheMaster974 I see, there are already some mods out there that fixes it, but sadly don't have a tutorial or the code for it though
@XENON2028
Жыл бұрын
try compile in Release mode and assertion errors should go away
@Stongg
Жыл бұрын
@@XENON2028 I did, and it doesn't fix that problem, it's more of a bug in the code
@XENON2028
Жыл бұрын
@@Stongg hmm, doesn't happen for me so idk
i got an error model what model name for viewmodel should i use?
@TheMaster974
Жыл бұрын
The closest viewmodel for the Physgun is the Gravity Gun from retail Half-Life 2, which is models/weapons/v_physcannon.mdl but if you want the Beta Physgun viewmodel, you have to get it elsewhere i.e. the Missing Information mod.
@notevencoybowvoicem5239
Жыл бұрын
@@TheMaster974 does that model exists from source sdk 2013 singleplayer If yes why does it have a error?
@TheMaster974
Жыл бұрын
The Beta Physgun viewmodel does not exist in the game files, hence why it's showing up as an error. To change this, edit the viewmodel part of weapon_physgun.txt in the mod's scripts directory.
@notevencoybowvoicem5239
Жыл бұрын
@@TheMaster974 ok thank you
@notevencoybowvoicem5239
Жыл бұрын
@@TheMaster974 lets see if it work
Hey man I can't add this to half-life 2 singleplayer file
@TheMaster974
2 жыл бұрын
What's the issue exactly? Server/Client code issues, needing a weapon script or a viewmodel/worldmodel? The Physgun code files should already be provided when obtaining the 2013 source code. If you could let me know what the problem is exactly, I can try and assist further.
@redtoasttoy
2 жыл бұрын
@@TheMaster974 Also 2013 code will not work for me
@TheMaster974
2 жыл бұрын
Try following the steps shown in this video: kzread.info/dash/bejne/h2uTr89phr3gaMo.html I know the code doesn't compile properly if you don't do what's shown in the video, though I don't know if that will help here. Other than that, I don't know what to suggest.
@redtoasttoy
2 жыл бұрын
@@TheMaster974 Ok thanks man 👊
It fails to compile
@TheMaster974
Жыл бұрын
What does the error message say?
@painfulburn
Жыл бұрын
@@TheMaster974 Oops sorry for not respoding i didnt get a notification im gonna send the error
@painfulburn
Жыл бұрын
i didnt get a error this time, thats weird, anyways, thanks
help!!!! i cant find games solution
@TheMaster974
Жыл бұрын
Did you run the creategameprojects.bat file?
@frxn_official
Жыл бұрын
@@TheMaster974 yes, do i need to download vs 2013?
@TheMaster974
Жыл бұрын
Preferably yes, though you can follow this guide to be able to create the games solution: developer.valvesoftware.com/wiki/Source_SDK_2013#Unable_to_find_RegKey_for_.vcproj_files_in_solutions_.28Windows.29 But you may run into an issue where the solution won't compile, because you don't have the necessary Platform Toolset installed, which I don't know how to easily fix. However, there's the Community Edition version of the Source code that's designed to work with Visual Studio 2019 without issues, which can be found here: github.com/Nbc66/source-sdk-2013-ce