weapon_portalgun

From Valve Developer Community
Jump to: navigation, search

weapon_portalgun is a point entity available in the Portal (series) Portal games. This is the Aperture Science Handheld Portal Device, the main item used throughout the series. Before being picked up, it can fire portals and is often placed on a pedestal. It can be used to pick up physics objects that weigh up to 85kg.

As with all weapon entities, the portal gun will continue to exist after being picked up, but have its targetname cleared. Using VScript, point_entity_finder, or simply by pointing outputs at the weapon_portalgun classname, a portal gun being carried by a player can be made to fire portals automatically, or change which portals it can fire using AddOutput.

The portal gun can be obtained with the give_portalgun command (only in Portal 2), and upgraded with the upgrade_portalgun command.

Icon-Bug.pngBug:If a portal has been fired and this weapon is dropped into a trigger_portal_cleanser via a trigger_weapon_strip, the game will crash. This is fixed in P2:CE.
A weapon_portalgun firing.
Note.pngNote:A weapon_portalgun firing on its own will not target info_placement_helpers (even ones with Force Placement enabled).


Portal 2 Spawning with a portal gun

In Portal 2, players may automatically recieve a portal gun on spawn in certain cases, which vary between singleplayer and co-op.

In singleplayer the player will recieve a portal gun on spawn if the map has the prefix sp_

Singleplayer

Valve's singleplayer transition VScript (transitions/sp_transition_list.nut) will always give the player a dual portal gun on spawn in non-default maps. This script is included in the arrival_departure_transition_ents instance, but it also gets automatically added to the map if the map name starts with sp_. If you don't want the player to spawn with a portal gun in a standalone map, the easiest way to work around this is to add a trigger_weapon_strip in the elevator shaft, which removes the player's gun before giving them a new one if desired. If you're making a mod, you should instead modify the singleplayer transition script to include your mod's maps instead of the default ones, which will allow you to specify which portal gun the player has in each map.

Internally, if the map name starts with sp_, the game checks for a logic_script called @transition_script on load. If one doesn't exist, it creates a new logic_script called failsafe_transition_script and sets it to run transitions/sp_transition_list.nut. Note that the Entity Scripts keyvalue is not checked on the original @transition_script entity, so this can be used to prevent the transition script from running at all - place the entity in Hammer and give it that name, but leave the entity scripts blank. It may be useful to create a modified version of the arrival_departure_transition_ents which uses this method to get rid of the script entirely, since standalone maps don't really need it.

Co-op

In cooperative mode, players will spawn with portal guns by default. This is done in code, not VScript like in singleplayer. To prevent players from spawning with portal guns, any entity named supress_blue_portalgun_spawn (for Atlas) and/or supress_orange_portalgun_spawn (for P-Body) must be present in the map. These work independently from each other, allowing a portal gun to be given to one player only, and are checked on every respawn, so they can be Killed to enable portal guns on respawn, or spawned from a point_template to disable portal guns on respawn mid-map.

If you want players to pick up portal guns partway through the map, the easiest way to handle this is to give these names to the weapon_portalguns themselves. Picking up a portal gun automatically clears its name, allowing that player to spawn with a portal gun on every subsequent respawn.

Note.pngNote:There is a keyvalue on info_coop_spawn and a global state that both pertain to spawning with a portal gun, but neither appears to do anything; the method above must be used.

Keyvalues

Can Fire Portal 1 (CanFirePortal1) <boolean>
Can this portal gun create blue portals?
Can Fire Portal 2 (CanFirePortal2) <boolean>
Can this portal gun create orange portals?
Show PotatOS <boolean> (in all games since Portal 2)
Does this portal gun have PotatOS on the end?
Icon-Bug.pngBug:Non-functional. Instead, use the AddPotatosToPortalgun input of logic_playerproxy or the command upgrade_potatogun to show PotatOS.
Starting Team <choices> (in all games since Portal 2)
Which team this gun originally belongs to. Will decide which portals it fires before being picked up.
  • 0 : Single Player
  • 2 : Orange
  • 3 : Blue

Targetname:
Name (targetname) <string>
The targetname that other entities refer to this entity by.

Angles:
Pitch Yaw Roll (Y Z X) (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.

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
Note.pngNote:Prevents the model from moving.
Icon-Bug.pngBug:Unparenting unconstrained weapons will corrupt its position.
  •  [2] : Deny player pickup (reserve for NPC)
  •  [4] : Not puntable by Gravity Gun
  •  [8] : Disable pickup sound Portal 2: Community Edition

Inputs

ChargePortal1
Does charge up effect for mounted portal gun.
ChargePortal2
Does charge up effect for mounted portal gun.
FirePortal1
Projects portal 1 (blue) onto a wall in the facing direction of the gun.
FirePortal2
Projects portal 2 (orange) onto a wall in the facing direction of the gun.
FirePortalDirection1 <angle>
Fires the blue portal in the specified direction.
Icon-Bug.pngBug:Using this input in Portal 2 will crash the game.
FirePortalDirection2 <angle>
Fires the orange portal in the specified direction.
Icon-Bug.pngBug:Using this input in Portal 2 will crash the game.

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

OnFiredPortal1
Fires when the first (blue) portal is fired.
OnFiredPortal2
Fires when the second (orange) portal is fired.

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.