GameEvents

Joined
Mar 6, 2003
Messages
775
GameEvents is not listed on the Wiki, its available in Lua from the main state and indexed in other states. Unlike the InGame Events these don't depend on what is revealed on the player's map.

Functions:

* CanDeclareWar
listener(playeractive, playertarget)

* PlayerDoTurn
listener(player)

* PreGameStart
?

* SetPopulation
listener(x, y, populationold, populationnew)

* TeamMeet
listener(playeractive, playermet)

* TeamTechResearched
listener(val1, val2, val3)

* UnitGetSpecialExploreTarget
listener(player, someID)

* UnitSetXY
listener(player, unitID, x, y)


===

Also,
LuaEvents functions:

* OnRecommendationCheckChanged
?
 
I take it these were harvested from the New World scenario? I remember some of them from when I read that... I rather suspect there are more, as well, and the modding dev has taken his time (so far) on his promise to document them for us...

PS: or if it's only from the polynesia scenario, there may be more in the New World scenario.

PPS: Good work on pulling the info out, in any case.
 
Ah, here we are, from New World scenario:

* CityCaptureComplete (city has been captured and all updates to data structures gone through, as an educated guess)
listener(playerID, bCapital, iX, iY, newPlayerID) (playerID presumably old owner, bCapital is "is this a capital")

* UnitGetSpecialExploreTarget (appears to be called whenever a unit is told to explore, with a return of true if the target has been set, and the unit gets the target set through pUnit:ExecuteSpecialExploreMove(pTargetPlot), giving the unit a particular target to aim for)
listener(iPlayerID, iUnitID)

Also, regarding CanDeclareWar - this is another one with the return mattering. If it's true (presumably for all listeners) then it's possible, and if it's false (presumably for any listener) it's not. However, it's possible the precedence works the other way, I'm just guessing based on what makes sense.

Maybe I'll get this on the official wiki later.
 
Some of them can be seen in the Tuner. If you start a new game and look at the Table Browser (set to the Main State) it lists PreGameStart, TeemMeet, TeemTechResearched, and UnitSetXY under GameEvents. And all of them have 9 methods, as seen in the below screenshot.

2zrf3mp.jpg
 
Ah-ha! That appears to clarify slightly the situations with boolean returns and multiple listeners... it looks like there are three ways to trigger the event - Call, TestAll, and TestAny. I'll warrant that Call discards return values, TestAll and TestAny both handle them purely as booleans, with All ANDing them and Any ORing them. That just means we'd need to know, for each standard GameEvent (such as CanDeclareWar), which the engine does.
 
It seems to have taken me a week to notice, but Sseckman has added some background on the wiki, explaining the varieties of GameEvent and so on. No more info on the actual events as yet, though
 
The Viking scenario allows us to find out about two more GameEvents, one of which was in the patch notes as a new addition. CityCanContruct, taking a player index, a city index, and a buildingtype index; and SetAlly, triggered when someone becomes the Ally of a CS. The scenario makes very creative use of the latter, using it to 'give' the units of the CS to the Ally, including removing them from control of the old ally. I believe this only works because each CS has special units of its own (or does some cleverness with names, it's not clear), so it can find them later, and the way it changes ownership appears to be to remove the old unit and insert a new one with matching details.

Anyway, I've added those to the wiki.
 
I believe this only works because each CS has special units of its own (or does some cleverness with names, it's not clear), so it can find them later, and the way it changes ownership appears to be to remove the old unit and insert a new one with matching details.

Anyway, I've added those to the wiki.

that line is used to keep track of the owner :

Code:
pNewUnit:SetOriginalOwner(iOldOwner);

and it add the CS name to the unit.

I'm already using the kill/replace method for City State UU, and it seems they've forgotten to keep promotion/experience in this scenario.
 
The wiki now has a little more info that Sseckman provided when I asked for it; all of the GameEvents in the game are now listed there; there's only two that I've not found in the scenarios, and they may not be well tested. They plan to go through the game and find lots more places to add them, but so far they've been adding them where they've wanted for the scenarios, I guess.

It was suggested that feedback on what other events would be useful may be useful, and I guess it makes it more likely that those events would be added. Maybe we can even persuade the powers that be that they can be added without thorough testing, and we can test them and feed back.

Anyhew, I don't know if Mr Seckman is more likely to see things here or on the official modding forum; he's posted there a little bit recently, certainly. I guess a thread for GameEvents suggestions, and to keep track of them, would be worthwhile, and I'm happy to start it and collate every so often. I expect more people are likely to post here, but I have a slight leaning in logic towards official forums for likelihood/frequency of being noticed. Opinions on this are most welcome.
 
I had concluded that these events were being added as required, rather than available and undocumented, based on the "useful when you get the C code" section in the WIKI combined with a test of several hundred permutations of possible listener names I've been doing... :(

Regarding this newly documented GameEvents.PlayerPreAIUnitUpdate(iPlayerID) I think it's fairly safe to assume that the ID passed is the player index for the relevant player. I'll look into this methinks, because it may be useful to cycle through a players units and make changes to attributes before the AI makes decisions based on them. For example healing a unit before the AI decides to run away (not that it seems to do that...).
 
Well, I've created a thread on the official forums, and discussion there might flow better, but I'll be following here and anywhere else I notice as well (possibly less frequently).

The official forum thread is at http://forums.2kgames.com/showthread.php?107775-GameEvents-new-event-suggestions; I also made a thread for other suggestions that would make a big difference, but I'm just planning to pull stuff in I notice elsewhere - that said, I won't be searching really hard, so anything anyone wants to bring to attention there would be handy. Hopefully devs, particularly Shaun Seckman, will at least see it there, possibly even get into dialogue. The consolidation might be useful to them.
 
thanx for your work SamBC, here are a few suggestions :

CityCanTrain : similar to CityCanConstruct, for units
CanMakePeace : similar to CanDeclareWar
 
Obvious one, but it would be good to get events pre and post combat that weren't tied to the UI so we could count on them firing in strategic view or with quick combat enabled.

More than that, it would be cool to be able to pass back some info around the impact of our custom promotions and such to the AI. For example, if I want to have a "Zombie Hunter" promotion that increases unit strength versus Zombies, or just plain increases damage, it would be good for the AI to get that feedback when making decisions.
 
Obvious one, but it would be good to get events pre and post combat that weren't tied to the UI so we could count on them firing in strategic view or with quick combat enabled.
Already got that one :)
More than that, it would be cool to be able to pass back some info around the impact of our custom promotions and such to the AI. For example, if I want to have a "Zombie Hunter" promotion that increases unit strength versus Zombies, or just plain increases damage, it would be good for the AI to get that feedback when making decisions.
I'll put that in the other thread I started, on 'things that would be a real help' that could be changed or added. However, I think it would be a big project for them. Hopefully the AI already looks at what the bonuses and penalties will be in specific cases, in order to judge the sense of a particular attack.
 
Obvious one, but it would be good to get events pre and post combat that weren't tied to the UI so we could count on them firing in strategic view or with quick combat enabled.

More specifically, these events need to have additional information that the CombatSim events don't:

> When a city is one of the two "units" involved, the CombatSim events will just have unit number -1, and there'll be no way to figure out which city was involved.
> When a nuke is used, the defending player and unit are both -1, because nukes are targeted on a map hex and not a unit/city. Also, since nukes can damage units from multiple players, it's a bit more problematic in general.

In both cases, all we'd really need are positional arguments. Pass the X and Y of the hex where the combat is happening in to the routine, and we could figure out ourselves which city is involved, which player is getting nuked, and so on. (Normally you could get this from the defending unit's position, but that doesn't work for nukes or cities.)
 
Back
Top Bottom