Request for a unit respawning function

cfkane

Emperor
Joined
Feb 7, 2006
Messages
1,196
I could really use a mod component that allowed for a unit to be reborn upon death a finite number of times. I'm not sure how you could program it, but I suspect a python function could handle it, or even as a series of XML and python events that could bring the unit back a certain number of times.

Could it be done?
 
It can be done, there's something like that in FfH2.
I've tried it, but my code doesn't work, my python is not very good, more trial & error than real programming.

Maybe an other modder can find the problem
Spoiler :
PHP:
	def onUnitKilled(self, argsList):
		'Unit Killed'
		unit, iAttacker = argsList
		player = PyPlayer(unit.getOwner())
		
		pPlayer = gc.getPlayer(unit.getOwner())
		attacker = PyPlayer(iAttacker)
		if (unit==gc.getInfoTypeForString('UNIT_WARRIOR')):
                    for iCity in range(0):
        			pCity = pPlayer.getCity(iCity)
        			iX =pCity.getX()
        			iY = pCity.getY()
			
        			pNewUnit = pPlayer.initUnit('UNIT_WARRIOR', iX, iY, UnitAITypes.UNITAI_EXPLORE, DirectionTypes.NO_DIRECTION )
		if (not self.__LOG_UNITKILLED):
			return
		CvUtil.pyPrint('Player %d Civilization %s Unit %s was killed by Player %d' 
			%(player.getID(), player.getCivilizationName(), PyInfo.UnitInfo(unit.getUnitType()).getDescription(), attacker.getID()))

I think it has to be an really stupid mistake, but i don't see it.
 
Okay, very simpel, but works.

I've modified the CvEventManager.py, and i've changed
Code:
	def onUnitKilled(self, argsList):
		'Unit Killed'
		unit, iAttacker = argsList
		iPlayer = unit.getOwner()
		player = PyPlayer(iPlayer)
		attacker = PyPlayer(iAttacker)
###respawnbeginn###
		pPlayer = gc.getPlayer(iPlayer)
		if (unit is not None and unit.getUnitType() == gc.getInfoTypeForString('UNIT_WARRIOR')):
                        for iCity in range(1):
        			pCity = pPlayer.getCity(iCity)
        			iX =pCity.getX()
        			iY = pCity.getY()
        			u_newunit = gc.getInfoTypeForString( 'UNIT_WARRIOR' )
			
        			pNewUnit = pPlayer.initUnit(u_newunit, iX, iY, UnitAITypes.UNITAI_EXPLORE, DirectionTypes.NO_DIRECTION )
###respawnend###

If you haven't modified your CvEventManager.py, just create the Fictionalization\assets\python\ folder and add CvEventManager.py (file is attached).
If you have already modified it, you know, what to do.

At the moment, like you see, it is checked, if UNIT_WARRIOR is killed, and if it is, a new warrior is spawned in your first city. Replace the two UNIT_WARRIOR with whatever you like.
If you want more units to respawn, just copy all between ###respawnbegin### and ###respawnend### and change the units.

I don't know, how to add the promotions from the killed unit, sorry.
I think, the should ask the question in the python-subforum again.


edit:
Credits go to tsentom1 and FfH2-coding-team, because i've stolen code-parts from them.
Also credits go to EmperorFool, for his advice.

Problems:
Game will crash, if a unit is killed, and the unit-owner doesn't have a city (but no problems with barbarians).
 

Attachments

Thanks!

One thing I was thinking about... is there any way this function could be tied to a promotion? So if the unit has "Six Lives" or something like that, it would get killed and come back with the promotion "Five Lives" and so on until it runs out.

And while I'm thinking of it, if a unit is consumed by an act, like a Great Person researching a technology, does that count as a unit being killed or lost?
 
I think, it can be done, because something like this is in Ffh (but done in the sdk, if i'm right), but i don't know, if i can do it.
Maybe i can steal some code from tsentoms promotions, to get it work (if i have some time).

Great Persons: FfH2 has also a "bug", that GPs with the "immortal"-promotion are re-born, if they are used, so it is, like they are killed.

Maybe i can have a look at it tomorrow.
 
Well my survivor promotion basically is a re-spawn on death just tied to percentage chance instead of of number of times:

http://forums.civfanatics.com/downloads.php?do=file&id=11655

Although kinda sloppy, the easiest way for it to be a set number instead of chance would be to have a promotion for each life, and upon respawn check which promotion it has and replace it with one lower life. So Have Life 1, Life 2, Life 3 all with the code. When it gets to the last life it will just remove all the promotions all together.

Otherwise you need to do several checks, maybe even a net message to prevent OOS--I'd have to go look through the function again to see if this is the case--if you want to game to keep 'track' of the lives itself.
 
Yes, i've seen it....after 2 hours of copy and paste, to get a check for every promotion :wallbash::wallbash::wallbash:.
This could have been done in much lesser time :wallbash: :wallbash::wallbash:.

But i don't know, how to remove an promotion. If i can figure it out (or someone else), i'll try a version with a better code.

In my code, a new unit is created, and it get's all the old promotions, besides the one with the additional "life".

attachment.php


attachment.php


I've added two new promotions, respawn1+2 (i've seen a heart-button, but couldn't find it).
Respawn1 needs combat5 and (medic2 or drill4), respawn2 need respawn1 (but that's the easiest to change).
When a unit is killed, it is checked, if it has one of the both promotions, and if yes, a new unit is created, which gets all the promotions, the old one had.
But i don't know, how to check for the experience. Also generals can't be transfered :(.
This would be no problem with tsentoms code, but, like i said, i don't know how to remove a promotion :(.


Credits, for the current version:
- Tsentom1, i've stolen some code from the field-medic-promotion
- and FK2006 for the buttons (i think, they are from him).
 

Attachments

  • respawn.zip
    respawn.zip
    23 KB · Views: 48
  • Civ4ScreenShot0103.JPG
    Civ4ScreenShot0103.JPG
    126 KB · Views: 102
  • Civ4ScreenShot0105.JPG
    Civ4ScreenShot0105.JPG
    137.1 KB · Views: 110
Code:
pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_COMBAT1'), False)
Should remove a specific promotion.

I say should, because I don't think I've ever actually used it. Though, that's how you remove buildings and stuff so it follows the same logic.
 
Here is the thread, here the download.


If you have a wish for a customisation, just say it :).


Credits go, like already said, to tsentom1, this time for the survival-promotion and his help, and FK2006 for the buttons.


Code:
pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_COMBAT1'), False)
Should remove a specific promotion.

I say should, because I don't think I've ever actually used it. Though, that's how you remove buildings and stuff so it follows the same logic.

Works, like you see :goodjob:.
 
Back
Top Bottom