Page 1 of 1

PlayerEnterVehicle Event, filters? (4th Post)

Posted: Fri Jul 06, 2007 4:45 pm
by Ace_Azzameen_5
I'm trying to add a filter to the FinishCapture event, so that the functions are executed whenever CP3cam is captured.

My code is below

Code: Select all

OnFinishCapture( --If this CIS captures CP 3
function(post)
if GetObjectTeam("cp3cam") == 2 then
CP3CIS = 1
SetProperty("cp3cam", "SpawnPath", "cp3_spawn")
ShowMessageText("level.ace.campaigncw.objectives.CP3Lost", REP)
end
end,
"cp3cam"
)
However, the filter is being completely ignored, and whenever a CP is captured and the IF statement satisfied, the functions are executed.

Whenever any CP is captured and the CP3cam belongs to the CIS the message appears and the other stuff presumably happens.

TY in advanced.

Posted: Fri Jul 06, 2007 8:52 pm
by Abiter_b
i think this is the code u need for the start,

Code: Select all

OnFinishCaptureName(post, "cp3cam");

hope this helps, Abiter

Posted: Sun Jul 08, 2007 9:39 pm
by Ace_Azzameen_5
That didn't work, because I couldn't include code after that statement - both "OnFinishCaptureName(post, "cp3cam"); - function(post) - code - end" and just "OnFinishCaptureName(post, "cp3cam"); - code - end" produced errors.

Code: Select all

OnFinishCaptureName(function3, "cp3cam"); 
function function3
CODE
end
just didn't work
and

Code: Select all

OnFinishCaptureName(CP3Capt(), "cp3cam"); 

CP3Capt = function()
CODE
end
resulted in an in-game "Attempt to call a global function failed" error in the log as well as breaking the script.

Now I have headache.

Posted: Sun Jul 08, 2007 11:45 pm
by [RDH]Zerted
There is no difference between

Code: Select all

OnFinishCaptureName( function(post) end, "filter value" )
and

Code: Select all

functionToCall = function(post) end
OnFinishCaptureName( functionToCall, "filter value" )
All it does is allows you to restructure your code so its easier to read. Which way is esaier to read depends completely on the person reading it.

However, Abiter_b is correct in that you are missing OnFinishCaptureName. When you provide a filter, you need to let the game know what the filter represents (name, team, etc...).

Both of the following code segments should work. I changed your code slightly to use GetCommandPostTeam() compared to GetObjectTeam(). I think I remember reading something, somewhere about the less general functions being more optimized.

Code: Select all

	OnFinishCaptureName( --If this CIS captures CP 3 
		function(post, holding) 

			--if the CP was not captured by team 2, do nothing
			if GetCommandPostTeam(post) ~= 2 then
				return
			end
			
			CP3CIS = 1 
			SetProperty("cp3cam", "SpawnPath", "cp3_spawn") 
			ShowMessageText("level.ace.campaigncw.objectives.CP3Lost", REP) 
		end, "cp3cam" 
	)

Code: Select all

	cp3Lost = function(post, holding)
			--if the CP was not captured by team 2, do nothing
			if GetCommandPostTeam(post) ~= 2 then
				return
			end
			
			CP3CIS = 1 
			SetProperty("cp3cam", "SpawnPath", "cp3_spawn") 
			ShowMessageText("level.ace.campaigncw.objectives.CP3Lost", REP) 
		end
	OnFinishCaptureName( cp3Lost, "cp3cam" )

Posted: Tue Jul 10, 2007 10:29 am
by Ace_Azzameen_5
[RDH]Zerted wrote:However, Abiter_b is correct in that you are missing OnFinishCaptureName. When you provide a filter, you need to let the game know what the filter represents (name, team, etc...).
:oops: GAHH! Thanks, Zert. And ty for the optimization info.

can you tell me why this is a silent failure?

Code: Select all

--When the player enters the Relocation Gunship, if the Mall has been locked down, begin the relocation sequence
--if the mall hasn't, inform the player that the area is still not secured
OnCharacterEnterVehicleName( 
function(turret, player)
if IsCharacterHuman(player) then
if GetObjectTeam("con") == 1 then
ArcInFlightMessageSequence()
SetObjectTeam("mtttur1", 2)
SetObjectTeam("mtttur", 2)
AddReinforcements(1, 50)
StartTimer("Gun_Fly1")
end
if GetObjectTeam("con") ~= 1 then
ShowMessageText("level.ace.campaigncw.objectives.AreaNotYetSecure", REP)
end
end-- of is Character Human
end,
"rep_prop_gunship"
)

Posted: Wed Jul 11, 2007 4:28 am
by [RDH]Zerted
Toss in

Code: Select all

print("<code location description here>")
before and inside each of your if statements. Run the map, then check the error log. This will show you what parts of the code are getting execuited.

WTF? I pressed Preview and it took me to http://www.gametoast.com/index.php and again and again. Hopefully Submit works...

Edit: Submit took me to the main page too. Reloading the topic showed my post.

Posted: Wed Jul 11, 2007 8:43 am
by Ace_Azzameen_5
lol @ post wierdness.

This outputs to the bf2log, right? I just realized that the first if statement has no message output, (just a call to a method which has one, but the call could be broken) I guess this will be useful, but when either statement should be satisfied I get nothing.

I think that that I an using non-existent filters (I tried vehicle, and just player, too) as the docs don't name any. I suppose I could place a region in the turrets and use enterregion, since the turret is a set of LAAT balls.

*Edit* Since none of the Prints inside of the event were ever output, and the one just before it was, its safe to say the event itself is broken.

Posted: Wed Jul 11, 2007 6:52 pm
by [RDH]Zerted
If the filter isn't in the docs, you can assume it doesn't exist. Remove your filter and the event callback should work.

Posted: Wed Jul 11, 2007 7:37 pm
by Ace_Azzameen_5
Sorry, I misread the Docs, the filter is probably working, its just the event. From the above experience, I know that events can function with Mis-filters, they just ignore them.

Posted: Tue Jul 17, 2007 3:06 pm
by Ace_Azzameen_5
Is it possible that the fact the turret has been animated to a new position and the animation is paused and not stopped cause the EnterVehicle to not function?

If its possible I could re-write my code so the object is animated twice, or pull a killobject/respawn new object trick.

I also tried renaming the object and changing the script accordingly, copy and pasted spelling, and still the event won't trigger.

*Edit* As a test for name accuracy, I commented out the EnterVehicle and used an ObjectKill instead. Sabered the turret (its a gunship prop * with two turrets) up good, and the event triggered.

*Wait a minute, since this event works for vehicles and turrets, do I need to somehow reference the individual turret position?

Posted: Thu Jul 19, 2007 1:56 pm
by [RDH]Zerted
I'm not exactly sure what you are saying at some points, but I think it would be good to point out that your event call-back is wrong.
docs wrote:CharacterEnterVehicle: function (player, vehicle)
This event occurs whenever a character enters a vehicle. It also works for turrets!
You have turret and player backwards. It's OnCharacter, the character is first and the filter is applied against the character, not the vehicle/turret.

The docs say you can use a Name, Team, or Class filter.

Posted: Thu Jul 19, 2007 2:31 pm
by Ace_Azzameen_5
Ah, I didn't know that order mattered. Or notice that they were out of order.
Maybe I have bad debugging eyes.

Then again its only 10 out 805 lines that I have in ScriptPostLoad().
I don't have any custom functions outside of the main LUA though.