Weapon physcannon

From Valve Developer Community
Jump to: navigation, search
English (en)
Edit
Weapon physcannon.png

weapon_physcannon is a point entity available in the Half-Life 2 series. It's the Zero-Point Energy Field Manipulator (AKA Gravity Gun), used to manipulate physics objects in the game world. Before it is picked up, the gravity gun also follows all physics rules as if it were a prop_physics.

Tip.pngTip:To supercharge the Gravity Gun, use an env_global entity to enable the global state super_phys_gun. This does not work in Half-Life 2: Deathmatch or Portal.
Icon-Bug.pngBug:Sometimes the game may crash when the player is holding something at the moment they pick up the gravity gun.

Games

Blank image.pngTodo:

Half-Life 2: Deathmatch Half-Life 2: Deathmatch

Players spawn with a gravity gun by default.

Dedicated ConVars

g_debug_physcannon

g_debug_physcannon <bool>
Enables Gravity Gun debugging, which shows a wire frame outline around objects when picked up(Default: 0)

physcannon_cone

physcannon_cone <float>
Changes how wide the pickup range is, lower numbers are wider (Default: 0.97)

physcannon_ball_cone

physcannon_ball_cone <float>
Blank image.pngTodo: Add a description for this variable.

(Default: 0.997)

physcannon_punt_cone

physcannon_punt_cone <float>
Blank image.pngTodo: Add a description for this variable.

(Default: 0.997)

physcannon_minforce

physcannon_minforce <float>
Blank image.pngTodo: Add a description for this variable.

(Default: 700.0)

physcannon_maxforce

physcannon_maxforce <float>
Blank image.pngTodo: Add a description for this variable.

(Default: 1500.0)

physcannon_maxmass

physcannon_maxmass <float>
Sets the maximum mass at which an object can be picked up by the gravity gun(Default: 250.0)

physcannon_pullforce

physcannon_pullforce <float>
How much force to be used when pulling objects to the player(Default: 4000.0)

physcannon_tracelength

physcannon_tracelength <float>
How far an object can be pulled from(Default: 250.0)

physcannon_mega_enabled

physcannon_mega_enabled <bool>
Enables Dark Energy Field Manipulator(Default: 0).

physcannon_mega_pullforce

physcannon_mega_pullforce <float>
How much force the Dark Energy Field Manipulator (Default: 8000.0)

physcannon_mega_tracelength

physcannon_mega_tracelength <float>
The distance at which the Dark Energy Field Manipulator will be able to pull an object(Default: 850.0)

player_throwforce

player_throwforce <float>
Blank image.pngTodo: Add a description for this variable.

(Default: 1000.0)

KeyValues


Base:
Name (targetname) <string>
The name that other entities use to refer to this entity.
Parent (parentname) <targetname>
Maintain the same initial offset to this entity. An attachment point can also be used if separated by a comma at the end. (parentname [targetname],[attachment])
Tip.pngTip:Entities transition to the next map with their parents
Tip.pngTip:phys_constraint can be used as a workaround if parenting fails.
Origin (X Y Z) (origin) <coordinates>
The position of this entity's center in the world. Rotating entities typically rotate around their origin.
Note.pngNote:Hammer does not move the entities accordingly only in the editor.
Pitch Yaw Roll (X Y Z) (angles) <angle>
This entity's orientation in the world. Pitch is rotation around the Y axis, yaw is the rotation around the Z axis, roll is the rotation around the X axis.
Note.pngNote:This works on brush entities, although Hammer doesn't show the new angles.
Classname (classname) <string> !FGD
Determines the characteristics of the entity before it spawns.
Tip.pngTip:Changing this on runtime still has use, like making matching an entry in S_PreserveEnts will persist the entity on new rounds!
Flags (spawnflags) <integer> !FGD
Toggles exclusive features of an entity, its specific number is determined by the combination of flags added.
Effects (effects) <integer> !FGD
Combination of effect flags to use.
Entity Scripts (vscripts) <scriptlist> (in all games since Left 4 Dead 2) (also in Team Fortress 2)
Space delimited list of VScript files (without file extension) that are executed after all entities have spawned. The scripts are all executed in the same script scope, later ones overwriting any identical variables and functions. Scripts executed on the worldspawn entity will be placed in root scope.
Think function (thinkfunction) <string> (in all games since Left 4 Dead 2) (also in Team Fortress 2)
Name of the function within this entity's script that'll be called automatically every 100 milliseconds, or a user-defined interval if the function returns a number. Avoid expensive operations in this function, as it may cause performance problems.
Lag Compensation (LagCompensate) <boolean> (in all games since Left 4 Dead 2) !FGD
Set to Yes to lag compensate this entity. Should be used very sparingly!
Is Automatic-Aim Target (is_autoaim_target) <boolean> (in all games since Counter-Strike: Global Offensive) !FGD
If set to 1, this entity will slow down aiming movement for consoles and joystick controllers when the entity is under the crosshairs.

