Fixed Mounted Gun Anims and Effects When Spawned by Users #192
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do:
This pull request fixes the animations and effects of the func_tank (mounted gun) when it is spawned by users using .CFG console command script. This fix will NOT break or change any original gameplay experience in HL2 chapter maps where there are mounted guns.
Why is this PR useful:
It is important to notice that user-made .CFG scripts make the gameplay more fun, and provide a more GMOD-like experience. There are a lot of people using TOUCH spawnmenus on the android version because they want a GMOD-like experience in the original game. This PR will open up more possibilities for the players by allowing them to spawn mounted guns with correct anims and effects in ANY maps. Users can also make .CFG scripts to attach different entities to the func_tank using ent_* commands, therefore they can make custom weapons with various effects. Besides, this fix will not break or modify any original gameplay experience in HL2 maps.
Statement of the original problem:
In the original game, when player spawns a mounted AR2 gun (Combine Mounted Gun) using console command script (entity commands
ent_*written in a .CFG file), there are no firing muzzle effects, no gun rotating animations, and the bullet traces come from a wrong place (it should come from the muzzle of the mounted AR2 gun model).Problem details and causes:
In the HL2 game, there is a option for the
func_tankentity to use aprop_dynamicas its model, rather than the model offunc_tankitself. And themounted ar2(Combine Mounted Gun) uses this option. To do this, thefunc_tankshould beparentedto theprop_dynamic, whereprop_dynamicis the mounted ar2 gun model. Thefunc_tankchecks whether it is alreadyparentedto a validprop_dynamicon itsspawn function. If it is, thefunc_tankwill configurate itself to use the right parameters for the mounted ar2.However, when the
func_tankis spawned by console commands (ent_create), it is impossible toparentit to anyprop_dynamicBEFORE it is spawned, because theparentnamekeyvalue is only checked and executed on map load, which is defined inmapentities.cpp. After it is spawned by console commands, usingent_fire [tankentity] setparent [prop_dynamic entity]will be useless for solving the anims and effects problem because the parenting check and parameter self-configuration process is only done in itsspawn function.Solution:
To solve this problem, I added the
parentnamekeyvalue check and the parameter self-configuration code in the functionCFuncTank::Activate(), then the mounted ar2 is working fine with all the correct anims and effects.The .CFG script in ZIP format for spawning mounted ar2 to test:
create_mounted_ar2.zip
Video demonstration:
HALF-LIFE.2.2023-02-08.08-58-11.mp4