[TOT] Diety level difficulty two settlers?

DaggerDigwillow

Reading: Second World Wars by Victor Davis Hanson
Joined
Dec 8, 2013
Messages
216
In Classic Civ 2 when playing Deity you would always get two settlers in TOT Extended Original you only get 1 but in Tot when selecting Original Game you still get two. Is there a way to fix this for the extended original?
 
Very easy with totpp.
Add an event.lua file in the original(misunderstood) extended original folder.

In this file, add a little code doing "At the beginning of the first turn, if difficulty is deity, for each tribe playing, if the amount of settlers is one then create a second one at the settlers' location"
 
Last edited:
Gave this a try and don't think I'm implementing it correctly. I created a text file named event.lua in the original folder.
Copied and pasted the quoted text in your message both with and without the quotes but neither one worked. Moved the file to extended original in both instances and still no success. Not familiar with lua files so I'm probably doing this wrong.
 
Gave this a try and don't think I'm implementing it correctly. I created a text file named event.lua in the original folder.
Copied and pasted the quoted text in your message both with and without the quotes but neither one worked. Moved the file to extended original in both instances and still no success. Not familiar with lua files so I'm probably doing this wrong.
Ho, sorry. I only gave you the litteral idea to transcribe in Lua. I'll look into it this evening to give you the corresponding event.lua, as light as possible.
 
There we are, just tested it.
Don't hesitate to open the lua file with a text editor to see how it's working.

Just have to unzip it in the folder of the mod "to correct" : extended original

! if one already have an events.lua file in said folder, don't replace it by this one. You would loose code that could be important. You should only add portion of this file in the previous one !
 

Attachments

  • events.7z
    875 bytes · Views: 20
Last edited:
This is awesome I will give it a try tomorrow.

Another few questions on Lua.
When can I learn it/practice it best?
Could I script events where any combat that takes place the victor creates a unit such as the captive function creating settlers in Civ 3?
 
Could I script events where any combat that takes place the victor creates a unit such as the captive function creating settlers in Civ 3?
Of course. Such a feature is displayed (with alea) in the dadais expansion mod proposing slavery generation (and risk if owning too much) per exemple.

When can I learn it/practice it best?

I guess the best to begin is @Prof. Garfield 's learning guide. A good thing to play with to understand the basics.

Then, to go further easily, it is possible to use @Prof. Garfield 's template.
One could also look into the lua code of scenario events file(s) to learn from there code, with a little experience.
 
Ok looking at the Lua event file for your Dadais mod I see the following.

if "modSlavery" == "modSlavery" then

allStatics.SlaveryBoolean = true -- Set Slavery Capture And Revolt On or Off

allStatics.chanceToGetSlaves = 25 --% Chance To Get Slaves
allStatics.chanceForVeteranToGetSlaves = 50 --% Veterans Chance To Get Slaves

allStatics.thresholdRandomCheckSlavery = 20 --Slave Unrest Random Chance To Evolve Into Revolt (+luxuries%)

end
Does this require another mod called "slavery" or is it referencing another instance within the Dadais mod? How does the Evolve into revolt work?
 
Ok looking at the Lua event file for your Dadais mod I see the following.

if "modSlavery" == "modSlavery" then

allStatics.SlaveryBoolean = true -- Set Slavery Capture And Revolt On or Off

allStatics.chanceToGetSlaves = 25 --% Chance To Get Slaves
allStatics.chanceForVeteranToGetSlaves = 50 --% Veterans Chance To Get Slaves

allStatics.thresholdRandomCheckSlavery = 20 --Slave Unrest Random Chance To Evolve Into Revolt (+luxuries%)

end
Does this require another mod called "slavery" or is it referencing another instance within the Dadais mod? How does the Evolve into revolt work?
This part of the code says :
"We name statics and give them a value"

Another part later in the file will refer to these to order diverse stuffs.
Per exemple, in the civ.scen.onUnitKilled() function, we check if allStatics.slaveryBoolean is true to know if we gives try to give a slave or not to the winner, adding conditions.
 
This part of the code says :
"We name statics and give them a value"

Another part later in the file will refer to these to order diverse stuffs.
Per exemple, in the civ.scen.onUnitKilled() function, we check if allStatics.slaveryBoolean is true to know if we gives try to give a slave or not to the winner, adding conditions.
Alright, this is well out of my depth but if I understand correctly the static is a function being identified for later use.
The later reference recalls the identifier for actually putting the function into use

There are later references to the slave such as
if "units" == "units" then
-- objects.u = nil
objects.uSlaves = civ.getUnitType(0) --Worker

Also an instance of

if allStatics.SlaveryBoolean and turn >= 5 then
allVariables.slaveUnitsToCount = 0
for unitToCountSlaves in civ.iterateUnits() do
if unitToCountSlaves.owner == tribe then
if unitToCountSlaves.type == objects.uSlaves or unitToCountSlaves.type == objects.uAfricanSlaves then

allVariables.slaveUnitsToCount = allVariables.slaveUnitsToCount + 1

end
end
end

I've tried to ignore the revolt, abolition and african slave references as I only want the slave unit created when one unit destroys another unit.
If I understand the above 2 instances of code correctly the first is the identifier for later recall and the second is the actual instance instructing the game to check if the game has progressed past turn 5 then to count how many slaves are in play and add +1.

Is this correct?
 
If I understand the above 2 instances of code correctly the first is the identifier for later recall

This is correct.

and the second is the actual instance instructing the game to check if the game has progressed past turn 5 then to count how many slaves are in play and add +1.

This is not.
This piece of code is for counting already existing slaves a the current tribe in a variable.
This variable is then used to check if a slave revolt is launched or not ;) .

The piece you are looking for is in the onUnitKilled() ;)
 
