Page 1 of 2

How do I allow AI to trigger OnEnterRegion?

Posted: Tue Dec 06, 2016 11:49 pm
by SkinnyODST
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?

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Wed Dec 07, 2016 6:37 pm
by Marth8880
Yep, that's just the OnEnterRegion event handler at its simplest form.

Code: Select all

OnEnterRegion(
	function(region, character)
		--do stuff
	end,
"region"
)

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Thu Dec 08, 2016 1:42 am
by SkinnyODST
This doesn`t seem to work?

Code: Select all

 OnEnterRegion(
    function(region, character)
       SetupAmbushTrigger("ambushregion", "ambushpath", 8, 5)
    end,
 "ambushregion"
 )
    
 end
I know I`m doing something wrong, how do I set this out correctly?

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Thu Dec 08, 2016 2:29 am
by Marth8880
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:

Code: Select all

-- Spawn 10 units from REP at the path "ambush_clones"
Ambush("ambush_clones", 10, REP)
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

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Thu Dec 08, 2016 2:50 am
by SkinnyODST
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!

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Thu Dec 08, 2016 2:53 am
by Marth8880
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.
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:

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
I'd strongly suggest giving battlefront2_scripting_system.doc a good, thorough read-through. ;)

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Thu Dec 08, 2016 2:55 am
by AnthonyBF2
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!
Try:

Code: Select all

 OnEnterRegion(
    function(region, character)
	if GetCharacterTeam(character) == "REP" then
        Aumbush("ambushregion", "ambushpath", 8, 5)
    end,
 "ambushregion"
 )
    
 end

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Thu Dec 08, 2016 2:57 am
by Marth8880
@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

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Thu Dec 08, 2016 2:59 am
by AnthonyBF2
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
Yeah, I edited my post. I was just copying the code from an above post before I saw your correction.

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Thu Dec 08, 2016 3:00 am
by Marth8880
ahah of cause ^^

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Thu Dec 08, 2016 5:12 am
by SkinnyODST
Try:

Code: Select all
OnEnterRegion(
function(region, character)
if GetCharacterTeam(character) == "REP" then
Aumbush("ambushregion", "ambushpath", 8, 5)
end,
"ambushregion"
)

end
Whenever I put that in, I get errors. Is there a bracket missing?
It says:
Hidden/Spoiler:
[code]C:\BF2_ModTools\data_CCC\_BUILD\Common\..\..\..\ToolsFL\Bin\luac.exe: ..\..\common\scripts\CCC\CCCc_con.lua:112: unexpected symbol near `,'
ERROR[scriptmunge scripts\CCC\CCCc_con.lua]:Could not read input file.ERROR[scriptmunge scripts\CCC\CCCc_con.lua]:Could not read input file. [continuing]
2 Errors 0 Warnings

ERROR[levelpack mission\CCCc_con.req]:Expecting bracket, but none was found.
File : munged\pc\cccc_con.script.req(1)...

ucft <--
ERROR[levelpack mission\CCCc_con.req]:Expecting bracket, but none was found.
File : munged\pc\cccc_con.script.req(1)...

ucft <--

2 Errors 0 Warnings[/code]

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Thu Dec 08, 2016 5:53 am
by AnthonyBF2
Try adding another end after end

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Fri Dec 09, 2016 1:05 am
by SkinnyODST
Nope. Still says the same thing

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Fri Dec 09, 2016 1:10 am
by AnthonyBF2
Oh I think you posted some bit of text from this webpage. :P

Look closely at the beginning.

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Fri Dec 09, 2016 2:45 am
by SkinnyODST
Hidden/Spoiler:
[code] EnableSPHeroRules()

OnEnterRegion(
function(region, character)
if GetCharacterTeam(character) == "REP" then
Aumbush("ambushregion", "ambushpath", 8, 5)
end,
"ambushregion"
)

end

end[/code]
Still the same errors?

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Fri Dec 09, 2016 2:47 am
by AnthonyBF2
Take off the other end I said to add earlier.

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Fri Dec 09, 2016 5:02 am
by SkinnyODST
Nope.

Code: Select all

   EnableSPHeroRules()

 OnEnterRegion(
    function(region, character)
   if GetCharacterTeam(character) == "REP" then
        Aumbush("ambushregion", "ambushpath", 8, 5)
    end,
 "ambushregion"
 )
    
 end

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Fri Dec 09, 2016 9:57 am
by Teancum
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

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Sat Dec 10, 2016 3:25 am
by SkinnyODST
Hidden/Spoiler:
[code]function ScriptPostLoad()

function SetupAmbushTrigger(ambushregion, ambushpath, 8, 5)
local trigger --must be declared before being used
trigger = OnEnterRegion(
function(region, character)
if IsCharacterHuman (character) then
Ambush(ambushpath, 8, 5)
ReleaseEnterRegion(trigger)
end
end,
ambushregion
)
ActivateRegion(ambushregion)
end[/code]
Shows errors. The region is called "ambushregion" and the path is called "ambushpath"

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.

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Sat Dec 10, 2016 4:50 pm
by Marth8880
DeactivateRegion("regionname") should do it.