+1 Movement for the AI?

You mean only during Golden Ages, right?

Giving it to everyone would be easy with this SQL (including modded civs that are loaded before your mod):
Code:
UPDATE Traits SET GoldenAgeMoveChange = 1;

You could do that, and then take away the extra turn from the human player's units, but I'm not sure if that would make it appear like every unit had already moved that turn. So, since we've got to use Lua anyway, let's do the whole thing in Lua instead:
Code:
for iPlayer = 1, GameDefines.MAX_MAJOR_CIVS do
    local player = Players[iPlayer]
    if (player:GetGoldenAgeTurns() > 0) then
        for unit in player:Units() do
            unit:SetMoves(unit:GetMoves() + 1)
        end
    end
end
 
You mean only during Golden Ages, right?

Giving it to everyone would be easy with this SQL (including modded civs that are loaded before your mod):
Code:
UPDATE Traits SET GoldenAgeMoveChange = 1;

You could do that, and then take away the extra turn from the human player's units, but I'm not sure if that would make it appear like every unit had already moved that turn. So, since we've got to use Lua anyway, let's do the whole thing in Lua instead:
Code:
for iPlayer = 1, GameDefines.MAX_MAJOR_CIVS do
    local player = Players[iPlayer]
    if (player:GetGoldenAgeTurns() > 0) then
        for unit in player:Units() do
            unit:SetMoves(unit:GetMoves() + 1)
        end
    end
end
Thanks. I don't mean just during golden ages. The combat AI has serious difficulty with maneuvering. I'm not a fan of the AI bonuses of Immortal and Deity, as I feel they sort of force the player to play a very limited game in order to compete. I can do it on Immortal (haven't tried deity), but I don't enjoy it as much; so I play on emperor with the Buffed AI mod ( http://forums.civfanatics.com/showthread.php?t=504220). This mod makes emperor about as difficult as immortal, but in a more interesting way.

I'd like to experiment with giving the all the AIs the Persian Golden Age bonus to movement by default. I'm hoping this bonus of +1 to movement could be a way to "level the playing field" between the player and the AI.

also: the only modding I've ever done has been with xml files. Is lua much more difficult? Thanks in advance.
 
The Golden Age bonus only applies... during golden ages, so referring to the Persian trait doesn't really help you.

Assuming you don't want this to apply to city states and barbarians, just add a new Lua file to your mod, copy in the following:
Code:
Events.ActivePlayerTurnStart.Add(
function()
    for iPlayer = 1, GameDefines.MAX_MAJOR_CIVS do
        local player = Players[iPlayer]
        if player:IsAlive() then
            for unit in player:Units() do
                unit:SetMoves(unit:GetMoves() + 1)
            end
        end
    end
end)

Then add your new Lua file to Content:InGameUIAddin

Note, I haven't actually tested this, but I'm pretty sure it should work.


EDIT: If you want to include city states, change
Code:
GameDefines.MAX_MAJOR_CIVS
to
Code:
GameDefines.MAX_CIV_PLAYERS - 1
or if you also want to include barbarians, you can instead just use
Code:
GameDefines.MAX_CIV_PLAYERS
 
So how about lua that detects if a unit belongs to the AI (by not being a human) and Persia?
Code:
for iPlayer = 1, GameDefines.MAX_MAJOR_CIVS do
    local player = Players[iPlayer]
    if not (player:IsHuman()) then
	if (player:GetCivilizationType() == GameInfoTypes.CIVILIZATION_PERSIA) then
        	for unit in player:Units() do
           		 unit:SetMoves(unit:GetMoves() + 1)
		end
        end
    end
end
Although wouldn't this give it another extra move each turn (so it stacks)?

So it would be better to give the unit a promotion.
Code:
for iPlayer = 1, GameDefines.MAX_MAJOR_CIVS do
    local player = Players[iPlayer]
    if not (player:IsHuman()) then
	if (player:GetCivilizationType() == GameInfoTypes.CIVILIZATION_PERSIA) then
        	for unit in player:Units() do
           		unit:SetHasPromotion(GameInfoTypes.PROMOTION_EXTRA_MOVE_PERSIA, true)
		end
        end
    end
end
Code:
<GameData>
	<UnitPromotions>
		<Row>
			<Type>PROMOTION_EXTRA_MOVE_PERSIA</Type>
			<Description>TXT_KEY_PROMOTION_EXTRA_MOVE_PERSIA</Description>
			<Help>TXT_KEY_PROMOTION_EXTRA_MOVE_PERSIA_HELP</Help>
			<Sound>AS2D_IF_LEVELUP</Sound>
			<CannotBeChosen>true</CannotBeChosen>
			<MovesChange>1</MovesChange>
			<PortraitIndex>59</PortraitIndex>
			<IconAtlas>ABILITY_ATLAS</IconAtlas>
			<PediaType>PEDIA_ATTRIBUTES</PediaType>
			<PediaEntry>TXT_KEY_PROMOTION_EXTRA_MOVE_PERSIA</PediaEntry>
		</Row>
	</UnitPromotions>
</GameData>
 
So how about lua that detects if a unit belongs to the AI (by not being a human) and Persia?
My reading of the request was that it had nothing to do with Persia, he just thought since that trait existed, he could apply it somehow outside of the context of golden ages, and only to AI players.

Code:
for iPlayer = 1, GameDefines.MAX_MAJOR_CIVS do
    ...
        if not (player:IsHuman()) then
If you start your loop at 1-index, you'll never hit the human player (well... unless he's trying to mod multiplayer)

Although wouldn't this give it another extra move each turn (so it stacks)?
If you mean by "stacks," would it give their units additional turns for each player that's come before (i.e., additional turns equal to iPlayer), then that would be true if you were hooking the wrong event, e.g., GameEvents.PlayerDoTurn() and then still looping through all players instead of using the playerID parameter with that GameEvent. My method uses Events.ActivePlayerTurnStart and so it only applies once at the start of the game turn (i.e., before player 0's turn).

