Point script use target: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
(Added example)
Line 1: Line 1:
{{l4d2 point|point_script_use_target}} It makes an other entity behave like a button similar to [[func_button_timed]]. The entity is intended to be programmed from an attached [[L4D2_Vscripts|VScript]] instead of using Hammer, and calls hook functions in its own scripting scope as well as normal entity outputs. It is mainly used for run-time created [[L4D2_EMS/Appendix:_Spawning|entity groups]] together with a use target script based on <code>usetargets\base_buildable_target.nut</code>.  
{{l4d2 point|point_script_use_target}} It makes an other entity behave like a button similar to [[func_button_timed]]. The entity is intended to be programmed from an attached [[L4D2_Vscripts|VScript]] instead of using Hammer, and calls hook functions in its own scripting scope as well as normal entity outputs. It is mainly used for run-time created [[L4D2_EMS/Appendix:_Spawning|entity groups]] together with a use target script based on <code>usetargets\base_buildable_target.nut</code>.  


See the scripts in <code>left 4 dead 2\sdk_content\scripting\scripts\vscripts\</code> for examples of use.
See the scripts in <code>left 4 dead 2\sdk_content\scripting\scripts\vscripts\</code> for more examples of use.


== Game engine hooks ==
== Game engine hooks ==
Line 16: Line 16:
|<code>OnUseStart</code>
|<code>OnUseStart</code>
|<code>bool OnUseStart()</code>
|<code>bool OnUseStart()</code>
|Called when the player begins to use this button. Return false to stop the player from using the button.
|Called when the player begins to use this button. Return false to disable the third-person use animation.
|-
|-
|<code>OnUseStop</code>
|<code>OnUseStop</code>
Line 53: Line 53:
|<code>SetProgressBarFinishTime</code>
|<code>SetProgressBarFinishTime</code>
|<code>void self.SetProgressBarFinishTime(float ''time'')</code>
|<code>void self.SetProgressBarFinishTime(float ''time'')</code>
|Sets the total time the button takes to use.
|Sets the total time the button takes to use. If '0', no progress bar will be displayed.  
|-
|-
|<code>SetProgressBarCurrentProgress</code>
|<code>SetProgressBarCurrentProgress</code>
Line 61: Line 61:
|<code>StopUse</code>
|<code>StopUse</code>
|<code>void self.StopUse()</code>
|<code>void self.StopUse()</code>
|Prevents players from using the button.
|Stops the current use action.
|-
|-
|}
|}
Line 79: Line 79:
{{IO|OnUseFinished|Fired when a player use is complete.}}
{{IO|OnUseFinished|Fired when a player use is complete.}}
{{O Targetname}}
{{O Targetname}}
== Example script ==
This is a simple script that sets the use time to 5 seconds, and disables the button after use.
<source lang="cpp">
Enabled <- false; // Variable to keep track of if the button is usable.
// Called when the entity spawns.
function Precache()
{
self.SetProgressBarText( "Press me for 5 seconds" );
self.SetProgressBarSubText( "I get disabled afterwards" );
self.SetProgressBarFinishTime( 5 );
self.SetProgressBarCurrentProgress( 0.0 );
self.CanShowBuildPanel( true );
Enabled = true;
}
// Called when a player tries to use the button.
// Return false to disable the third-person use animation.
function OnUseStart()
{
return Enabled;
}
// Called when the progress bar is full.
function OnUseFinished()
{
Enabled = false;
EntFire( self.GetUseModelName(), "stopglowing" )
}
</source>

Revision as of 07:27, 1 May 2014

Template:L4d2 point It makes an other entity behave like a button similar to func_button_timed. The entity is intended to be programmed from an attached VScript instead of using Hammer, and calls hook functions in its own scripting scope as well as normal entity outputs. It is mainly used for run-time created entity groups together with a use target script based on usetargets\base_buildable_target.nut.

See the scripts in left 4 dead 2\sdk_content\scripting\scripts\vscripts\ for more examples of use.

Game engine hooks

These VScript methods are called by the entity on the script set in the Entity Scripts keyvalue.

Function Signature Description
OnUseFinished void OnUseFinished() Called when the player has used this button for at least 'FinishTime' seconds.
OnUseStart bool OnUseStart() Called when the player begins to use this button. Return false to disable the third-person use animation.
OnUseStop void OnUseStop(float timeUsed) Called when the player stops using this button. Passes the time this button has been used (time between StartUse and now).
Precache void Precache() Called by the game engine when the entity first spawns, immediately after this script is run.

Script methods

These VScript methods can be called from the script, using the self handle. The methods for CBaseEntity are also available.

Function Signature Description
CanShowBuildPanel void self.CanShowBuildPanel(bool showPanel) Sets if the UI panel for the button is shown.
GetUseModelName string self.GetUseModelName() Get the entity name of the prop bound to this button.
SetProgressBarText void self.SetProgressBarText(string text) Sets the use text for the button UI.
SetProgressBarSubText void self.SetProgressBarText(string text) Sets the subtext below the progress bar for the button UI.
SetProgressBarFinishTime void self.SetProgressBarFinishTime(float time) Sets the total time the button takes to use. If '0', no progress bar will be displayed.
SetProgressBarCurrentProgress void self.SetProgressBarCurrentProgress(float time) Sets the current use progress. It can be used to save the use progress when the user releases the use key.
StopUse void self.StopUse() Stops the current use action.

Keyvalues

Use Model ([todo internal name (i)]) <targetname>
The name of the entity the player will be using.


Name (targetname) <string>[ Edit ]
The name that other entities refer to this entity by, via Inputs/Outputs or other keyvalues (e.g. parentname or target).
Also displayed in Hammer's 2D views and Entity Report.
See also:  Generic Keyvalues, Inputs and Outputs available to all entities

Origin:

Origin (X Y Z) (origin) <origin>
The position of this entity's center in the world. Rotating entities typically rotate around their origin.

Inputs

Outputs

OnUseStarted
Fired when a player starts using this target.
OnUseCanceled
Fired when a player use is canceled.
OnUseFinished
Fired when a player use is complete.


Example script

This is a simple script that sets the use time to 5 seconds, and disables the button after use.


Enabled <- false; // Variable to keep track of if the button is usable.

// Called when the entity spawns.
function Precache()
{
	self.SetProgressBarText( "Press me for 5 seconds" );
	self.SetProgressBarSubText( "I get disabled afterwards" );
	self.SetProgressBarFinishTime( 5 );
	self.SetProgressBarCurrentProgress( 0.0 );
	self.CanShowBuildPanel( true );
	Enabled = true;
}

// Called when a player tries to use the button.
// Return false to disable the third-person use animation.
function OnUseStart()
{
	return Enabled;
}

// Called when the progress bar is full.
function OnUseFinished()
{
	Enabled = false;
	EntFire( self.GetUseModelName(), "stopglowing" )
}