1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

[LUA] Granting a Free Tech to every player

Discussion in 'Civ5 - Creation & Customization' started by Drawmeus, Nov 1, 2012.

  1. Drawmeus

    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.
     
  2. Pazyryk

    Pazyryk Deity

    Joined:
    Jun 13, 2008
    Messages:
    3,584
    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).
     
  3. Drawmeus

    Drawmeus Emperor

    Joined:
    Jul 25, 2007
    Messages:
    1,213
    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.
     
  4. Irkalla

    Irkalla ENTP POWWWEEEEEER

    Joined:
    Sep 25, 2012
    Messages:
    1,009
    Location:
    Way down around Vicksburg
    How about just pick one the same way a goody hut does?
     
  5. snarko

    snarko DLLer

    Joined:
    Dec 9, 2003
    Messages:
    1,512
    Location:
    Sweden
    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).
     

Share This Page