Page 2 of 2

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Sat Dec 10, 2016 10:21 pm
by SkinnyODST
Marth8880 wrote:DeactivateRegion("regionname") should do it.
Ok so how what do I write to make it work? OnCPCapture?

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Sat Dec 10, 2016 10:31 pm
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

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Sat Dec 10, 2016 10:53 pm
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

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Sat Dec 10, 2016 10:56 pm
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

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Sat Dec 10, 2016 11:19 pm
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.

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Sun Dec 11, 2016 1:41 am
by Marth8880
REP isn't a string though, it's very much an integer.

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Sun Dec 11, 2016 1:42 am
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:

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Mon Dec 12, 2016 12:54 am
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.

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Mon Dec 12, 2016 2:20 pm
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
 )

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Tue Dec 13, 2016 4:27 am
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"?

Re: How do I allow AI to trigger OnEnterRegion?

Posted: Tue Dec 13, 2016 5:30 am
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
)