Page 1 of 1

LUA Help with Timers for new Gamemode [Solved]

Posted: Sat Jan 16, 2021 2:01 pm
by Benoz
Hello Gametoast, I have a problem with some LUA code and maybe you can help.

MY GOAL:
I want to setup a new gamemode where both teams have to capture the middle command post which is an ion cannon. If one team holds it for 60 seconds, the ion cannon is ready to fire and shoots at the enemy ship dropping its shields. Then the succeeding team has 30 seconds to attack the enemy ship until its shields are back up and the battle for the ion cannon (middle command post) begins anew.

EXECUTION:
I'm quite confident in setting up the mechanics and I thought everything through. But I'm still a newby at Lua scripting. So here's what I've got so far:

Code: Select all

	-- create the timer for the cap time for team 1
	CreateTimer("Team1CapControl")
	SetTimerValue("Team1CapControl",60)
	
	-- create the timer for the cap time for team 2
	CreateTimer("Team2CapControl")
	SetTimerValue("Team2CapControl",60)
	
	OnFinishCaptureTeam( --TEAM 1 CAPTURE TIMER START
		function(cp3)
		local pName = GetEntityName(cp3)
		
		-- start the timer
		ShowTimer(nil)
		ShowTimer("Team1CapControl")
		StartTimer("Team1CapControl")
		
		-- update AI goals
		ClearAIGoals(1)
		ClearAIGoals(2)
		AddAIGoal(1, "Deathmatch", 50)
		AddAIGoal(1, "Defend", 50, "cp_control")
		AddAIGoal(2, "Conquest", 100)
		
		end,
		1
	)
	
	OnTimerElapse( --TEAM 1 CAPTURE TIMER FUNCTION
		function(timer)

		-- make cp_control non capturable during that time
		SetProperty (cp3, "CaptureRegion", "")
		
		-- start the timer
		ShowTimer(nil)
		CreateTimer("Team1Attack")
		SetTimerValue("Team1Attack",5)
		ShowTimer("Team1Attack")
		StartTimer("Team1Attack")
		
		-- destroy the capControl timer for both teams
		DestroyTimer("Team1CapControl")
		DestroyTimer("Team2CapControl")
		
		end,
		"Team1CapControl"
    ) 
	
	OnTimerElapse( --TEAM 1 ATTACK TIMER FUNCTION
		function(timer)
		
		-- make cp_control neutral and capturable again
		SetProperty (cp3, "Team", 0)
		SetProperty (cp3, "CaptureRegion", "cp3_capture")
		
		-- reset the capControl timers for both teams
		ShowTimer(nil)
		CreateTimer("Team1CapControl")
		SetTimerValue("Team1CapControl",60)
		CreateTimer("Team2CapControl")
		SetTimerValue("Team2CapControl",60)
		
		-- destroy the Attack timer for both teams
		DestroyTimer("Team1Attack")
		DestroyTimer("Team2Attack")
		
		end,
		"Team1Attack"
    )
	
	OnFinishNeutralizeTeam( --TEAM 1 NEUTRALIZE CAPTURE FUNCTION
		function(cp3)
		local pName = GetEntityName(cp3) -- Gets the name of the post that was captured

		-- stop the capControl timer for both teams and destroy Attack timers
		ShowTimer(nil)
		StopTimer("Team1CapControl")
		StopTimer("Team2CapControl")
		
		-- update AI goals
		ClearAIGoals(1)
		ClearAIGoals(2)
		AddAIGoal(1, "Conquest", 100)
		AddAIGoal(2, "Conquest", 100)
		
		end,
		1
	)
EXPLANATION:
The above code sets up a timer for each team. Once the middle CP is captured by team 1, the timer Team1CapControl starts. If the enemy team manages to neutralize the CP, the timer stops and when the enemy captures the point, the timer Team2CapControl starts. Once the CapControl timer runs out, it's starting a new timer Team1Attack in which time the shield of the enemy ship is down. During this time the command post is not capturable anymore SetProperty (cp3, "CaptureRegion", "") and the succeeding team can attack the enemy ship. When Team1Attack runs out, the middle command post is being set to neutral SetProperty (cp3, "Team", 0) and can be captured again. The CapControl timers will be created new. I will use the same code for the other team. All the above code is in the ScriptPostLoad() function.

PROBLEM:
When I test the code ingame, everything works fine upon the point when the Team1Attack timer runs out. It does neither hide nor trigger the middle command post to be neutral again. It just stops at '0:00' at the clock. The middle CP remains captured by the succeeding team and the process can not begin from new. Is there something wrong in my code that doesn't make the OnTimerElapse(Team1Attack) trigger? Or is there something completely different wrong with my logic?

Thanks i advance for your feedback and help.

Re: LUA Help with Timers for new Gamemode

Posted: Sat Jan 16, 2021 3:18 pm
by Marth8880
Looks like you're referencing cp3 incorrectly. You need to reference it by its object name in ZE. The way you're referencing it currently is by the 'cp3' variable, which is a table containing some basic information about it - aka an incorrect argument for SetProperty.

Re: LUA Help with Timers for new Gamemode

Posted: Sat Jan 16, 2021 5:42 pm
by Benoz
Marth8880 wrote:
Sat Jan 16, 2021 3:18 pm
Looks like you're referencing cp3 incorrectly. You need to reference it by its object name in ZE. The way you're referencing it currently is by the 'cp3' variable, which is a table containing some basic information about it - aka an incorrect argument for SetProperty.
Thanks Marth, that did the trick with the ability to capture the post. After some rearranging of the code it works like charm.