[SDK MOD] Action Buttons 2.0

talchas

Prince
Joined
Jan 3, 2006
Messages
428
Alright, here is the new version of my action buttons utilities (old version, which uses python only is here) that uses the SDK. This means that there are no more problems due to negative action numbers, and there are tooltips. The mod is runnable as it is as a demo where all units that can attack and have combat 1 get a healing ability.

As before the AI does not use this.

The files:
Civ4-talchas-AB.xls - an excel file that outputs the action buttons xml file.
C++ source - the C++ source files. To rebuild the new dll, copy these on top of a copy of the sdk files. It also includes the Code::Blocks project file I am using
Assets\Python\EntryPoints\CvABInterface.py - A new entry point for this utility. You should open this up and change the "import MyMod" at the top to something for your mod.
Assets/Python/MyMod.py - the python file containing all of the functions used by the action buttons. This file could be named anything, or split into many different files, but all of the files would have to be imported in CvABInterface.py.
Assets/XML/Units/CIV4ActionButtonInfos.xml - this is where all of the actions are defined. There are explanations of the tags in the excel file.
Assets/CvGameCoreDLL.dll - the modified dll file.


To use:
  • Copy all of the Assets/* files into your mod's Assets folder.
  • Rename MyMod.py to whatever you want and change CvABInterface's import statement to import the new name.
  • Open up the renamed MyMod.py and add 2 functions for each action you want. One function should return true when you can use the action. The other should do whatever the action is supposed to do. See the note in MyMod.py about bTestVisible, basically when bTestVisible is true, the game is testing whether or not the button should appear at all.
  • Open up CIV4ActionButtonInfos.xml or the excel file. If you use the excel file, reimport the CIV4ActionButtonInfos.xml from wherever your mod is.
  • Add entries for each action. PyRequirement should call the function you defined previously for this action that returns true when you can do this action. There are three variables you can use here - pUnit, which is a reference to the selected unit, eAction, which is the number of the action, cooresponding to gc.getActionButtonInfo(), and bTestVisible, which I discussed before. PyResult should call the function that does whatever you want the button to do.
  • If you are using the the excel file, export it.
  • Run Civ4.

File at http://members.aol.com/ben77/ActionButtons2.zip
 
Can we get a link please?
 
Upload completed.
 
Talchas,
I downloaded your mod and are getting this error when clicking on a unit with the combat1 promotion:
raceback (most recent call last):

File "CvABInterface", line 16, in canDoAction

File "<string>", line 0, in ?

TypeError: canDoTest1() takes exactly 1 argument (2 given)
ERR: Python function canDoAction failed, module CvABInterface

EDIT: I would dive into your code and send you a fix but I am trying to get all of my mod components to be compatible with the v1.61 patch... almost there :D
 
Oops, I put the bTestVisible argument on the wrong function in the python. The problem is just with the example, I'm uploading a new version now.

Done.
 
Let us know when you are done uploading it so I can grab it and play with it.

Thanks!!
 
Its finished.
 
Very cool, it works!!!! :good job:
 
Ok, I couldn't help myself, I dove into your code...

Could I ask a favor from you Talchas? Could you wrap your code in start/end comment tags so it is easier to see what changes you made to the code? I had to do a diff on your files to see what you changed.

Thanks
 
Umm, yeah I should probably do that, or at least include a diff in with the code. Its just that I copied most of it over from FFH's new spell system code, so I wasn't thinking in that way.
 
Ok, I've uploaded a new version with those tags stuck in.
Code:
//// BEGIN ActionButtons2
(changed)
//// END ActionButtons2

and
(changed) //// ActionButtons2
if its just one line.
 
Talchas, I downloaded the new version of your mod and started it up on my machine... I think there might be a problem with it, I am not seeing the sample button from your mod on any of my units. Any ideas?
 
Oops, not a problem with the mod, its a problem with the description in my post. The heal ability is only given to units with combat 1. I'll edit the first post to reflect this.
 
talchas said:
Oops, not a problem with the mod, its a problem with the description in my post. The heal ability is only given to units with combat 1. I'll edit the first post to reflect this.
Ah, ok, thanks for pointing that out :D
 
It allows mod makers to create their own action buttons and add them to the game. In its previous incarnation there was the limit that the action buttons wouldn't display the help text, this version fixes that limitation by using the SDK. The other benefit of using this mod is that you do not have to go through the SDK to add action buttons, instead talchas provided a very flexible way to add the action button functionality through python instead. It is a very slick and flexible mod.

Did I do your mod justice talchas?
 
Yeah - although the fact that the AI can't use them is pretty important - if you want to see something like that, you get to wait until phase 2 of FFH .
 
Talchas, I am having an issue that you might be able to help with. I am trying to integrate your ABM v2.0 into the mercenaries mod. Basically right now I am stuck... in my <PyResult>...</PyResult> tags I have a call to a method that calls the kill method from the CyUnit class. But when the kill method is called the game crashes. I know its not the mercenary code since I did my due diligence can when through and traced my code to that method call. When I found it I isolated the call to a new method whos only purpose was to call that method. Here is a copy of you CvABInterface.py file with the code causing the crash so you can see it yourself.
Code:
from CvPythonExtensions import *

def foobar(objUnit):

	objUnit.kill(false,PlayerTypes.NO_PLAYER)

	
gc = CyGlobalContext()
def doAction(argsList):
	pUnit, eAction = argsList
	action = gc.getActionButtonInfo(eAction)
	eval(action.getPyResult())
	CyInterface().setDirty(InterfaceDirtyBits.SelectionButtons_DIRTY_BIT, True)

def canDoAction(argsList):
	pUnit, eAction, bTestVisible = argsList
	action = gc.getActionButtonInfo(eAction)
	req = action.getPyRequirement()
	if(req == None or req == ""): 
		return True
	return eval(req)

Here's the <ActionButtonInfo>:
Code:
		<ActionButtonInfo>
			<Type>FIRE_MERCENARY</Type>
			<Description>TXT_KEY_FIRE_MERCENARY</Description>
			<Civilopedia>TXT_KEY_PEDIA_USELESS</Civilopedia>
			<Strategy>TXT_KEY_STRATEGY_USELESS</Strategy>
			<Help>TXT_KEY_FIRE_MERCENARY_HELP</Help>
			<PromotionPrereq1>NONE</PromotionPrereq1>
			<PromotionPrereq2>NONE</PromotionPrereq2>
			<PyResult>foobar(pUnit)</PyResult>
			<PyRequirement>true</PyRequirement>
			<HotKey></HotKey>
			<bAltDown>0</bAltDown>
			<bShiftDown>0</bShiftDown>
			<bCtrlDown>0</bCtrlDown>
			<iHotKeyPriority>0</iHotKeyPriority>
			<Button>Art/Interface/Buttons/Actions/FireMercenary.dds</Button>
		</ActionButtonInfo>

Let me know what you think.
 
use kill(true...) not kill(false...) for anything called from the actionbuttons stuff.
 
Top Bottom