[LUA] Granting a Free Tech to every player

Drawmeus

Emperor
Joined
Jul 25, 2007
Messages
1,213
I'm trying to set up a wonder that gives a free tech to every civilization when built. I'm very comfortable with the XML portions of modding.

This is a Free Tech similar to the Great Library free tech - you get a popup that lets you choose one tech.

I've started by trying to set it up through the FireTuner lua console as a command. I've been testing by using the FireTuner feature allowing me to switch from player to player.

I can successfully grant a free tech to everyone, and give a notification if the player is human. I can't get the AI to actually spend its free tech. I assume I'm missing a call somewhere, but after some digging, I can't find anything that looks very promising.



The code I've been using is:

Code:
i = 0;
for i = 0, GameDefines.MAX_CIV_PLAYERS-1, 1 do
	if Players[i]:IsEverAlive()  then

		local pPlayer = Players[i];
		
		pPlayer:SetNumFreeTechs(pPlayer:GetNumFreeTechs() + 1);
		if (pPlayer:IsHuman()) then
			pPlayer:AddNotification(NotificationTypes.NOTIFICATION_FREE_TECH, "Choose Free Tech", "Free Tech");
		end		   
	end
	
	i = i + 1;
end

Anyone have any ideas? EDIT: Also, if you see that I'm doing something silly unrelated to my question, please point it out. I'm using this as an entry point to learn Lua and especially how Civ 5 uses it. I'm a competent scripter but not a programmer or anything.

EDIT2: Accidentally pasted an older version of the code. Fixed.
 
I've seen this too. The AI will never pick its free tech if you give it one. You have to pick a tech for each AI player and give it to them with team:SetHasTech(TechType index, bool newValue).
 
No way to just get them to pick?

Oh, well. I'm perfectly happy to do the workaround (another similar one would be granting them research equal to the cost of the tech they're currently working on), was just looking to see if there's a way to 'do it right'. As I mentioned I'm using this as a way to start learning the Civ 5 Lua implementation, so taking my time to do things the best way possible.

Thanks for the response.
 
No way to just get them to pick?

Oh, well. I'm perfectly happy to do the workaround (another similar one would be granting them research equal to the cost of the tech they're currently working on), was just looking to see if there's a way to 'do it right'. As I mentioned I'm using this as a way to start learning the Civ 5 Lua implementation, so taking my time to do things the best way possible.

Thanks for the response.

How about just pick one the same way a goody hut does?
 
You need to call CvPlayerAI::AI_chooseFreeTech to get the AI to pick their free tech, which I'm pretty sure you can't in LUA.

What you can do is have the wonder add a building in each players capital that gives them a free tech (and nothing else). This will trigger CvPlayer::processBuilding which in turn will call CvPlayerAI::AI_chooseFreeTech for the AI (and another function for the human).
 
Top Bottom