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:

Re: How do I allow AI to trigger OnEnterRegion?

Post by SkinnyODST »

Marth8880 wrote:DeactivateRegion("regionname") should do it.
Ok so how what do I write to make it work? OnCPCapture?
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:OnCPCapture?
Almost correct.

Let's play another game. See if you can find the right one in this document: https://sites.google.com/site/swbf2modt ... ing_system
User avatar
commanderawesome
Field Commander
Field Commander
Posts: 971
Joined: Tue Aug 13, 2013 11:58 pm
Projects :: Skin Changer - Warfront - Other stuff
Games I'm Playing :: SWBF SWTOR KotOR EaW
xbox live or psn: AaTc_CmdrAwesome
Location: The Universe

Re: How do I allow AI to trigger OnEnterRegion?

Post by commanderawesome »

I think I see the problem regarding the original issue and Skinny's script. This:
SkinnyODST wrote:

Code: Select all

if IsCharacterHuman (character) then
Should be:

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
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 »

^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
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 »

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.
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 »

REP isn't a string though, it's very much an integer.
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:REP isn't a string though, it's very much an integer.
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. :cpu:
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 »

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
Nope, I`ve also tried it with 1 "end", still shows errors.


EDIT: I put this code in my LUA -
Hidden/Spoiler:
[code]
OnFinishCaptureTeam(CaptureTeam1, 1) KillObject("cp4")[/code]
The idea was that when the Republic captures cp3, cp4 will disappear, but cp4 disappears at the start of the game anyway? I don`t know how to set this out, I read that documentation on this code stuff and it didn`t tell me how to do this.
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:

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
Nope, I`ve also tried it with 1 "end", still shows errors.
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.

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
end
You'd place that code *after* (not inside) ScriptPostLoad.

Alternatively, 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
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 still doesn`t work for me, are you sure it`s even possible to do this? Everything I`ve tried so far causes errors.
Hidden/Spoiler:
[code]

OnEnterRegion(
function(region, character)
if not GetCharacterTeam(character) and GetCharacterTeam(character) == REP then
Aumbush("ambushregion", "ambushpath", 8, 5)
end,
"ambushregion"
)
end[/code]
Anyway, that

Code: Select all

OnFinishCaptureTeam(
    function(post)
        KillObject("cp4")
    end,
 REP
 )
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"?
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: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.
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.



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"
)
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"?
Sure. Use GetEntityName with `post` as the argument (passed as the parameter from OnEnterRegion) like so:

Code: Select all

OnFinishCaptureTeam(
    function(post)
        if GetEntityName(post) == "cpname" then
            KillObject("cp4")
        end
    end,
REP
)
Post Reply