How do I allow AI to trigger OnEnterRegion?

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

SkinnyODST
Lieutenant Colonel
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?

Post 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?
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: How do I allow AI to trigger OnEnterRegion?

Post 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"
)
SkinnyODST
Lieutenant Colonel
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?

Post 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?
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: How do I allow AI to trigger OnEnterRegion?

Post 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
SkinnyODST
Lieutenant Colonel
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?

Post 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!
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: How do I allow AI to trigger OnEnterRegion?

Post 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. ;)
Last edited by Marth8880 on Thu Dec 08, 2016 2:56 am, edited 1 time in total.
User avatar
AnthonyBF2
Sith
Sith
Posts: 1255
Joined: Wed Aug 21, 2013 3:55 pm
Projects :: PS2+PSP Overhaul

Re: How do I allow AI to trigger OnEnterRegion?

Post 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
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: How do I allow AI to trigger OnEnterRegion?

Post 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
Last edited by Marth8880 on Thu Dec 08, 2016 2:59 am, edited 1 time in total.
User avatar
AnthonyBF2
Sith
Sith
Posts: 1255
Joined: Wed Aug 21, 2013 3:55 pm
Projects :: PS2+PSP Overhaul

Re: How do I allow AI to trigger OnEnterRegion?

Post 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.
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: How do I allow AI to trigger OnEnterRegion?

Post by Marth8880 »

ahah of cause ^^
SkinnyODST
Lieutenant Colonel
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?

Post 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]
User avatar
AnthonyBF2
Sith
Sith
Posts: 1255
Joined: Wed Aug 21, 2013 3:55 pm
Projects :: PS2+PSP Overhaul

Re: How do I allow AI to trigger OnEnterRegion?

Post by AnthonyBF2 »

Try adding another end after end
SkinnyODST
Lieutenant Colonel
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?

Post by SkinnyODST »

Nope. Still says the same thing
User avatar
AnthonyBF2
Sith
Sith
Posts: 1255
Joined: Wed Aug 21, 2013 3:55 pm
Projects :: PS2+PSP Overhaul

Re: How do I allow AI to trigger OnEnterRegion?

Post by AnthonyBF2 »

Oh I think you posted some bit of text from this webpage. :P

Look closely at the beginning.
SkinnyODST
Lieutenant Colonel
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?

Post 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?
User avatar
AnthonyBF2
Sith
Sith
Posts: 1255
Joined: Wed Aug 21, 2013 3:55 pm
Projects :: PS2+PSP Overhaul

Re: How do I allow AI to trigger OnEnterRegion?

Post by AnthonyBF2 »

Take off the other end I said to add earlier.
SkinnyODST
Lieutenant Colonel
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?

Post by SkinnyODST »

Nope.

Code: Select all

   EnableSPHeroRules()

 OnEnterRegion(
    function(region, character)
   if GetCharacterTeam(character) == "REP" then
        Aumbush("ambushregion", "ambushpath", 8, 5)
    end,
 "ambushregion"
 )
    
 end
User avatar
Teancum
Jedi Admin
Jedi Admin
Posts: 11080
Joined: Wed Sep 07, 2005 11:42 pm
Projects :: No Mod project currently.
Games I'm Playing :: Destiny
xbox live or psn: No gamertag set
Location: Indiana

Re: How do I allow AI to trigger OnEnterRegion?

Post 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
SkinnyODST
Lieutenant Colonel
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?

Post 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.
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: How do I allow AI to trigger OnEnterRegion?

Post by Marth8880 »

DeactivateRegion("regionname") should do it.
Post Reply