Requesting Python Help

MaxAstro

Spiral Knight
Joined
Dec 18, 2007
Messages
645
I'm trying to make a unit that steals weapon promotions from enemies it defeats, using PyPostCombatWon. I've got what should be a working block of python written out for it. However, for some reason, it causes the unit to automatically gain Mithril weapons after any fight, regardless of the enemy's weapon promotions. Can someone look at this code and tell me what I am doing wrong?

Code:
def postCombatScavenge(pCaster, pOpponent):
        bScavenged = False
	if pOpponent.isHasPromotion(gc.getInfoTypeForString('PROMOTION_BRONZE_WEAPONS')):
                if ((pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_BRONZE_WEAPONS')) == False) and (pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_IRON_WEAPONS')) == False) and (pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_MITHRIL_WEAPONS')) == False)):
                        pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_BRONZE_WEAPONS'), True)
                        bScavenged = True
	if pOpponent.isHasPromotion(gc.getInfoTypeForString('PROMOTION_IRON_WEAPONS')):
                if  ((pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_IRON_WEAPONS')) == False) and (pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_MITHRIL_WEAPONS')) == False)):
                        pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_IRON_WEAPONS'), True)
                        bScavenged = True
	if pOpponent.isHasPromotion(gc.getInfoTypeForString('PROMOTION_MIRTHIL_WEAPONS')):
                if (pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_MITHRIL_WEAPONS')) == False):
                        pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MITHRIL_WEAPONS'), True)
                        bScavenged = True
	if pOpponent.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ENCHANTED_BLADE')):
                if (pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ENCHANTED_BLADE')) == False):
                        pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENCHANTED_BLADE'), True)
                        bScavenged = True
        if bScavenged:
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_SCAVENGER", ()),'',1,'Art/Interface/Buttons/Promotions/Enchantedblade.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)
 
if pOpponent.isHasPromotion(gc.getInfoTypeForString('PROMOTION_MIRTHIL_WEAPONS')):

I've seen typos such as that to cause weird things... try starting there. (Mirthil instead of Mithril).
 
Honestly it looks like it should work to me. Though you don't have it remove the lower weapon promotions, so it would seem you could get multiple weapon types this way. But Mimic doesn't have anything to handle that so maybe they automatically overwrite one another.

EDIT: Nice catch Mooo.
 
Okay, that does explain it. *bonks self on head* I figured it was something stupid like that, thanks.
 
I believe I've heard that mimics often do get multiple weapons promotions at once. Both of these should be edited.

I suspected a spelling error, but I kept overlooking it.


I'll probably borrow this in my modmod. Since I'm using the DLL Grey Fox made, I'll apply this to a promotion that I'll give to all Doviello Units. (I might use the winterborn promotion but add a check to make sure it is a non-animal Doviello, or I might make a new promotion. Hmm...maybe it would be good to add a scavenger trait that gives this promotion, and maybe let orks purchase the promotion too.)
 
Magi, for your modmod you ought to make it pop up a screen to ask if you want to switch to the new weapon, since you are planning to create so many more weapons and there won't be any clear order of power (A > B > C > D > E), but rather tradeoffs which might leave you inclined to desire keeping what you have instead of taking what they were using.
 
Yep, I did have to add a check to prevent multiple weapon promotions, and Mimics can get multiple weapons... I'll report this in the bug thread.
 
Maybe. Of course, I don't know how to make pop-ups yet :( I should probably learn eventually though


Actually, I was thinking I'd implement them as "quasi-equipment"; there would be an equipment unit for each weapon that allows spells to get the weapons promotion (and drop the equipment unit for the current weapon promotion), but these would only ever appear if the unit is defeated by a Doviello, and only the Doviello could use these spells.


For the most part there will be an order, just not quite as rigid. Getting weapons will normally be through a spell that costs gold. I'll probably make it so that you also have to "pawn your weapons" (through another spell or spells that give you a fraction of the cost back) before getting another one . Better weapons tend to cost more. Mithril will still be the best, but also be very expensive. Bronze and Iron will be equal in strength, but Bronze is costly and Iron is chea. You can get the (fairly expensive) copper weapons, which are weaker, with just the copper resource (which you can get at mining) with no building requirement. Bronze Weapons would require copper (if I decide to add tin you might need this too, but then the weapons cost would decrease), the Bronze Working tech, and maybe a forge. Iron Weapons would need Iron Working and a forge. Dwarven Steel would require a Dwarven Smithy, Iron Working, and Iron, and be stronger than but the same cost as iron and be pawned for more. (If I was willing to make these spells use python I'd probably make the spell cheaper in Khazad Cities.) (These spells require a city, not your city, so open borders can be useful.) Mithril Weapons would be the most costly, require mithril, a forge (or maybe a new, later building), and Mithril Working. Galvorn Weapons will have a more moderate cost, require Rage, require iron, Require the new Dark Forge of Eol wonder, and be stronger of the offense (but not defense) than Mithril, and maybe sometimes drive the units insane. Silver weapons would be relatively expensive and good vs werewolves (and maybe vampires)

Some weapons (copper, iron, silver) may corrode randomly, others only from the rust spell (Bronze and Dwarven Steel), and some (Mithril & Galvorn) not at all (these units would be immune to rust).

There might be RoK spells that can get you weapons promotions more easily (perhaps forging the appropriate weapons directly atop the proper mines, at a reduced cost), and the Mines of Galdur will provide 1 copper, 1 iron, 1 mithril, 1 gold, 1 silver, and 1 gems. (One of the RoK world spells will also create these resources on peaks in your territory, complete with mines/quarries and roads. RoK Priests may also be able to move impassible


There may be some more weapons latter on, so I'll consider switching to popups.
 
Back
Top Bottom