BaseFadeProp:

Start Fade Dist (fademindist) <float>
Distance at which the prop starts to fade.
End Fade Dist (fademaxdist) <float>
Max fade distance at which the prop is visible.
  • If start fade is <0, the prop will disappear instantly when end fade is hit.
  • If end fade is <0, the prop won't disappear at all. (This is the default behavior.)
The values will scale appropriately if the prop is in a 3D Skybox.
Fade Scale (fadescale) <float>
If you specify so in worldspawn, or if the engine is running below DirectX 8 (DX7 in Source 2006), props will fade out even if the fade distances above aren't specified. This value gives you some control over when this happens: numbers smaller than 1 cause the prop to fade out at further distances, while those greater than 1 cause it to fade out at closer distances. Using 0 turns off the forced fade altogether. See also the QC command $noforcedfade.

Flags

  •  [1] : Start Constrained
       Prevents the model from moving. Off by default.
  •  [2] : Start without grab functionality.
       Obsolete (in all games since Half-Life 2: Episode One)
  •  [2] : Deny player pickup (reserve for NPC) (in all games since Half-Life 2: Episode One)
  •  [4] : Not puntable by Gravity Gun (in all games since Half-Life 2: Episode One)

Inputs

EnableGrab
Enable the grab functionality. Obsolete (in all games since Half-Life 2: Episode One)

Base:
AddContext <string>
Adds to the entity's list of response contexts. See Context.
AddOutput <string>
Assigns a new keyvalue/output on this entity. For keyvalues, some rely on extra necessary code to be ran and won't work if its simply just changed through this input. There is a strict format that must be followed:
// Format of changing KeyValues: "AddOutput [key] [value]"
//// Raw text:
"OnUser1" "!self,AddOutput,targetname new_name"

