1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

[Python] zUnit Enslavement

Discussion in 'Civ4 - Mod Components' started by Zebra 9, Jan 31, 2007.

  1. Zebra 9

    Zebra 9 Emperor

    Joined:
    May 17, 2006
    Messages:
    1,554
    Location:
    Middle of Cyberspace
    zUnit Enslavement v0.21

    Patch Compatibility: 1.61, 2.00, 2.08 (All Versions Of Civ 4 That Are worth Haveing)
    Multiplayer Compatiblity: Not tested but should work

    Description:
    A basic Python component that allows you to set any number of units to enslave any
    unit at any chance that you want. I made every attempt to make it as user friendly
    as possible and I belive that anyone how has at least read the first 2-3 pages of any
    good Python tutorial should be able to use it.

    Usage:
    I have defined 3 basic functions to allow the user to interact with the Python
    classes I created. I'm not going in depth here (I provided documentation) but the 3
    functions that I defined allow you to set data on unit classes & unit types, as well
    one that allows you to set a land and sea unit type for enslavement by any unit.:king:

    Here are the instructions for instaling as a MOD:
    1) Unzip into "My Documents\My Games\Warlords\MODS".
    2) Load the game.
    3) Click on "Advanced"-->"Load A MOD"-->"zUnitEnslavement", the Game will restart.
    4) Now you can play as normal. :goodjob:

    Instaling into a MOD takes only about 5 lines of code and copying a file into the
    python directory.

    Things Changed In v0.21:
    Fixed the tech bug that prevented you from enslaveing under certain circumstances

    Things Changed In v0.2:
    I fixed a misspelling (thanks to strategyonly for pointing this out).
    I added prerequisite and obsoleteing technology options.
    I added new functions that allow you to set Land and Sea units seperatly or you can still use the setAllEnslave.
    Changed the math after realizing that 0% actually meant 1% that is now fixed so 0% is 0%.

    Credits:
    Well I did the whole thing but I would like to thank strategyonly for asking me to
    make this for him.

    Located Here:)
     
  2. Edgecrusher

    Edgecrusher King

    Joined:
    Aug 7, 2006
    Messages:
    915
    Location:
    Massachusetts
    I had a question about this mode.

    I created a unit called "Javelineer", and I want it to enslave other units into workers.

    If I define it as this:

    self.addUnitClass("UNITCLASS_JAVELINEER", "UNIT_WORKER", 25)

    does the Javelineer have a 25% chance to enslave just workers, or a 25% chance to enslave any unit it defeats as a worker (much like the effect in civ3)
     
  3. strategyonly

    strategyonly C2C Supreme Commander

    Joined:
    Mar 13, 2006
    Messages:
    20,558
    Gender:
    Male
    Location:
    MN
    I have this already in my MOD and its GREAT, THX!! Everything i asked for i want generic so others could use it and not just one MOD and the README file is VERY VERY good, explains everything.
     
  4. Zebra 9

    Zebra 9 Emperor

    Joined:
    May 17, 2006
    Messages:
    1,554
    Location:
    Middle of Cyberspace
    Edgecrusher
    It would give the Javelineer a 25% chance of enslaving a worker no matter what unit it fights. Actually that might not be a bad idea to allow you to set a list of units that you can enslave from.:goodjob:

    Fixed a new bug! I'm a dope! This will not affect anything that you have already done!
     
  5. Edgecrusher

    Edgecrusher King

    Joined:
    Aug 7, 2006
    Messages:
    915
    Location:
    Massachusetts
    Just wondering.

    I set it to 100% and started to attack, just to get it to work. I must be missing something becuase I havent been able to solve it yet.

    This is my first attemt at editing Python and am using this to learn some basics. So not being able to work wasn't unexpected.
     
  6. strategyonly

    strategyonly C2C Supreme Commander

    Joined:
    Mar 13, 2006
    Messages:
    20,558
    Gender:
    Male
    Location:
    MN

    What did you attempt to do: post code?
     
  7. Infantry#14

    Infantry#14 Emperor

    Joined:
    Dec 26, 2006
    Messages:
    1,580
    does enslaving apply to barbarin animals?
     
  8. Zebra 9

    Zebra 9 Emperor

    Joined:
    May 17, 2006
    Messages:
    1,554
    Location:
    Middle of Cyberspace
    It applies to everything. In the future I want to make it so you have a more control over what you enslave from.

    Edgecrusher could you post the code you put after the line that sayes
    def __init__(self):​
    .
     
  9. Edgecrusher

    Edgecrusher King

    Joined:
    Aug 7, 2006
    Messages:
    915
    Location:
    Massachusetts
    I thought I was following the directions you had provided Here is what i did.

    I edited the CvEventManager file. At the top I put this line of code.

    from CvPythonExtensions import *
    from zUnitEnslavement import *

    A little bit down, after #globals I put
    PHP:
    [B]class enslave(enslavement):
        
    def __init__(self):
            
    self.addUnitType("UNIT_JAVELINEER"UNITCLASS_WORKER100)[/B]
    I skipped down and under the def onCombatResult section I put just this

    PHP:
        def onCombatResult(selfargsList):
            
    'Combat Result'
            
    pWinner,pLoser argsList
            
            self
    .enslave().doEnslavement(pWinnerpLoserself.enslave())
            
    playerX PyPlayer(pWinner.getOwner())
            
    unitX PyInfo.UnitInfo(pWinner.getUnitType())
            
    playerY PyPlayer(pLoser.getOwner())
            
    unitY PyInfo.UnitInfo(pLoser.getUnitType())
            if (
    not self.__LOG_COMBAT):
                return
            if 
    playerX and playerX and unitX and playerY:
                
    CvUtil.pyPrint('Player %d Civilization %s Unit %s has defeated Player %d Civilization %s Unit %s' 
                    
    %(playerX.getID(), playerX.getCivilizationName(), unitX.getDescription(), 
                    
    playerY.getID(), playerY.getCivilizationName(), unitY.getDescription()))

    Anyway I havent been home to play with it in a bit. Tomorrow I will have some time. I appreciate any help you can give. but like I said, I'm learning.
     
  10. strategyonly

    strategyonly C2C Supreme Commander

    Joined:
    Mar 13, 2006
    Messages:
    20,558
    Gender:
    Male
    Location:
    MN
    answer was answered and deleted.:blush:
     
  11. Zebra 9

    Zebra 9 Emperor

    Joined:
    May 17, 2006
    Messages:
    1,554
    Location:
    Middle of Cyberspace
    Strategyonly I don't see anything wrong with your code. The only thing I can think might be wrong is that maybe the unit class for A1 is diferent than A2 (See below image), this could be anj oversight or a misspelling.

    Edgecrusher I will test your code and let you know.
     

    Attached Files:

  12. Edgecrusher

    Edgecrusher King

    Joined:
    Aug 7, 2006
    Messages:
    915
    Location:
    Massachusetts
    class enslave(enslavement):
    def __init__(self):
    self.setAllEnslave("UNIT_WORKER", None, 100, 0) #Remove This When You add Your Own Code
    self.addUnitClass("UNITCLASS_ARCHER", "UNIT_ARCHER", 100)
    self.addUnitClass("UNITCLASS_MACEMAN", "UNIT_WARRIOR", 100)
    self.addUnitClass("UNITCLASS_TANK", "UNIT_MACEMAN", 100)

    Strategy, Im wondering, Was it because of the bolded sections?

    The 2 lines of code, If I am interpreting it correctly, self.AllEnslave, makes all units enslave workers.

    then the self.addunitclass line is making it so all archers create an archer.

    So in a sense, the archer is getting the ability to enslave an archer and a worker?
     
  13. Zebra 9

    Zebra 9 Emperor

    Joined:
    May 17, 2006
    Messages:
    1,554
    Location:
    Middle of Cyberspace
    No the addUnitClass overides the setAllEnslave. His archer would only enslave an archer and never a worker. His problem is most likely in the unitinfos.xml, the unit class is wrong on A2 (see my above post).
     
  14. strategyonly

    strategyonly C2C Supreme Commander

    Joined:
    Mar 13, 2006
    Messages:
    20,558
    Gender:
    Male
    Location:
    MN
    Yeppers your right, i had one as a LONGBOWMAN Archer and the other just as an Archer, DUH!!!
     
  15. Zebra 9

    Zebra 9 Emperor

    Joined:
    May 17, 2006
    Messages:
    1,554
    Location:
    Middle of Cyberspace
    Edgecrusher I found your problem.
    Right now you have:
    Code:
    class enslave(enslavement):
        def __init__(self):
            self.addUnitType("UNIT_JAVELINEER", [B]UNITCLASS_WORKER[/B], 100)
    
    You need to put quotes on both sides of UNITCLASS_WORKER, so it would look like:
    Code:
    class enslave(enslavement):
        def __init__(self):
            self.addUnitType("UNIT_JAVELINEER", [B]"UNITCLASS_WORKER"[/B], 100)
    
    If you use this code it should work!:goodjob:
     
  16. Edgecrusher

    Edgecrusher King

    Joined:
    Aug 7, 2006
    Messages:
    915
    Location:
    Massachusetts
    thanks for your help.

    Im trying to understand what the code does, not just mindlessly copying/pasteing.
     
  17. Portus

    Portus Warlord

    Joined:
    May 17, 2005
    Messages:
    121
    Hi :)
    Its possible to add a civic prerequesit, for exemple only in slavery civic it can enslave.
    Maybe possibility to choose civicXORcivicY if we want POW in later eras.
     
  18. Fabrysse

    Fabrysse Charming-snake learner

    Joined:
    Sep 11, 2006
    Messages:
    430
    Location:
    Toulouse - France
    Hi,
    I plan to use this ModComp in my future Spain 1936 for BtS Mod (with credits given to :bowdown: Zebra 9, of course).

    So I had to add few modifications to render it BtS compatible. It's done (it was really a little job : only the "initUnit" to change...:p ).
    While modifiing, I added too the possibility to translate the Mod. And I translated it into French. :D
    NB: German, Italian and Spanish versions actually return english text, but you just have to modify the xml file to add these languages. :goodjob:

    @Zebra 9 :
    Spoiler :

    I let you add the file to the database : it's still your Mod, no credit for me, here.
     

    Attached Files:

  19. Zebra 9

    Zebra 9 Emperor

    Joined:
    May 17, 2006
    Messages:
    1,554
    Location:
    Middle of Cyberspace
    AJust added your BtS update, thanks. :thumbsup:
     
  20. frekk

    frekk Scourge of St. Lawrence

    Joined:
    Jun 21, 2003
    Messages:
    3,151
    Location:
    Kingston, Ontario
    edited. Never mind, I figured it out!!
     

Share This Page