This article relates to the game "Dota 2". Click here for more information.
This article relates to the SDK/Workshop Tools for "Dota 2 Workshop Tools". Click here for more information.
This article's documentation is for Source 2. Click here for more information.

Detecting If Player Clicked Inside An Area

From Valve Developer Community
Jump to: navigation, search

  • Step 1: In Hammer, create a brush with the brush tool ( Shift+B). Make sure you have the "toolstrigger.vmat" material selected. It should cover the area you want to be tested.
  • Step 2: Select the brush you just and go to Tools > Tie To Entity (Ctrl+T). This will create a trigger entity that is tied to your box.
  • Step 3: Select the trigger and change its class to "trigger_multiple".
  • Step 4: Give the trigger a targetname, for the sake of this example, let's call it "trigger_no_ward".


Now in npc_items_custom.txt:

	"item_custom_ward"
	{
		"BaseClass"					"item_datadriven"
		"AbilityTextureName"				"item_ward_sentry"
		"AbilityBehavior"				"DOTA_ABILITY_BEHAVIOR_POINT"
		"OnSpellStart"
		{
			"RunScript"
			{
				"ScriptFile"			"scripts/vscripts/custom_ward.lua"
				"Function"		        "spawn"
			        "Target"                        "POINT"
			}	
		}
	}

And in custom_ward.lua:


function spawn(keys)
  local inTrigger = false
  local CHECKINGRADIUS = 10

    for _,thing in pairs(Entities:FindAllInSphere(GetGroundPosition(keys.target_points[1], nil), CHECKINGRADIUS) )  do

        if (thing:GetName() == "trigger_no_ward") then
            --In no_ward trigger. Set flag.
            inTrigger = true
        end

    end
    
    if (inTrigger == True)
       --Used onto specified area. Do stuff...
    end
end