How do you manually trigger BtS Random Events

sinucus

Chieftain
Joined
Oct 13, 2006
Messages
14
I am wondering how you can trigger manually the random events in BtS. Is there a way with Python to trigger event XX on demand? In some games a random event has triggered but for whatever reason I had to reload from a prior save and that event doesn't happen again, is there a way to force these events on demand? Thanks
 
A simple way via XML is to set iWeight to -1 and iPercentGamesActive to 100 in the XML\Events\EventTriggerInfos.xml.
This will make the event trigger immediatly after all requirements have been meet.

There's also a way with python, but if you're not familiar with it, it might be too difficult.
 
Turn on cheatcodes.

Then, use SHIFT-~ in game to activate the python console. Type "gc.getPlayer(0).trigger(gc.getInfoTypeForString("XML_NAME_FOR_EVENT_TRIGGER"))"., then press enter.

Now a brief explanation of what you are doing. Player 0 is the human, 99% of the time. getInfoTypeForString gives the game the number value for some kind of string (word). The "XML_NAME_FOR_EVENT_TRIGGER" part needs to be looked up in CIV4EventTriggerInfos.xml, you need to know which event should be triggered.
 
Awesome! That appears to be just what I was looking for, I can't test for sure until I can load up my game in a few hours.
 
Turn on cheatcodes.

Then, use SHIFT-~ in game to activate the python console. Type "gc.getPlayer(0).trigger(gc.getInfoTypeForString("XML_NAME_FOR_EVENT_TRIGGER"))"., then press enter.

Now a brief explanation of what you are doing. Player 0 is the human, 99% of the time. getInfoTypeForString gives the game the number value for some kind of string (word). The "XML_NAME_FOR_EVENT_TRIGGER" part needs to be looked up in CIV4EventTriggerInfos.xml, you need to know which event should be triggered.

So that worked exactly as you stated but is it possible to use copy/paste or must I always hand type this for whatever trigger I am trying to do?
 
Type by hand, console commands can't accept copy-paste. Sucks, I know.
 
I have some python code which allows you to trigger any event available in the game in a simple pop-up window. When cheat mode is activated, Ctrl-Shift-E opens the event screen and there you can select an event to trigger.

If you have hundreds of events, I do not recommend using it as it has no search/sort functionality and just lists the events in the sequence they appear in the trigger XML file.

If someone is interested, I can extract the code bits and make them available.
 
See below for the code bits needed for this event-trigger pop-up. Please note, that I have written this piece of code for CIV COL. It is not tested with CIV BTS, but should work.

In CvEventManager.py, please locate the function onKbdEvent and insert the additional code below the line CvCameraControls.g_CameraControls.handleInput( theKey )

PHP:
#################### ON EVENTS ######################
	def onKbdEvent(self, argsList):
		'keypress handler - return 1 if the event was consumed'

		eventType,key,mx,my,px,py = argsList
		game = gc.getGame()
		

		if (self.bAllowCheats):
			# notify debug tools of input to allow it to override the control
			argsList = (eventType,key,self.bCtrl,self.bShift,self.bAlt,mx,my,px,py,gc.getGame().isNetworkMultiPlayer())
			if ( CvDebugTools.g_CvDebugTools.notifyInput(argsList) ):
				return 0
		
		if ( eventType == self.EventKeyDown ):
			theKey=int(key)
			
			CvCameraControls.g_CameraControls.handleInput( theKey )
						
# Ronnar: EventTriggerMenu START
# Shift+Ctrl+E in cheat mode
			if( theKey == int(InputTypes.KB_E) and self.bShift and self.bCtrl and self.bAllowCheats) :
				iPlayer = gc.getGame().getActivePlayer()
				popupInfo = CyPopupInfo()
				popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON)
				popupInfo.setText(CyTranslator().getText("TXT_KEY_POPUP_SELECT_EVENT",()))
				popupInfo.setData1(iPlayer)
				popupInfo.setOnClickedPythonCallback("selectOneEvent")
				for i in range(gc.getNumEventTriggerInfos()):
					trigger = gc.getEventTriggerInfo(i)
					popupInfo.addPythonButton(str(trigger.getType()), "")
				popupInfo.addPythonButton(CyTranslator().getText("TXT_KEY_POPUP_SELECT_NEVER_MIND", ()), "")
				
				popupInfo.addPopup(iPlayer)
