How do I allow AI to trigger OnEnterRegion?
Moderator: Moderators
-
- Lieutenant Colonel
- Posts: 545
- Joined: Mon Jul 04, 2016 10:56 pm
- Location: My other account
- Contact:
How do I allow AI to trigger OnEnterRegion?
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?
-
- Resistance Leader
- Posts: 5042
- Joined: Tue Feb 09, 2010 8:43 pm
- Projects :: DI2 + Psychosis
- xbox live or psn: Marth8880
- Location: Edinburgh, UK
- Contact:
Re: How do I allow AI to trigger OnEnterRegion?
Yep, that's just the OnEnterRegion event handler at its simplest form.
Code: Select all
OnEnterRegion(
function(region, character)
--do stuff
end,
"region"
)
-
- Lieutenant Colonel
- Posts: 545
- Joined: Mon Jul 04, 2016 10:56 pm
- Location: My other account
- Contact:
Re: How do I allow AI to trigger OnEnterRegion?
This doesn`t seem to work?
I know I`m doing something wrong, how do I set this out correctly?
Code: Select all
OnEnterRegion(
function(region, character)
SetupAmbushTrigger("ambushregion", "ambushpath", 8, 5)
end,
"ambushregion"
)
end
-
- Resistance Leader
- Posts: 5042
- Joined: Tue Feb 09, 2010 8:43 pm
- Projects :: DI2 + Psychosis
- xbox live or psn: Marth8880
- Location: Edinburgh, UK
- Contact:
Re: How do I allow AI to trigger OnEnterRegion?
Oh, you're trying to use SetupAmbushTrigger? That does all of the OnEnterRegion and ActivateRegion stuff for you. With that said, it does it only when humans enter the region. Instead, what you could do is simply call Ambush(spawnPathName, numDudes, fromTeam) (obviously replacing the arguments with your own values, just like with SetupAmbushTrigger) inside your OnEnterRegion handler.
Example of using Ambush:
Do note that the path that is used must have at least as many nodes as the number of units to spawn. For example, if "ambush_clones" only has 7 path nodes, only 7 units will spawn. However, if it has 10 or more nodes, than all 10 units will spawn.
Keep the following thread in mind if you have any other issues with it: http://www.gametoast.com/viewtopic.php?f=27&t=6132
Example of using Ambush:
Code: Select all
-- Spawn 10 units from REP at the path "ambush_clones"
Ambush("ambush_clones", 10, REP)
Keep the following thread in mind if you have any other issues with it: http://www.gametoast.com/viewtopic.php?f=27&t=6132
-
- Lieutenant Colonel
- Posts: 545
- Joined: Mon Jul 04, 2016 10:56 pm
- Location: My other account
- Contact:
Re: How do I allow AI to trigger OnEnterRegion?
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!
-
- Resistance Leader
- Posts: 5042
- Joined: Tue Feb 09, 2010 8:43 pm
- Projects :: DI2 + Psychosis
- xbox live or psn: Marth8880
- Location: Edinburgh, UK
- Contact:
Re: How do I allow AI to trigger OnEnterRegion?
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
end
Last edited by Marth8880 on Thu Dec 08, 2016 2:56 am, edited 1 time in total.
- AnthonyBF2
- Sith
- Posts: 1255
- Joined: Wed Aug 21, 2013 3:55 pm
- Projects :: PS2+PSP Overhaul
Re: How do I allow AI to trigger OnEnterRegion?
Try: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"
)
end
-
- Resistance Leader
- Posts: 5042
- Joined: Tue Feb 09, 2010 8:43 pm
- Projects :: DI2 + Psychosis
- xbox live or psn: Marth8880
- Location: Edinburgh, UK
- Contact:
Re: How do I allow AI to trigger OnEnterRegion?
@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
Last edited by Marth8880 on Thu Dec 08, 2016 2:59 am, edited 1 time in total.
- AnthonyBF2
- Sith
- Posts: 1255
- Joined: Wed Aug 21, 2013 3:55 pm
- Projects :: PS2+PSP Overhaul
Re: How do I allow AI to trigger OnEnterRegion?
Yeah, 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
-
- Resistance Leader
- Posts: 5042
- Joined: Tue Feb 09, 2010 8:43 pm
- Projects :: DI2 + Psychosis
- xbox live or psn: Marth8880
- Location: Edinburgh, UK
- Contact:
Re: How do I allow AI to trigger OnEnterRegion?
ahah of cause ^^
-
- Lieutenant Colonel
- Posts: 545
- Joined: Mon Jul 04, 2016 10:56 pm
- Location: My other account
- Contact:
Re: How do I allow AI to trigger OnEnterRegion?
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
It says:
Hidden/Spoiler:
- AnthonyBF2
- Sith
- Posts: 1255
- Joined: Wed Aug 21, 2013 3:55 pm
- Projects :: PS2+PSP Overhaul
Re: How do I allow AI to trigger OnEnterRegion?
Try adding another end after end
-
- Lieutenant Colonel
- Posts: 545
- Joined: Mon Jul 04, 2016 10:56 pm
- Location: My other account
- Contact:
Re: How do I allow AI to trigger OnEnterRegion?
Nope. Still says the same thing
- AnthonyBF2
- Sith
- Posts: 1255
- Joined: Wed Aug 21, 2013 3:55 pm
- Projects :: PS2+PSP Overhaul
Re: How do I allow AI to trigger OnEnterRegion?
Oh I think you posted some bit of text from this webpage.
Look closely at the beginning.
Look closely at the beginning.
-
- Lieutenant Colonel
- Posts: 545
- Joined: Mon Jul 04, 2016 10:56 pm
- Location: My other account
- Contact:
Re: How do I allow AI to trigger OnEnterRegion?
Hidden/Spoiler:
- AnthonyBF2
- Sith
- Posts: 1255
- Joined: Wed Aug 21, 2013 3:55 pm
- Projects :: PS2+PSP Overhaul
Re: How do I allow AI to trigger OnEnterRegion?
Take off the other end I said to add earlier.
-
- Lieutenant Colonel
- Posts: 545
- Joined: Mon Jul 04, 2016 10:56 pm
- Location: My other account
- Contact:
Re: How do I allow AI to trigger OnEnterRegion?
Nope.
Code: Select all
EnableSPHeroRules()
OnEnterRegion(
function(region, character)
if GetCharacterTeam(character) == "REP" then
Aumbush("ambushregion", "ambushpath", 8, 5)
end,
"ambushregion"
)
end
- Teancum
- Jedi Admin
- Posts: 11080
- Joined: Wed Sep 07, 2005 11:42 pm
- Projects :: No Mod project currently.
- xbox live or psn: No gamertag set
- Location: Indiana
Re: How do I allow AI to trigger OnEnterRegion?
Ensure you're using the code Marth posted earlier
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) <- 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
-
- Lieutenant Colonel
- Posts: 545
- Joined: Mon Jul 04, 2016 10:56 pm
- Location: My other account
- Contact:
Re: How do I allow AI to trigger OnEnterRegion?
Hidden/Spoiler:
EDIT: Actually, seeing as this isn`t working, I have a workaround. What code do I put in to delete the ambushregion after the CP (that the ambushers spawn near) has been captured? Seeing as only the player can trigger it, if the AI capture the CP before the player gets to the ambush region, I don`t want the ambushers to spawn.
-
- Resistance Leader
- Posts: 5042
- Joined: Tue Feb 09, 2010 8:43 pm
- Projects :: DI2 + Psychosis
- xbox live or psn: Marth8880
- Location: Edinburgh, UK
- Contact:
Re: How do I allow AI to trigger OnEnterRegion?
DeactivateRegion("regionname") should do it.