Skip to content

Conversation

@steadyfield
Copy link
Contributor

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_tank entity to use a prop_dynamic as its model, rather than the model of func_tank itself. And the mounted ar2 (Combine Mounted Gun) uses this option. To do this, the func_tank should be parented to the prop_dynamic, where prop_dynamic is the mounted ar2 gun model. The func_tank checks whether it is already parented to a valid prop_dynamic on its spawn function. If it is, the func_tank will configurate itself to use the right parameters for the mounted ar2.
However, when the func_tank is spawned by console commands (ent_create), it is impossible to parent it to any prop_dynamic BEFORE it is spawned, because the parentname keyvalue is only checked and executed on map load, which is defined in mapentities.cpp. After it is spawned by console commands, using ent_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 its spawn function.

Solution:
To solve this problem, I added the parentname keyvalue check and the parameter self-configuration code in the function CFuncTank::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

ar2

Fixed mounted gun anims and effects when spawned by .cfg user scripts.
@nillerusr
Copy link
Owner

why not

@nillerusr nillerusr merged commit e9af8c6 into nillerusr:master Feb 16, 2023
@steadyfield
Copy link
Contributor Author

why not

@nillerusr thanks for merging, and you can check all my entity scripts in my repo:
https://github.com/steadyfield/HL2_Entity_Script
The repo will be kept updating. All my new entity scripts will be posted there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants