[BtS][Modded]How to manually trigger an Event

tvbowman

Chieftain
Joined
Aug 26, 2020
Messages
30
In another discussion on this site, someone indicated that they were able to manually trigger an Event with a key-combination. They also mentioned that they got an Event to fire when the correct conditions were met. I have tried to create an Event but I don't know how to make it so it always works and I don't know how to manually fire it. Can anyone help me?

What I am trying to do is create a feature or improvement that acts sort of like a Goody Hut, so that when a Scout visits it, an Event fires. It would be similar to the way Colonization handles units entering native villages, where it asks if you want to talk to the chief or live among the natives or attack, etc.
 
The key combination probably refers to Ctrl+Shift+E, but that's a BUG 4.5 feature, and most BUG-based mods use version 4.4, the last official release. BAT is the notable exception; the shortcut should work in BAT. Well, I assume that you want to trigger the event programmatically and are only interested in the implementation of the BUG shortcut. This thread has just inspired me to merge the shortcut into my own mod, so this Git commit of mine includes all the relevant code. The actual triggering happens simply through a call to CyPlayer::trigger with the event trigger ID as the call argument (at the end of the triggerRandomEvent function in the TriggerEvent module). I.e. the trigger function already exists in BtS and was already exposed to Python. It should be possible to obtain the event trigger ID through getInfoTypeForString.
 
The key combination probably refers to Ctrl+Shift+E, but that's a BUG 4.5 feature, and most BUG-based mods use version 4.4, the last official release. BAT is the notable exception; the shortcut should work in BAT. Well, I assume that you want to trigger the event programmatically and are only interested in the implementation of the BUG shortcut. This thread has just inspired me to merge the shortcut into my own mod, so "that git commit" of mine includes all the relevant code. The actual triggering happens simply through a call to CyPlayer::trigger with the event trigger ID as the call argument (at the end of the triggerRandomEvent function in the TriggerEvent module). I.e. the trigger function already exists in BtS and was already exposed to Python. It should be possible to obtain the event trigger ID through getInfoTypeForString.

This went way over my head, so I looked at your code, and that went even further over. I guess I should clarify that I am using a Mod of FfH2. I seriously doubt I could incorporate any of your code into my project.

Let's get back to this:
What I am trying to do is create a feature or improvement that acts sort of like a Goody Hut, so that when a Scout visits it, an Event fires. It would be similar to the way Colonization handles units entering native villages, where it asks if you want to talk to the chief or live among the natives or attack, etc.

So, I know how to create an event, and if there is an existing routine that runs visible python code in my project, I can edit that code to select my event rather than what it currently does, but in this case, I am not aware of any existing code that runs when someone walks over a goody hut or any other feature, bonus, or improvement on the map. In FfH2 there are dungeons and ruins, but in order for code to run on them, you need to "cast a spell". I tried replacing the Goody Huts, but the new features acted the same, and did not run my Event, but either gave out the same goodies, or did nothing when I walked on them.
 
I didn't mean to suggest that you adopt all that code. The only relevant part, as far as I can tell, is that CvPlayer::trigger can be used to trigger an event from Python – something like: player.trigger(gc.getInfoTypeForString("EVENTTRIGGER_MY_EVENT"))
It sounds like perhaps you were already aware of that; in any case, the problem is to find
[...] code that runs when someone walks over a goody hut or any other feature, bonus, or improvement on the map.
There's a Python function doGoody in CvGameUtils.py that gets called from the DLL when an improvement with bGoody=1 is entered by a non-Barbarian unit. Your code in doGoody could check e.g. the type string of the improvement (getInfoTypeForString) to decide whether to trigger your event or to take no action. In the former case, True should be returned to indicate to the DLL that Python has handled the goody.

In a total conversion with a lot of Python code, things could work a bit differently. There might already be Python code in doGoody, or the mod could include BUG, which handles Python callbacks differently. Well, a print statement (to PythonDbg.log) should clarify quickly whether your code is being executed.
 
Top Bottom