Ok so how what do I write to make it work? OnCPCapture?Marth8880 wrote:DeactivateRegion("regionname") should do it.
How do I allow AI to trigger OnEnterRegion?
Moderator: Moderators
-
SkinnyODST
- 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?
-
Marth8880
- 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?
Almost correct.SkinnyODST wrote:OnCPCapture?
Let's play another game. See if you can find the right one in this document: https://sites.google.com/site/swbf2modt ... ing_system
- commanderawesome
- Field Commander

- Posts: 971
- Joined: Tue Aug 13, 2013 11:58 pm
- Projects :: Skin Changer - Warfront - Other stuff
- xbox live or psn: AaTc_CmdrAwesome
- Location: The Universe
Re: How do I allow AI to trigger OnEnterRegion?
I think I see the problem regarding the original issue and Skinny's script. This:
Should be:SkinnyODST wrote:Code: Select all
if IsCharacterHuman (character) then
Code: Select all
if not IsCharacterHuman(character) and GetCharacterTeam(character) == REP then-
Marth8880
- 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?
^That, and he also was not supposed to use the below code, which is from Ambush.lua and is called externally.
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
- 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?
Keep in mind text values like REP belong inside ""
Just a head's up to save you from more errors down the line. Only numeric values do not need "" in Lua.
Just a head's up to save you from more errors down the line. Only numeric values do not need "" in Lua.
-
Marth8880
- 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?
REP isn't a string though, it's very much an integer.
- 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?
My bad, I remember Zerted telling me something like that, I guess I took it the wrong way. In fact using "" on REP might be causing his crash issue.Marth8880 wrote:REP isn't a string though, it's very much an integer.
-
SkinnyODST
- 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?
Code: Select all
OnEnterRegion(
function(region, character)
if not GetCharacterTeam(character) and GetCharacterTeam(character) == REP then
Aumbush("ambushregion", "ambushpath", 8, 5)
end,
"ambushregion"
)
end
endEDIT: I put this code in my LUA -
Hidden/Spoiler:
-
Marth8880
- 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?
Almost correct! That if-statement needs to be closed, try putting a single end in a new line after Ambush is called. Also remove that stray end at the very bottom of the code you posted.SkinnyODST wrote:Nope, I`ve also tried it with 1 "end", still shows errors.Code: Select all
OnEnterRegion( function(region, character) if not GetCharacterTeam(character) and GetCharacterTeam(character) == REP then Aumbush("ambushregion", "ambushpath", 8, 5) end, "ambushregion" ) end end
Go ahead and read through this section of Programming In Lua for a better understanding on how to implement if-statements: https://www.lua.org/pil/4.3.1.html
As for OnFinishCaptureTeam, it needs to be registered properly as an event callback. Simply using OnFinishCaptureTeam(CaptureTeam1, REP) would make it execute a function called CaptureTeam1 whenever REP team captures a CP. If you want to do this, you'll need to register CaptureTeam1 as a function like so:
Code: Select all
function CaptureTeam1()
-- do stuff, this is where you'd put your KillObject call
endAlternatively, you'd register the event callback like so:
Code: Select all
OnFinishCaptureTeam(
function(post)
-- do stuff, this is where you'd put your KillObject call
end,
REP
)-
SkinnyODST
- 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 still doesn`t work for me, are you sure it`s even possible to do this? Everything I`ve tried so far causes errors.
Anyway, that thing WORKS! 1 further question, am I able to decide which CP triggers the event I put into it? Because right now with this code, if the Republic captures ANY CP, cp4 will go away, am I able to add in somewhere a certain CP that will trigger CP4 to be "killed"?
Hidden/Spoiler:
Code: Select all
OnFinishCaptureTeam(
function(post)
KillObject("cp4")
end,
REP
)-
Marth8880
- 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?
The core of my wave-based combat system for my Europa map relies on this very method, so yes, I am 200% positive that this works. You just don't seem to be very familiar with how logic and control structures work within programming, which is totally understandable, everyone starts out not knowing. What you need to do is *learn how these things work* though. Like, seriously, you'll get nowhere unless you do. We can't keep writing all your code for you.SkinnyODST wrote:This still doesn`t work for me, are you sure it`s even possible to do this? Everything I`ve tried so far causes errors.
With that said, here's the code I've corrected and written for you. :u
Code: Select all
OnEnterRegion(
function(region, character) -- this is a function
if not GetCharacterTeam(character) and GetCharacterTeam(character) == REP then -- this is an if-statement
Ambush("ambushregion", "ambushpath", 8, 5)
end -- this is what closes the if-statement
end, -- this is what closes the function
"ambushregion"
)Sure. Use GetEntityName with `post` as the argument (passed as the parameter from OnEnterRegion) like so:SkinnyODST wrote:am I able to decide which CP triggers the event I put into it? Because right now with this code, if the Republic captures ANY CP, cp4 will go away, am I able to add in somewhere a certain CP that will trigger CP4 to be "killed"?
Code: Select all
OnFinishCaptureTeam(
function(post)
if GetEntityName(post) == "cpname" then
KillObject("cp4")
end
end,
REP
)