New trait: Free unit each 10th turn

Kritzo

Chieftain
Joined
Jan 20, 2014
Messages
13
How would you make this trait? The idea is that the civilization receives a specific unit free each x turn (x = 10 to begin with atleast)
I'm sure you would need some .lua scripts, but I don't know how to code in those yet, and I havn't been able to find a civ 5 oriented guide. I've done a course in java, at the university so I understand most of the commands, but I don't know how to make my own.

Could you make a integer that would counts up once each time you end your turn, and have a while loop that activates whenever this counter reaches 10, providing the free unit? If so, how would you make it in .lua?

Edit: I just noticed that in the "Civ5Traits" folder is a column:
<Column name="FreeUnit" type="text" reference="UnitClasses(Type)" default="NULL"/>
I havn't been able to find anything using that, for the example, but maybe I could? Or is it just the command for the free starting settler, etc?
 
I'm not sure how to solve your problem, but I can say that the trait is OP.
 
So far I have mixed this together, but all startup windows disappears the moment I select one of the two civilizations so far in my mod. This is all the code I currently have for the trait:


The XML:
Spoiler :

Code:
<Traits>
		<Row>
			<Type>TRAIT_THE_WATCH</Type>
			<Description>TXT_KEY_TRAIT_THE_WATCH</Description>
			<ShortDescription>TXT_KEY_TRAIT_THE_WATCH_SHORT</ShortDescription>
		</Row>
		<Update>
			<Where Type="TRAIT_THE_WATCH"/>
			<Set NightsWatch="true"
				 />
		</Update>
</Traits>


The SQL:
Spoiler :

Code:
DELETE FROM Language_EN_US WHERE Tag = 'TXT_KEY_TRAIT_THE_WATCH';
INSERT INTO Language_EN_US (Tag, Text, Gender, Plurality) VALUES ('TXT_KEY_TRAIT_THE_WATCH', 'Will recieve a upkeep free unit called Night's Watch ranger, every 10th turn.', '', '');

ALTER TABLE Traits ADD NightsWatch boolean;

);


The LUA:
Spoiler :

Code:
function PlayerStartBonuses(player)
	local trait
	local leaderType
	local traitType
	
	print ("PlayerStartBonuses")

	for PlayerID, player in pairs(Players) do

		if player and player:IsEverAlive() and not player:IsBarbarian() and not player:IsMinorCiv() then

			leaderType = GameInfo.Leaders[GetLeaderType()].Type
			traitType = GameInfo.Leader_Traits("LeaderType ='" .. leaderType .. "'")().TraitType
			trait = GameInfo.Traits[traitType]

			if trait and trait.NightsWatch then
				while (Game.GetGameTurn() % 10 == 0) do
					addFreeUnit(GameInfo.Units.UNIT_NIGHTS_WATCH.ID);
				end
			end
		end
	end

	print("PlayerStartBonuses Done")
		
end
Events.SequenceGameInitComplete.Add(PlayerStartBonuses)


Is there anyone who can see any wrong commands in my code, etc.? When I look at my lua log, it seems like the game never initializes the local trait, but I doubt I have mispelled anything. Anyone?
 
Okay, first of all, it's so much easier to tell what your code is saying if you wrap it in
Code:
 blocks.

Second of all, you can't just add an XML column like that and expect it to work. You'd have to update the DLL with coding that specifies what this new "NightWatch" column actually does.
 
Code:
GameEvents.PlayerDoTurn.Add(function(iPlayer)
	if Players[iPlayer]:GetCivilizationType() == GameInfoTypes.[COLOR="Red"]YOUR_CIVILIZATION_TYPE[/COLOR] then
		if (Game.GetElapsedGameTurns()%10) == 0 then
			Players[iPlayer]:AddFreeUnit(GameInfoTypes.[COLOR="Red"]YOUR_UNIT_TYPE[/COLOR]);
		end
	end
end)
 
Spoiler :
Code:
GameEvents.PlayerDoTurn.Add(function(iPlayer)
	if Players[iPlayer]:GetCivilizationType() == GameInfoTypes.[COLOR="Red"]YOUR_CIVILIZATION_TYPE[/COLOR] then
		if (Game.GetElapsedGameTurns()%10) == 0 then
			Players[iPlayer]:AddFreeUnit(GameInfoTypes.[COLOR="Red"]YOUR_UNIT_TYPE[/COLOR]);
		end
	end
end)[/spoiler]
Spoiler :


Thanks for your reply. I've tried to insert that into my lua, instead of my current, but it doesn't seem to apply any of the if commands. I've deleted the xml and the sql, but as far as I can read in your code it shouldn't have anything to do with the trait itself, but the civilization itself. Nothing seems to happen at turn 10, where it should.
Thanks again though.
@AgressiveWimp I'm sorry that I hadn't put it in the code format, I didn't know it existed.
 
Top Bottom