Difference between revisions of "Dota 2 Workshop Tools/Scripting/Simple Trigger that calls Lua"

From Valve Developer Community
Jump to: navigation, search
m (editing the output to be "volvo wiki" style.)
Line 10: Line 10:
  
 
* '''Step 6:''' Add an output named "OnStartTouch". Set the trigger as the target. The input should be "CallScriptFunction" and the parameter should be the name of the function you want to be called.
 
* '''Step 6:''' Add an output named "OnStartTouch". Set the trigger as the target. The input should be "CallScriptFunction" and the parameter should be the name of the function you want to be called.
 +
 +
::{| class=standard-table
 +
!  || My Output || Target Entity || Target Input || Parameter || Delay || Only Once
 +
|-
 +
| [[Image:Io11.png]] || OnStartTouch || trigger_name|| CallScriptFunction || MyFunction || 0.00 || No
 +
|}
  
 
* '''Step 6:''' Add another output with the same values, but the name should be "OnEndTouch". You probably want to set a different function name as well.
 
* '''Step 6:''' Add another output with the same values, but the name should be "OnEndTouch". You probably want to set a different function name as well.

Revision as of 00:51, 11 August 2014

  • Step 1: Create a box with the block tool (Shift+B). Make sure you have the "toolstrigger.vmat" material selected. This box will server as the trigger area.
  • Step 2: Select the box and go to "Tools > Tie To Entity" (Ctrl+T). This will create a trigger entity that is tied with your box.
  • Step 3: Select the trigger and change its class to "trigger_hero". This trigger is meant to be used for when a player enters or leaves the trigger area. There are a lot of types of triggers but let's keep it simple for now.
  • Step 4: Set a name and the path to the script file you want to call functions from.
  • Step 5: With the trigger selected press Alt+Enter to open the Object Properties window, then select the Outputs tabs.
  • Step 6: Add an output named "OnStartTouch". Set the trigger as the target. The input should be "CallScriptFunction" and the parameter should be the name of the function you want to be called.
My Output Target Entity Target Input Parameter Delay Only Once
Io11.png OnStartTouch trigger_name CallScriptFunction MyFunction 0.00 No
  • Step 6: Add another output with the same values, but the name should be "OnEndTouch". You probably want to set a different function name as well.


Example lua code:

function OnStartTouch(trigger)

	print(trigger.activator)
	print(trigger.caller)
	
end

function OnEndTouch(trigger)

	print(trigger.activator)
	print(trigger.caller)
	
end