// Format of adding an Output: "AddOutput {targetname}:{inputname}:{parameter}:{delay}:{max times to fire, -1 means infinite}"
//// Raw text:
"OnUser1" "!self,AddOutput,OnUser1:SetParent:!activator:0.0:-1"
// Arguments can be left blank, but the empty blank should still be contained.
//// Raw text:
"OnUser1" "!self,AddOutput,OnUser1:ClearParent::0.0:-1"
ClearContext
Removes all contexts from this entity's list.
ClearParent
Removes this entity from the the movement hierarchy, leaving it free to move independently.
FireUser1 to FireUser4
Fires the respectiveOnUseroutputs; see User Inputs and Outputs.
Kill
Removes this entity and any entities parented to it from the world.
KillHierarchy
Functions the same as Kill, although this entity and any entities parented to it are killed on the same frame, being marginally faster thanKillinput.
RemoveContext <string>
Remove a context from this entity's list. The name should match the key of an existing context.
SetParent <string>
Move with this entity. See Entity Hierarchy (parenting).
SetParentAttachment <string>
Change this entity to attach to a specific attachment point on its parent. The entity will teleport so that the position of its root bone matches that of the attachment. Entities must be parented before being sent this input.
SetParentAttachmentMaintainOffset <string>
As above, but without teleporting. The entity retains its position relative to the attachment at the time of the input being received.
Use  !FGD
Same as a player invoking +use; no effect in most cases.
DispatchResponse <string> !FGD
Dispatches a response to the entity. See Response and Concept.
DispatchEffect <string> (removed since Left 4 Dead) !FGD
Dispatches a special effect from the entity's origin; See also List of Client Effects. Replaced by the particle system since Left 4 Dead.
RunScriptFile <script> (in all games since Left 4 Dead 2) (also in Team Fortress 2)
Execute a VScript file from disk, without file extension. The script contents are merged with the script scope of the receiving entity.
RunScriptCode <string> (in all games since Left 4 Dead 2) (also in Team Fortress 2)
Execute a string of VScript source code in the scope of the entity receiving the input. String quotation may be needed when fired via console.
Icon-Bug.pngBug:In Hammer, using string arguments will corrupt the VMF file's structure, making the file unviewable for the next Hammer session.
Note.pngFix:Remove the string argument manually with a text editor.
Note.pngNote:Team Fortress 2 Backtick characters ` are replaced with quotation marks at runtime, allowing quotation marks to be used when normally not possible.
CallScriptFunction <string> (in all games since Left 4 Dead 2) (also in Team Fortress 2) !FGD
Calls a VScript function defined in the scope of the receiving entity.
TerminateScriptScope  (only in Team Fortress 2) !FGD
Destroys the script scope of the receving entity.
SetLocalOrigin <coordinates> (in all games since Alien Swarm) !FGD
Send this entity to a spot in the map. If the entity is parented to something, it will be offset from the parent by this amount.
SetLocalAngles <angles> (in all games since Alien Swarm) !FGD
Set this entity's angles.

Outputs

Weapon:

OnNPCPickup
Fires when an NPC picks up this weapon. (!activator is the NPC.)
OnPlayerUse
Fires when the player +uses this weapon. (!activator is the player.)
OnPlayerPickup
Fires when a player picks up this weapon. (!activator is the player.)
OnCacheInteraction
Fires when the player 'proves' they've found this weapon. Fires on: Player Touch, +USE pickup, Physcannon pickup, Physcannon punt.

Base:

OnUser1 to OnUser4
These outputs each fire in response to the firing of the like-numbered FireUser1 to FireUser4 Input; see User Inputs and Outputs.

Half-Life 2: Deathmatch Half-Life 2: Deathmatch Dark Energy Field Manipulator fix

In Half-Life 2: Deathmatch Half-Life 2: Deathmatch the Zero-Point Energy Field Manipulator (AKA Gravity Gun) won't go into supercharged mode. There is a fix to this. First open shared\hl2mp\weapon_physcannon.cpp

NOTICE: I'm going to update this to work with the correct file.

At line 50 or near add:

extern ConVar physcannon_mega_enabled;

Now find:

	// Do we have the super-phys gun?
	inline bool	PlayerHasMegaPhysCannon()
	{
	return false;
	}

and replace it with:

	inline bool	PlayerHasMegaPhysCannon()
	{
		if ( physcannon_mega_enabled.GetBool() || GlobalEntity_GetState("super_phys_gun") )
		{
			return true;
		}
		else
		{
			return false;
		}
	}

Now at line 2047 or near replace:

m_grabController.AttachEntity( pOwner, pObject, pPhysics, false, vPosition, false );

With:

m_grabController.AttachEntity( pOwner, pObject, pPhysics, IsMegaPhysCannon(), vPosition, false);

Now at line 2473 or near replace:

GetGrabController().AttachEntity( ToBasePlayer( GetOwner() ), pAttachedObject, pPhysics, false, vec3_origin, false);

With:

GetGrabController().AttachEntity( ToBasePlayer( GetOwner() ), pAttachedObject, pPhysics, IsMegaPhysCannon(), vec3_origin, false);

Now near line 3102 after:

void CWeaponPhysCannon::CloseElements( void )
{

Add:

// The mega cannon cannot be closed!
if (IsMegaPhysCannon())
{
	OpenElements();
	return;
}

Now Near line 2041 replace:

float CWeaponPhysCannon::TraceLength()
{
	return physcannon_tracelength.GetFloat();
}

With:

float CWeaponPhysCannon::TraceLength()
{
	if(!IsMegaPhysCannon())
	return physcannon_tracelength.GetFloat();
	else
	return physcannon_mega_tracelength.GetFloat();
}

The effects are not ready.

This is not the finished code. Writing it down will take a while and I still have some other things to do with the code. I'll go post the finished parts of the code on Github. There is some extra code for allowing one Gravity Gun to be Mega/Upgraded and one Normal. https://github.com/TheVogels/Source-SDK-2013-Multiplayer-physcannon-mega-fix

Now compile the project and it should work. weapon_physcannon is a point entity available in the Half-Life 2 series.