If, OTOH, you mean by "stacks," would a unit that doesn't move that turn keep getting extra turns that could be used later, then the answer is no.

EDIT: It's possible that my method doesn't work if the unit turns are reset between each player rather than between each game turn, in which case you would have to switch it to PlayerDoTurn(), and use the playerID parameter as I mention above rather than looping through all players, then just take out the city states and/or barbs, as desired.
 
Thanks very much. I don't know much about modding CiV (only xml, so far). I mentioned Persia specifically only because their plus one to movement ability made me think that modding it in for all the AIs was possible (I could have also mentioned England for their movement bonus for ships).

I'm going to implement these changes and see how they work later tonight. Before I do, just one question: as I mentioned before, my CiV modding experience is very limited. All I've ever done is open xml files with notepad, make changes and save. Is there anything I should know about how to mod lua files? How is it different from modding xml files? Thanks again.
 
Before I do, just one question: as I mentioned before, my CiV modding experience is very limited. All I've ever done is open xml files with notepad, make changes and save. Is there anything I should know about how to mod lua files? How is it different from modding xml files?
This isn't really the kind of code that you can just edit into an existing file, as the file you edit it into is likely using the wrong event hook. If the last half of that last sentence made no sense, just know that with this code it would be better to use ModBuddy an add a lua file.

Lua and XML files are added to the database in two very different ways and they're designed to do very different things. XML makes things exist and Lua makes those existing things do stuff. (3 cheers for being specific :p)

And obviously, as you've already seen, they have very different syntaxes. This is how I prefer to explain the difference between the syntaxes of Lua, XML and SQL:
Spoiler :
Code:
----------[ Lua ]----------

Life.Explanations.Add(
function LuaExample(parantheses)
	local parantheses = Parameters.GetVeryOverusedPunctuation()
	local isLua = { }
	if (Code:GetNumPunctuation(parantheses) >= many) then
		isLua = true
		print('This is indeed a Lua script.')
	elseif (Code:GetNumPunctuation(parantheses) < many)
		isLua = false
		print('This is not a lua script.')
	else
		print('you are doing something wrong...')
		break
	end
end)
		
----------[ XML ]----------

<Life>
   <Table name="Explanations">
      <Column name="ID" autoincrement="true" primarykey="true" type="integer"/>
      <Column name="Type" type="text" unique="true" notnull="true"/>
      <Column name="Description" type="text"/>
      <Column name="Parameters" type="text" reference="Parameters(Type)"/>
      <Column name="Useful" type="boolean" default="false"/>
      <Column name="IsCode" type="boolean" default="false"/>
      <Column name="IsScript" type="boolean" default="false"/>
   </Table>
   <Explanations>
      <Row>
         <ID>0</ID>
         <Type>EXPLANATION_XML</Explanation>
         <Description>eXtensible Markup Language</Description>
         <Parameters>PARAMETERSET_GREATERTHANSYMBOL_LESSTHANSYMBOL_UNDERSCORE</Parameters>
	 <Useful>false</Useful>
	 <IsCode>true</IsCode>
	 <IsScript>false</IsScript>
      </Row>
   </Explanations>
</Life>

----------[ SQL ]----------

WHERE TABLE = 'Life' (
	IF EXISTS NOT IN Explanations WHERE Type = 'EXPLANATION_SQL' THEN
		INSERT INTO Explanations
		VALUES ('EXPLANATION_SQL', 'Structured Query Language', 'PARAMETERSET_KEYWORDS_CAPITALLETTERS', '1', '1', '1'));
 
This isn't really the kind of code that you can just edit into an existing file, as the file you edit it into is likely using the wrong event hook. If the last half of that last sentence made no sense, just know that with this code it would be better to use ModBuddy an add a lua file.

Lua and XML files are added to the database in two very different ways and they're designed to do very different things. XML makes things exist and Lua makes those existing things do stuff. (3 cheers for being specific :p)

And obviously, as you've already seen, they have very different syntaxes. This is how I prefer to explain the difference between the syntaxes of Lua, XML and SQL:
Spoiler :
Code:
----------[ Lua ]----------

Life.Explanations.Add(
function LuaExample(parantheses)
	local parantheses = Parameters.GetVeryOverusedPunctuation()
	local isLua = { }
	if (Code:GetNumPunctuation(parantheses) >= many) then
		isLua = true
		print('This is indeed a Lua script.')
	elseif (Code:GetNumPunctuation(parantheses) < many)
		isLua = false
		print('This is not a lua script.')
	else
		print('you are doing something wrong...')
		break
	end
end)
		
----------[ XML ]----------

<Life>
   <Table name="Explanations">
      <Column name="ID" autoincrement="true" primarykey="true" type="integer"/>
      <Column name="Type" type="text" unique="true" notnull="true"/>
      <Column name="Description" type="text"/>
      <Column name="Parameters" type="text" reference="Parameters(Type)"/>
      <Column name="Useful" type="boolean" default="false"/>
      <Column name="IsCode" type="boolean" default="false"/>
      <Column name="IsScript" type="boolean" default="false"/>
   </Table>
   <Explanations>
      <Row>
         <ID>0</ID>
         <Type>EXPLANATION_XML</Explanation>
         <Description>eXtensible Markup Language</Description>
         <Parameters>PARAMETERSET_GREATERTHANSYMBOL_LESSTHANSYMBOL_UNDERSCORE</Parameters>
	 <Useful>false</Useful>
	 <IsCode>true</IsCode>
	 <IsScript>false</IsScript>
      </Row>
   </Explanations>
</Life>

----------[ SQL ]----------

WHERE TABLE = 'Life' (
	IF EXISTS NOT IN Explanations WHERE Type = 'EXPLANATION_SQL' THEN
		INSERT INTO Explanations
		VALUES ('EXPLANATION_SQL', 'Structured Query Language', 'PARAMETERSET_KEYWORDS_CAPITALLETTERS', '1', '1', '1'));
Thanks. This is all new to me, but I'm beginning to understand -at least somewhat. Is ModBuddy a modding tool? Do I download it like I would a mod?

Once I began using ModBuddy, how do I create a new lua file? Thanks in advance.
 
