Marshall Thomas
King
- Joined
- Dec 11, 2005
- Messages
- 700
What's the easiest way to give all the AIs the Persian ability of +1 movement? Thanks in advance.
UPDATE Traits SET GoldenAgeMoveChange = 1;
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.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
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)
GameDefines.MAX_MAJOR_CIVS
GameDefines.MAX_CIV_PLAYERS - 1
GameDefines.MAX_CIV_PLAYERS
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
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
<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>
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.So how about lua that detects if a unit belongs to the AI (by not being a human) and Persia?
If you start your loop at 1-index, you'll never hit the human player (well... unless he's trying to mod multiplayer)Code:for iPlayer = 1, GameDefines.MAX_MAJOR_CIVS do ... if not (player:IsHuman()) then
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).Although wouldn't this give it another extra move each turn (so it stacks)?
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.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?
----------[ 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?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)
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 for the step-by-step instructions; exactly what I needed. I'm going to try it tonight.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.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.
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.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.
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)
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.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.
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)?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)