Team:DeclareWar(Team) causing crashes.

Neirai

the Forgiven
Joined
Aug 5, 2013
Messages
1,049
Location
Canada
Hey, all. For an upcoming mod, I'm trying to cause CityState Teams to declare wars on players.

I'm using the following code:

Code:
local pTarget = Players[v.CivilizationID]
	print(pTarget)
	if pTarget:IsEverAlive() then
		print("pTarget is Alive")
		if pPlotOwner:IsEverAlive() then
			print("pPlotOwner is Alive")
			pPopupUnit:SetDamage(999)
			print("I killed the unit.")
			LuaEvents.GreatPersonExpended(activePlayer:GetID(), iMidew)
			print("A Great Person was Expended")
			if not Teams[pPlotOwner:GetTeam()]:IsHasMet(pTarget:GetTeam()) then
				print("The City State has not met the target.")
				Teams[pPlotOwner:GetTeam()]:Meet(pTarget:GetTeam(), true)
				print("Introductions facilitated.")
			end
			Teams[pPlotOwner:GetTeam()]:DeclareWar(pTarget:GetTeam())
			print("A Declaration of War!")
			print("Our work here is done.")
		end
	end

The problem is that it causes a crash about 50% of the time. It crashes on the Teams[pPlotOwner:GetTeam()]:DeclareWar(pTarget:GetTeam()) line.

Any ideas about why this would be?
Edit: this is code within other code.
 
If the source of target player are dead, that might crash. I only bring it up because you're using IsEverAlive() which returns true if that player was ever in the game. IsAlive() only returns true if the player is still alive now.

Also, you don't need to do the "meet" manually - declaring war between two players causes them to meet each other.
 
After the changes, I'm still getting crashes happening at that line. I'm hoping I'm missing something, since I really hope it's not Team:DeclareWar() that is the problem.
 
Back
Top Bottom