ModBuddy is a tool that you access via Steam just like Civ5 that should IINM come free with Civ5 when you buy it. But whereas on steam to play Civ5 you go Library > My Games, for ModBuddy you go Library > Tools and find something called "Sid Meier's Civilization V SDK". Double-click to download it. (I'm a little hazy on how to install it since that was a while ago.)

Fire up SDK and you have a choice of multiple programs to run: Firetuner, ModBuddy, WorldBuilder and Nexus. ModBuddy is the one where you actually make mods, so open that one. You want to create a new project and once you've done that a new file - which lua file is a choice for.
 
ModBuddy is a tool that you access via Steam just like Civ5 that should IINM come free with Civ5 when you buy it. But whereas on steam to play Civ5 you go Library > My Games, for ModBuddy you go Library > Tools and find something called "Sid Meier's Civilization V SDK". Double-click to download it. (I'm a little hazy on how to install it since that was a while ago.)

Fire up SDK and you have a choice of multiple programs to run: Firetuner, ModBuddy, WorldBuilder and Nexus. ModBuddy is the one where you actually make mods, so open that one. You want to create a new project and once you've done that a new file - which lua file is a choice for.
Thanks for the step-by-step instructions; exactly what I needed. I'm going to try it tonight.

I'm really hoping this +1 to movement gives the AI the combat boost it so desperately needs. We'll see. Thanks again.
 
ModBuddy is a tool that you access via Steam just like Civ5 that should IINM come free with Civ5 when you buy it. But whereas on steam to play Civ5 you go Library > My Games, for ModBuddy you go Library > Tools and find something called "Sid Meier's Civilization V SDK". Double-click to download it. (I'm a little hazy on how to install it since that was a while ago.)

Fire up SDK and you have a choice of multiple programs to run: Firetuner, ModBuddy, WorldBuilder and Nexus. ModBuddy is the one where you actually make mods, so open that one. You want to create a new project and once you've done that a new file - which lua file is a choice for.
I've done everything so far, but I can't seem to do the final step of uploading my Mod package to Steam workshop. It says the file doesn't exist, but it does.

Thanks in advance.

edit: managed to upload it. Thanks again for all your help. I just subscribed to it and now I'm going to go test it.
 
Again, I don't entirely remember the process of downloading a program from a long time ago, and since I already have it downloaded I can't replicate the problem without uninstalling it. Sorry. I would be looking up something along the lines of "how to install Civ5 SDK".

What I forgot to mention earlier: To run Civ5 SDK you need to have Microsoft Visual Studio Isolated Distributable 2010.
 
I've done everything so far, but I can't seem to do the final step of uploading my Mod package to Steam workshop. It says the file doesn't exist, but it does.

Thanks in advance.

edit: managed to upload it. Thanks again for all your help. I just subscribed to it and now I'm going to go test it.

Well done! Though you don't need to upload it to the Workshop just to test it. As soon as you Build it, it will automatically be copied to your Mods folder, and can then be enabled from the Mods menu ingame.
 
Again, I don't entirely remember the process of downloading a program from a long time ago, and since I already have it downloaded I can't replicate the problem without uninstalling it. Sorry. I would be looking up something along the lines of "how to install Civ5 SDK".

What I forgot to mention earlier: To run Civ5 SDK you need to have Microsoft Visual Studio Isolated Distributable 2010.
I had no problem downloading the SDK and creating the lua file. My problem was uploading it to Steam workshop. but after tinkering with it for a while, I finally figured it out and then I subscribed to the mod. It's simply called +1 movement for all AI units.

but now I've loaded my game and when I attempt to attack enemy units, it still says that they have 2 movement points -not 3, as they should if all AI units have an additional movement point. I saw that the saved game compatible box was checked when I made the mod.

So I'm not sure if the new lua file is working.
 
As I mentioned in post #6, you may have to change the Event you're hooking to GameEvents.PlayerDoTurn(), but it would change the code somewhat:
Code:
GameEvents.PlayerDoTurn.Add(
function(iPlayer)
    local player = Players[iPlayer]
    if player:IsAlive() then
        for unit in player:Units() do
            unit:SetMoves(unit:GetMoves() + 1)
        end
    end
end)
However, this would apply to city states and barbarians unless further edits are made. You haven't mentioned your preference as to this.
 
Well done! Though you don't need to upload it to the Workshop just to test it. As soon as you Build it, it will automatically be copied to your Mods folder, and can then be enabled from the Mods menu ingame.
Thanks. I've loaded my game and when I attempt to attack enemy units, it still says that they have 2 movement points -not 3, as they should if all AI units have an additional movement point. I saw that the saved game compatible box was checked when I made the mod.

So I'm not sure if the new lua file is working.

the only text I copied to a lua file was:

Events.ActivePlayerTurnStart.Add(
function()
for iPlayer = 1, GameDefines.MAX_MAJOR_CIVS do
local player = Players[iPlayer]
if player:IsAlive() then
for unit in player:Units() do
unit:SetMoves(unit:GetMoves() + 1)
end
end
end
end)



and then the city-state change:



GameDefines.MAX_MAJOR_CIVS to

Code:
GameDefines.MAX_CIV_PLAYERS - 1


my preference is to also give the +1 movement to city-states, but not to barbarians. Thanks again for taking the time to help me.
 
OK, so a just no barbs version would be:
Code:
GameEvents.PlayerDoTurn.Add(
function(iPlayer)
    local player = Players[iPlayer]
    if player:IsAlive() and not player:IsBarbarian() then
        for unit in player:Units() do
            unit:SetMoves(unit:GetMoves() + 1)
        end
    end
end)
 
OK, so a just no barbs version would be:
Code:
GameEvents.PlayerDoTurn.Add(
function(iPlayer)
    local player = Players[iPlayer]
    if player:IsAlive() and not player:IsBarbarian() then
        for unit in player:Units() do
            unit:SetMoves(unit:GetMoves() + 1)
        end
    end
end)
I just edited the lua script by replacing it with this and I'm going to test in now. will let you know. Thanks again!
 
OK, so a just no barbs version would be:
Code:
GameEvents.PlayerDoTurn.Add(
function(iPlayer)
    local player = Players[iPlayer]
    if player:IsAlive() and not player:IsBarbarian() then
        for unit in player:Units() do
            unit:SetMoves(unit:GetMoves() + 1)
        end
    end
end)
When I attempt to attack enemy ground units, it still says that they have 2 movement points -not 3. Is it possible that the mod is working and that it just says that the AI land units have 2 movement points, while they actually have 3 (+1 to their default 2)?

Thanks in advance.
 
Back
Top Bottom