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

Modding XP

Discussion in 'Civ4 - Creation & Customization' started by Telecide, Nov 3, 2005.

  1. Telecide

    Telecide Chieftain

    Joined:
    Oct 28, 2005
    Messages:
    29
    So in the manual, as an illustration of what python could do, it's suggested that you could make a script that gives a unit experience whenever it enters a particular square. I think that would be a cool thing to do. But I can't find anything referring to experience in any of the python files. Anyone know how you might go about doing this? :confused:
     
  2. snarko

    snarko DLLer

    Joined:
    Dec 9, 2003
    Messages:
    1,512
    Location:
    Sweden
    Goody huts give XP... that can problably be used. But I can't figure out how. If you do, post how to do it.
     
  3. c.fe

    c.fe Warlord

    Joined:
    Sep 20, 2003
    Messages:
    133
    Location:
    Germany
    You have to inherit from CvEventManager like it is (for example) done in CvAmRevEvents.py in the American Revolution Scenario.

    There overwrite the method onUnitMove other methods shouldn't be necessary. In this method argsList[1] seems to refer to the unit that has been moved. On this you can call all methods mentioned here (http://civilization4.net/files/modding/PythonAPI/AllClasses.html#CyUnit) especially getX(), getY(), setExperience(int, int).

    I hope this helps to get some research going on. If not - ask again.
     
  4. snarko

    snarko DLLer

    Joined:
    Dec 9, 2003
    Messages:
    1,512
    Location:
    Sweden
    I looked in the python api, but since the link to CyUnit doesn't work and it was in bold in the index I figured it wasn't included... guess I should've looked closer.

    Well, thanks for the help, it works.

    edit:
    There's also changeExperience(int, int). Don't know the diffrence since I haven't tried it. Perhaps experience can't go down if you use that? It can if you use set.
     
  5. c.fe

    c.fe Warlord

    Joined:
    Sep 20, 2003
    Messages:
    133
    Location:
    Germany
    Good to hear that. :)

    No idea about that one.
     
  6. Telecide

    Telecide Chieftain

    Joined:
    Oct 28, 2005
    Messages:
    29
    Thanks guys! Still not sure how to do this, but now I'm a whole lot closer. :)
     
  7. Jon Shafer

    Jon Shafer Civilization 5 Designer

    Joined:
    Jul 14, 2002
    Messages:
    2,102
    Location:
    Maryland
    My American Revolution scenario is a good reference to base one's mods off of (and Desert War too, I suppose ;)). It has a lot of examples of things like this (though some are more complicated than others).
     
  8. Jon Shafer

    Jon Shafer Civilization 5 Designer

    Joined:
    Jul 14, 2002
    Messages:
    2,102
    Location:
    Maryland
    To be more specific:

    onUnitMove() is definitely the function you need in this case. For your mod you want your own custom CvEventManager.py file and change that function.

    Inside of there right now all it does is unpack the arguments passed into the function into things we can understand (like pPlot and pUnit) and prints out the fact that the unit moved.

    pPlot and pUnit are objects which have their own functions that can be called. To identify the plot (aka Tile or Square, though "Plot" is the correct term) you can get the X and Y coordinates by calling pPlot.getX() and pPlot.getY(). You could say something like:

    Code:
    if (pPlot.getX() == 10 and pPlot.getY() == 5):
            blah
    "blah" being the code you want to execute if the plot matches what you're looking for. In this case we want to give the unit experience, which is pretty easy to do. We can just call the changeExperience() function on the pUnit object we have.

    Code:
    if (pPlot.getX() == 10 and pPlot.getY() == 5):
            pUnit.changeExperience(10,100)
    I'm not exactly sure on what all the arguments are but I'm fairly confident the first one is how much experience you're adding (or subtracting, in the case of a negative number) to the unit and the second is the MAXIMUM value it can have. I believe this is used when fighting Animal and Barbarian units since you can get a max of 5 and 10 against them, respectively.

    And that's it. Only a two-line change to get the XP mod working. :)
     
  9. Telecide

    Telecide Chieftain

    Joined:
    Oct 28, 2005
    Messages:
    29

    Awesome! This probably would have taken a lot longer to figure out than I thought.
     
  10. Telecide

    Telecide Chieftain

    Joined:
    Oct 28, 2005
    Messages:
    29
    Hmm... well I made copy of CvEventManager.py and put it into the custormassests\python folder. I copied and pasted that code at the end of the onUnitMove event and set both coordinates one higher than the starting location of one of the maps. I figure that should be down and to the right. No luck yet though... :(

    I'm kinda new to this python stuff.
     
  11. Jon Shafer

    Jon Shafer Civilization 5 Designer

    Joined:
    Jul 14, 2002
    Messages:
    2,102
    Location:
    Maryland
    If you hold down SHIFT and hover your cursor over a plot it will give you the X and Y coordinates. May need to set the cheat code for that but I'm not sure.
     
  12. c.fe

    c.fe Warlord

    Joined:
    Sep 20, 2003
    Messages:
    133
    Location:
    Germany
    Ah, the man who made the mod I gained my knowledge from :D .

    2 questions:

    1. Why did you make a subclass of CvEventManager? To make the code smaller? To retain the debug output?

    2. When I tried to imitate your event-handling-stuff I first got strange loading errors until (so it seemed to me) I gave the file/class the prefix Cv... . Is this really needed or was this some different error in disguise?

    Thanks.
     
  13. Telecide

    Telecide Chieftain

    Joined:
    Oct 28, 2005
    Messages:
    29
    Finally figured it out. I put the code in after the return function so it was never being run. Works like a charm now. :) It looks like the second number in parameter of the changeExperience method is the max one unit can get from that particular plot.
     

Share This Page