# Ronnar: EventTriggerMenu END

			if (self.bAllowCheats):

In CvScreensInterface.py a new function must be added at the end of the file:

PHP:
#Ronnar: EventTriggerMenu START

def selectOneEvent(argsList):
	iButtonId = argsList[0]
	iData1    = argsList[1]
		
	eventTriggerName = None
	eventTriggerNumber = -1

	if iButtonId < gc.getNumEventTriggerInfos():
		eventTriggerName = gc.getEventTriggerInfo(iButtonId).getType()
		eventTriggerNumber = iButtonId
	if eventTriggerName == None:
		return
	if eventTriggerNumber == -1:
		return
	message = 'Event: %s[%d]' % (eventTriggerName, eventTriggerNumber)
	CyInterface().addImmediateMessage(message, "")
	#message = 'pyPrint: You selected Event: %s[%d]' % (eventTriggerName, eventTriggerNumber)
	#CvUtil.pyPrint(message)
	#message = 'print: You selected Event: %s[%d]' % (eventTriggerName, eventTriggerNumber)
	#print message
	pPlayer = gc.getPlayer(iData1)
	pPlayer.trigger(eventTriggerNumber)

#Ronnar: EventTriggerMenu END

This function will trigger the event and print the event name as message. There is also code included which allows to print this into the log files. You can activate it if you need this functionality.
Note that events are only triggered if all trigger conditions are met. This function does not bypass the trigger conditions, just eliminates the random roll for this event.

You should also create two text keys in file CIV4GameText_Events_BTS.xml:

PHP:
	<TEXT>
		<Tag>TXT_KEY_POPUP_SELECT_EVENT</Tag>
		<English>Choose an event which should be triggered.</English>
		<French>Choose an event which should be triggered.</French>
		<German>Event aussuchen, das gestartet werden soll.</German>
		<Italian>Choose an event which should be triggered.</Italian>
		<Spanish>Choose an event which should be triggered.</Spanish>
	</TEXT>
	<TEXT>
		<Tag>TXT_KEY_POPUP_SELECT_NEVER_MIND</Tag>
		<English>Do not trigger an event.</English>
		<French>Do not trigger an event.</French>
		<German>Kein Event starten!</German>
		<Italian>Do not trigger an event.</Italian>
		<Spanish>Do not trigger an event.</Spanish>
	</TEXT>
 
Interesting, will have to give that a try next chance that I have. Looks like it'll be much easier than typing and extracting the event trigger names out manually.
 
Good stuff... :goodjob:
 
Thanks, I've added this feature to BUG.

That's an unexpected honour for a newbie python coder :)

I assume you did a few tests as I did not try it in CIV BTS, only in Colonization.

I also did not try what happens if you have hundreds of active events in a game or if the user has switched off events completely. I hope it doesn't crash in these cases.
 
Hmm, all good things to test. I tested the basic feature, and it works in BTS. I made a slight improvement to make the list more readable: stripping the EVENTTRIGGER_ prefix, converting _ to space, and switching to title casing. I tried getting the help text to show up when hovering over a button without success, so the name will have to be enough. It would probably be possible with BULL, though.
 
I need to test events in my mod, which I've integrated BUG 4.4 into it. I've set Cheatcode=1 in My Documents\My Games\Beyond the Sword\CivilizationIV.ini , however, pressing SHIFT-~ does not open up a console (or CTRL-SHIFT-E doesn't pop-up the one suppose to be in BUG).

What did I miss or do wrong?

Thanks!
 
The cheat code is actually not 1 but Chipotle.
 
Wait, to do this with BUG you need to enable the cheat code (CheatCode = chipotle) in the ini file and then press Ctrl-Shift-E?
 
Wait, to do this with BUG you need to enable the cheat code (CheatCode = chipotle) in the ini file and then press Ctrl-Shift-E?

Yes, it's designed to be used by modders testing their events--not players looking to get free Cover promotions. ;)
 
I couldn't get this to work. When I hold down Ctrl-Shift-E I get all sorts of weird info about techs and units when I move the mouse around.
 
Top Bottom