[BTS] Python version of Civ2's barbarian leader cash reward

Herostratus

Grim Harbinger of Things to Come
Joined
Jul 24, 2009
Messages
116
I feel like this should be simple, but my Python knowledge is obviously not up to snuff.

For those who don't recall, in Civ 2 (Test of Time only, I believe), killing the Barbarian Leader unit granted a flat amount of gold to the killer. I want to make this happen in Civ4-- but so far, all I've been able to achieve is the spawning of the new barb unit.

The code I've tried to use, which is adapted/mangled from a couple of other peoples' mods, is below; the problems are twofold:
1- Nothing happened when I tested it: no news text, no gold bonus. I'm pretty confident my EVENTTRIGGER and EVENT code is sound.
2- This code contains no provision to confirm that the target unit is owned by the barbarian civ. If possible, I'd like that to be in there, because my mod incorporates the possibility of capturing units. (I don't mind especially whether or not the cash reward occurs if a unit is captured rather than killed, and at any rate, I think unit "capturing" actually functions as "unit is killed, then resurrected as the player's.")

Code:
    def onUnitKilled(self, argsList):
        'Unit Killed'
        unit, iAttacker = argsList
        'determine owner of lost unit'
        player = PyPlayer(unit.getOwner())
        attacker = PyPlayer(iAttacker)
## Bounty ##
        if unit.getUnitClassType() == gc.getInfoTypeForString("UNITCLASS_BARBLEADER"):
            pPlayer2 = gc.getPlayer(iAttacker)
            triggerData = pPlayer2.initTriggeredData(gc.getInfoTypeForString("EVENTTRIGGER_BOUNTY"), True, -1)

Anybody know what I should be doing instead?
 
And it's working! For those who wish to use this:
The following CvEventManager.py code grants 500 gold to the killer of a "Barbarian Leader" unit (UNITCLASS_BARBLEADER), and displays a line of news (not a popup, 'cuz I didn't use events) about it:

Code:
    def onUnitKilled(self, argsList):
        'Unit Killed'
        unit, iAttacker = argsList
        'determine owner of lost unit'
        player = PyPlayer(unit.getOwner())
        attacker = PyPlayer(iAttacker)
## Barbarian Leader Bounty ##
        if unit.getUnitClassType() == gc.getInfoTypeForString("UNITCLASS_BARBLEADER"):
            pPlayer2 = gc.getPlayer(iAttacker)
            pPlayer2.changeGold(500)
            CyInterface().addMessage(iAttacker,true,15,CyTranslator().getText("TXT_BARBLEADER_BOUNTY",()),'',0,'Art/Interface/Buttons/Units/barbleader.dds',ColorTypes(44), unit.getX(), unit.getY(), True,True)
## Barbarian Leader Bounty End ##

And the following is the XML/Text content you need for the news:

Code:
    <TEXT>
        <Tag>TXT_BARBLEADER_BOUNTY</Tag>
        <English>We have gained 500 gold in ransom from the Barbarian Leader!</English>
    </TEXT>

P.S.-- Now that I think about it, the barbarian leader cash reward in Civ2 may have been something I added, too :mischief:
 
Back
Top Bottom