Random Settler and Tech Events

Darkhour

Warlord
Joined
Nov 15, 2005
Messages
165
Location
Melbourne, Australia
Can anyone help me, point to me and or explain how to me how to either;

1. create a random event that spawn settlers
and
2. create a random event that spawn new techs

AND/OR

1. create event that spawns random chance of new tech on completion of building
and
2. create a random event that spawns a random chance of a settler on the turn a city grows

Cheers in advance,
Darkhour
 
There are no random events built into the game. However, you can create these yourself pretty easily; make a start-of-turn event (ActivePlayerTurnStart), do a random number draw, and if it's the right value, do whatever you want.

There is no event for the completion of a building. You can get around this somewhat by saving the list of buildings in a city each turn, and checking the following turn to see if it differs; this is what the Building Resources mod does to allow certain buildings to create strategic resources. But this'll only trigger at the start of the following turn.

Similar limits apply to the "when a city grows" trigger you mention.

Now, as to the specific effects you've asked about:
> Spawning a Settler is easy, as long as you limit it to only be possible once a few turns have passed, so that you have an established capital city (which gives you the X and Y value to spawn the settler at). This one's very straightforward, although the balance could be very difficult if you let this happen early in the game, and in the late game (when all good sites are settled), having an extra settler is just worthless.

> By "spawn new techs" I'm assuming you mean gain existing techs from the list of ones your empire can currently research. This isn't actually that hard to do, but if it's purely random then it can be extremely overpowered; the random number generator, like all good random generators, is "streaky".
In my own mod, I have three Wonders that give you a small chance of stealing a tech known by any other civ, with the exact chance depending on how many other civs know the tech. It's not really that difficult to do, but there are a lot of little balance details you have to straighten out for this to work well.
 
I'd recommend using GameEvents.PlayerDoTurn rather than Events.ActivePlayerTurnStart - partly so you can separate it and do different things on each player's turn start (that includes AIs) and partly so it will still work when (if) they ever allow mods in MP (including hotseat).
 
cheers guys.. i have no idea how to mod lua but ill try to understand and ask for more help..

I dont know if this should be another thread but ill ask here anyway..

I've decided to change my mind and trigger the creation of a settler unit when a city loses population due to starvation. So the question is how do I go about this..?

I've found and snooped around some mods that refer to different triggers and I believe that setpopulation()-1 and foodifference <=0 is the key?

Cheers
Darkhour
 
I've found and snooped around some mods that refer to different triggers and I believe that setpopulation()-1 and foodifference <=0 is the key?

No.

SetPopulation is an OBJECT, not a EVENT. (Same for FoodDifference.) As in "once the trigger happens, set the population of this city to X". You still need an actual trigger.

Trigger events are listed here. The one you probably want is SerialEventCityPopulationChanged, but the Serial Events tend to be flaky since they generally only trigger when the active player (you) SEES the event happening. In this case, you have to have at least seen that city already, which is not really a good thing since it means it won't trigger in the early game for the AI empires on other continents.

Unfortunately, there don't seem to be any non-Serial events for this particular thing.
 
Ah. Yes, the GameEvent should work fine; I thought you were referring to the City:SetPopulation, since you also talked about FoodDifference. (The GameEvents are mostly relatively new and not very well documented.)

So yes, you could just make a function that keys off of that GameEvent, and if NewPopulation is less than OldPopulation it does something. Of course, there are two big problems with having a size reduction do something beneficial (like spawn a Settler):
1> There are more ways to lose population than just starvation. For instance, how do you tell the difference between losing a size due to starvation and losing a size due to being conquered and/or nuked? You can check FoodDifference, but it's possible to be running negative on food, still have plenty stored, and lose a size for those other reasons. So you'd also need to check the current food supply and figure out if it's possible that it was possible that it was a starvation loss, but even that's not conclusive due to how the numbers work.
(This sort of disambiguation problem applies to a lot of events. For instance, the SerialEventUnitCreated event triggers whenever a unit is created, embarks, disembarks, rebases, or you reload a savegame... you often have to find other ways to indicate this.)

2> An AI will attempt to stay at or above zero on food, because it thinks that growth is good. A Human, if he knows about this extra benefit, might choose to deliberately starve his own city to take advantage of it.
This is common to a lot of Lua modding; the game's AI will continue to play in its normal way, regardless of what you add. If the benefit is significant enough (and I'd say that adding an early-game Settler is), the human player gains a large advantage.
 
ok just trying to get this to work now.. go through all players and all cities, look to see if the cities are stagnant and then minus a population if they are.. i keep returning a nil value for foodDifference... regardless of anything i do.. ??

Code:
function stagnation(iPlayer)
	local pPlayer = Players[iPlayer]
	for pCity in Players[iPlayer]:Cities() do
		if pCity:foodDifference() == 0 and pCity:GetPopulation() > 1 then
			pCity:setPopulation(-1)
		end
	end
end
GameEvents.PlayerDoTurn.Add(stagnation)

as a further question.. is there anyway to add x amount of turns of stagnation as a requirement?
 
i keep returning a nil value for foodDifference... regardless of anything i do.. ??

That's because you have to capitalize the F. It's case-sensitive.

Also, as I said before, SetPopulation (the S also needs to be capitalized) sets the population of a city TO x, not changing it BY x. So pCity:SetPopulation(-1) means change this city's population to -1. Obviously not a good thing.

What you want to use is City:ChangePopulation(-1) instead. In general, a Change variable changes something by an amount, while a Set sets it to a specific amount.

as a further question.. is there anyway to add x amount of turns of stagnation as a requirement?

No. Or at least, not easily; you can use the Save/Load functions to store variables, but that takes a lot of work to set up. Without that, there's no easy way to store data across multiple turns, and Lua functions can only react to the current situation. There are at least four different ways I know of to make pseudo-counters, but each of those has other issues.
 
This reminds of an idea I had once...
Is it possible to make cities appear semi-randomly? I.E., you don't plan the city, it generally gets founded in a decent location though (basically, at certain points, a city would be founded at a "recommended" site, with no choice/input from the player)
I am aware that is unbalanced, I'm just wondering if it is possible.
 
I'm just wondering if it is possible.

Yes it is.

Need some Lua code, and surely some work to make it "realist", but it could be done, yes.
 
Spatz - thanks.. cant believe that it was case sensitive!.. im sure i tried mutliple times..

CivOasis - Ive long thought about that.. this time im trying for something inbetween..
 
Back
Top Bottom