How do I allow AI to trigger OnEnterRegion?
Posted: Tue Dec 06, 2016 11:49 pm
Simple question, am I able to allow for AI as well as the player to trigger OnEnterRegion functions such as an Ambush Region or something?
Get more from your games!
http://www.gametoast.com/
Code: Select all
OnEnterRegion(
function(region, character)
--do stuff
end,
"region"
)Code: Select all
OnEnterRegion(
function(region, character)
SetupAmbushTrigger("ambushregion", "ambushpath", 8, 5)
end,
"ambushregion"
)
endCode: Select all
-- Spawn 10 units from REP at the path "ambush_clones"
Ambush("ambush_clones", 10, REP)Oh that's easy. You'd just put the Ambush call inside a condition that checks if `character` (the argument passed through OnEnterRegion) is not human and is also from team REP, like so:SkinnyODST wrote:However what I want to is allow ONLY AI from the REP team to trigger it. So I think that might not be possible.
Code: Select all
-- Is the character an AI unit from team REP?
if not IsCharacterHuman(character) and GetCharacterTeam(character) == REP then
-- put Ambush call here
endTry:SkinnyODST wrote:Ok thanks! However what I want to is allow ONLY AI from the REP team to trigger it. So I think that might not be possible. But this is certainly something that will come in handy!
Code: Select all
OnEnterRegion(
function(region, character)
if GetCharacterTeam(character) == "REP" then
Aumbush("ambushregion", "ambushpath", 8, 5)
end,
"ambushregion"
)
endCode: Select all
--Designers: use this function to set up an ambush (don't call Ambush() directly, please) <- don't listen to this :u ~ Marth
function SetupAmbushTrigger(ambushRegionName, spawnPathName, numDudes, fromTeam)
local trigger --must be declared before being used
trigger = OnEnterRegion(
function(region, character)
if IsCharacterHuman (character) then
Ambush(spawnPathName, numDudes, fromTeam)
ReleaseEnterRegion(trigger)
end
end,
ambushRegionName
)
ActivateRegion(ambushRegionName)
endYeah, I edited my post. I was just copying the code from an above post before I saw your correction.Marth8880 wrote:@Anthony: The problem with SetupAmbushTrigger is that it only proceeds if the character entering the region is human:Code: Select all
--Designers: use this function to set up an ambush (don't call Ambush() directly, please) function SetupAmbushTrigger(ambushRegionName, spawnPathName, numDudes, fromTeam) local trigger --must be declared before being used trigger = OnEnterRegion( function(region, character) if IsCharacterHuman (character) then Ambush(spawnPathName, numDudes, fromTeam) ReleaseEnterRegion(trigger) end end, ambushRegionName ) ActivateRegion(ambushRegionName) end
Whenever I put that in, I get errors. Is there a bracket missing?Try:
Code: Select all
OnEnterRegion(
function(region, character)
if GetCharacterTeam(character) == "REP" then
Aumbush("ambushregion", "ambushpath", 8, 5)
end,
"ambushregion"
)
end
Code: Select all
EnableSPHeroRules()
OnEnterRegion(
function(region, character)
if GetCharacterTeam(character) == "REP" then
Aumbush("ambushregion", "ambushpath", 8, 5)
end,
"ambushregion"
)
endMarth8880 wrote:@Anthony: The problem with SetupAmbushTrigger is that it only proceeds if the character entering the region is human:Code: Select all
--Designers: use this function to set up an ambush (don't call Ambush() directly, please) <- don't listen to this :u ~ Marth function SetupAmbushTrigger(ambushRegionName, spawnPathName, numDudes, fromTeam) local trigger --must be declared before being used trigger = OnEnterRegion( function(region, character) if IsCharacterHuman (character) then Ambush(spawnPathName, numDudes, fromTeam) ReleaseEnterRegion(trigger) end end, ambushRegionName ) ActivateRegion(ambushRegionName) end