So this section of the code would be all that is needed for implementing the creation of a "slave" unit under the unit that won a battle? It looks like the civ names need to be specified and if the unit is veteran that wins the conflict the chance for slave unit creation is 100%?

civ.scen.onUnitKilled(function (loser, winner)

if allStatics.SlaveryBoolean then
if not(civ.hasTech(winner.owner, objects.kSlaveryAbolition)) and winner.type.domain == 0 and loser.type.domain == 0 then
if winner == allVariables.unitDidAttack then

if loser.owner.name == "Zulus" or loser.owner.name == "Ethiopians" or loser.owner.name == "Malineses" then
if winner.veteran then
if math.random(100) <= allStatics.chanceForVeteranToGetSlaves then civlua.createUnit(objects.uAfricanSlaves, winner.owner, {{winner.location.x, winner.location.y, winner.location.z}},{count = 1, randomize = true, homeCity = nil}) end
else
if math.random(100) <= allStatics.chanceToGetSlaves then civlua.createUnit(objects.uAfricanSlaves, winner.owner, {{winner.location.x, winner.location.y, winner.location.z}},{count = 1, randomize = true, homeCity = nil}) end
end
else
if winner.veteran then
if math.random(100) <= allStatics.chanceForVeteranToGetSlaves then civlua.createUnit(objects.uSlaves, winner.owner, {{winner.location.x, winner.location.y, winner.location.z}},{count = 1, randomize = true, homeCity = nil}) end
else
if math.random(100) <= allStatics.chanceToGetSlaves then civlua.createUnit(objects.uSlaves, winner.owner, {{winner.location.x, winner.location.y, winner.location.z}},{count = 1, randomize = true, homeCity = nil}) end
end
end

end
end
end

end)
 
Spoiler code :

civ.scen.onUnitKilled(function (loser, winner)

if allStatics.SlaveryBoolean then
if not(civ.hasTech(winner.owner, objects.kSlaveryAbolition)) and winner.type.domain == 0 and loser.type.domain == 0 then
if winner == allVariables.unitDidAttack then

if loser.owner.name == "Zulus" or loser.owner.name == "Ethiopians" or loser.owner.name == "Malineses" then
if winner.veteran then
if math.random(100) <= allStatics.chanceForVeteranToGetSlaves then civlua.createUnit(objects.uAfricanSlaves, winner.owner, {{winner.location.x, winner.location.y, winner.location.z}},{count = 1, randomize = true, homeCity = nil}) end
else
if math.random(100) <= allStatics.chanceToGetSlaves then civlua.createUnit(objects.uAfricanSlaves, winner.owner, {{winner.location.x, winner.location.y, winner.location.z}},{count = 1, randomize = true, homeCity = nil}) end
end
else

if winner.veteran then
if math.random(100) <= allStatics.chanceForVeteranToGetSlaves then civlua.createUnit(objects.uSlaves, winner.owner, {{winner.location.x, winner.location.y, winner.location.z}},{count = 1, randomize = true, homeCity = nil}) end
else
if math.random(100) <= allStatics.chanceToGetSlaves then civlua.createUnit(objects.uSlaves, winner.owner, {{winner.location.x, winner.location.y, winner.location.z}},{count = 1, randomize = true, homeCity = nil}) end
end
end

end
end
end

end)




This is what is doing the job.
I did put in red what you said you didn't need, in purple what you may not need too,
and in Bold Underscored what need to be defined at the beginning of the file.
Take care about allVariables.unitDidAttack : not like objects and statics which are supposed to stay the same once defined, it is a variable that has its value changed in the file (for this one, when a fight is initiated, to determine who is the attacker)

too bad we can't have both "code" and personalized police at the same time :(
 
I'll try to implement this when I get home over the next couple of days and report back.

I don't understand the "code" and personalized police meaning.
 
Ok so can I just insert this into the other file for Two settlers on Deity? Do I need to change "slave" to settler in the event.lua file or create a new unit in the rules file?
 
Ok so can I just insert this into the other file for Two settlers on Deity?

yes.
Don't forget about the part of the code allocating a value to allVariables.unitDidAttack.
Otherwise, the code won't launch, as the winner shall never be equal to "nil" (with no value)

Do I need to change "slave" to settler in the event.lua file or create a new unit in the rules file?

if objects.uSlaves is not defined before, it can ba changed for civ.getUnitType(0).
It refers directly for the first unitType in the rules.txt, on the settlers slot.
 
Ok so how would I allocate a value to the allVariables and define objects.uSlaves in the attached file? Do I need to change the unit looked for to "Settler" instead of nil?
 

Attachments

  • events.zip
    1.1 KB · Views: 13
Also I got a chance to try the events.lua file for 2 settlers on diety and it does not seem to work
 
Also I got a chance to try the events.lua file for 2 settlers on diety and it does not seem to work
Did the console returned you an error message ?
Which game type did you launch ? Did you activate Lua events ?
Where did you put the event.lua file ?
 
Ok so how would I allocate a value to the allVariables and define objects.uSlaves in the attached file? Do I need to change the unit looked for to "Settler" instead of nil?
To allocate a value, one shall write une Lua
variableName = value
With variableName being the variable and value what's poured in this variable. This value can be a string "hello world", integer "1", and many others kinds including "objects".

Here, checking if winner is equal to allVariables.unitDidAttack, we want them to be the same kind.
Winner is a "unit object", so we shall allocate a "unit object" to allVariables.unitDidAttack.

You shall see it done in the civ.scen.onInitiateCombat() function in the file you took as an exemple.

.

About the second question, I don't really understand it.
A nil value is an "empty value"

.

I realized I forgot to mention TNO excellent reference thread to understand better the lua environnement applied in civ2totpp.
 
Top Bottom