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

PyScenario: Beta version release

Discussion in 'Rhye's and Fall Modmods' started by Baldyr, Jun 2, 2010.

  1. LuKo

    LuKo The Royal Guard

    Joined:
    Aug 28, 2006
    Messages:
    1,501
    Location:
    Poland
    My main point is to help you to unable someone to create a great scenario (because my skills aren't perfect and I prefer to play someone's else mod if it's better than mine). :)

    This is the code I'm currently using (or I would if I reinstall cIV).
     
  2. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    I just found a bug with spawning cities next to rivers! It will be fixed in the next update, probably due in some week or so. :rolleyes:

    edit: Is it normal for Floodplains to disappear when cities are founded? :confused:
     
  3. LuKo

    LuKo The Royal Guard

    Joined:
    Aug 28, 2006
    Messages:
    1,501
    Location:
    Poland
    So my code should be sth like:
    Code:
    if bAlive == True and iStability <= -20:
        if iNumCities >= 2 and iNumUnits >= 2:
            (then iStability + 20 and pCity.changeBaseYieldRate(2, self.commerce) - 2)
        elif iNumCities >= 6 and iNumUnits >= 5:
            (then iStability + 20 and pCity.changeBaseYieldRate(2, self.commerce) - 2)
        elif iNumCities >= 11 and iNumUnits >= 12:
            (then iStability + 20 and pCity.changeBaseYieldRate(2, self.commerce) - 2)
        elif iNumCities >= 21 and iNumUnits >= 25:
            (then iStability + 20 and pCity.changeBaseYieldRate(2, self.commerce) - 2)
        elif iNumCities >= 21 and iNumUnits >= 35:
            (then iStability + 20 and pCity.changeBaseYieldRate(2, self.commerce) - 2)
    
    ?
     
  4. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Oh, this is probably not the right place to discuss stability modding. :rolleyes:

    But here goes:
    Spoiler :
    I added the (then) lines just to illustrate that there should be some code (a block of code) after each if/elif statement. So you don't actually need the parenthesis and the "then" is not defined anywhere so it would cause an exception.

    Other than that, you would have to fix indentation and indentation-levels (which are used to organize code into blocks). My example code used 4 blank-spaces for each level, but Rhye's code uses 8 instances. It needs to match perfectly or it won't work.

    Also, I didn't bother with defining the variables I used in my example:
    Code:
    bAlive = gc.getPlayer(iPlayer).isAlive()
    iStability = self.getStability(iPlayer)
    iNumCities = gc.getPlayer(iPlayer).getNumCities()
    Now, since I haven't actually tried any of this myself so I can't rule out that I've missed something.

    Note that you need to implant your Python code into some module other than Scenario.py - preferably the Stability module or a custom module of your own. (The last option would make it easier to actually add the code, as there would be no pre-existing code to match. But it creates the need to connect the module to the Event Handler - or some other module already connected to it.)

    And lastly, you set stability with self.setStability(iPlayer, self.getStability(iPlayer) + 20). And I'm not sure what you wanna do with the CyCity.changeBaseYieldRate() method, but what you are doing now probably doesn't do what you intend it to do.

    In summary, you didn't pick a good entry point for getting into Python modding... :p But if you're interested to go in this direction I could definitely get you started. And you start at the beginning. :D
     
  5. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Anyone looking to get into Python programming for real could follow along this tutorial.
     
  6. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    I finally uploaded the long promised update - available from the first post. It turned out to be a big one as the application is now converted to work with the RFC Epic/Marathon mod-mod instead of the official version. This means that there are two more game speeds available, but the update also includes new and (hopefully) improved features. So be sure to check out the updated documentation!

    As there are far to many last-minute changes and additions I haven't been able to test everything properly. This is why I'm relying on all the beta testers to do give v2 a through testing and to report back any issues. There will be fixes!

    Thank you for your help and support! :king:
     
  7. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    I just found a glaring mistake the unit spawning code (one line of code is missing) that results in a pickling error after a units spawning action has fired. This prevents Triggers from being saved alongside with the game - and also prevents the stored data in the mod being saved. So its pretty bad and a fix is coming shortly in the next update.

    I can't however figure out how this can have gone unnoticed until now. :confused: Has no one really used the units() method with beta version 2.0? Or has no one enabled Python exceptions in their game? (See the first post for details)
     
  8. killerkebab

    killerkebab Prince

    Joined:
    Jun 25, 2009
    Messages:
    571
    I use the units() method with city() to spawn defenders, but I've never noticed any huge problems...
     
  9. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Yeah, this is odd. Because I've done testing myself and never noticed any exceptions. But suddenly they appeared today and I couldn't figure out why. After some head-scratching I noticed that a line was missing in the new code for spawning units. When I added it the errors disappeared, as expected.
     
  10. LuKo

    LuKo The Royal Guard

    Joined:
    Aug 28, 2006
    Messages:
    1,501
    Location:
    Poland
    It's the reason I get "Trigger pickling failed" message when I save the game? Though, everything was working correctly so I didn't report that.
    But the reason I post now is CTD when I kill Hannibal in my scenario. Could the CTD be caused by PyScenario bug (death of Hannibal means cities flipping, units spawning)?
     
  11. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    It sure sounds like it. Since this is beta it would be very helpful if all error were reported. Because they pretty much mean that something isn't working. And we need to get this working.

    I have no idea, but skip Hannibal for now and test your Trigger with the next update. (Should be up this week.) If that doesn't help, then I can take a look at your script and see if I can't duplicate the error.
     
  12. LuKo

    LuKo The Royal Guard

    Joined:
    Aug 28, 2006
    Messages:
    1,501
    Location:
    Poland
    Hannibal worked wit not-Marathon-PyScenario-beta-version :)
    Strange bug, indeed. Is it the reason that:
    Code:
    Trigger("Celticcrusade").player(30).once().owned((60,44),7).units((59,46),37,3).AI("UNITAI_ATTACK").units((60,47),28,2).AI("UNITAI_ATTACK").message(Gaeliccrusade)
    doesn't work and:
    Code:
    Trigger("Celticcrusade").player(30).once().owned((60,44),7).message(Gaeliccrusade)
    Trigger().player(30).fired("Celticcrusade").once().units((59,46),37,3).AI("UNITAI_ATTACK").units((60,47),28,2).AI("UNITAI_ATTACK")
    does work? Or "barbarian-not-razing-holy-cities-fix" not working? Anyway, can't wait for update :)
     
  13. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Lets just wait and see. There is a lot going on with the upcoming version. :p
     
  14. LuKo

    LuKo The Royal Guard

    Joined:
    Aug 28, 2006
    Messages:
    1,501
    Location:
    Poland
    Is it possible to spawn units on ships?
    Code:
    Trigger().player(7).check(None,0).date(-50).units((60,44),29,1).XP(None,50).promotions(43).flag("Gaius Julius Caesar",1).AI("UNITAI_ATTACK").units((60,44),29,3).units((60,44),37,3).units((60,44),57,3).units((60,44),4,3).units((59,44),90,3)
    Above code doesn't do the job for AI. For human player I tested with non-Marathon-beta-version and it worked nicely.
     
  15. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    The problem seems to be that you are spawning units on several different tiles with one single Trigger. This is not longer kosher as the old units() method works differently than the old one. So the rule is: One target player and one map target per Trigger.

    Solution: Divide the event into two or more Triggers.
     
  16. sercer88

    sercer88 Emperor

    Joined:
    Oct 1, 2006
    Messages:
    1,443
    Location:
    MO, USA
    Baldyr you are a life saver, I just remembered one thing I suggested a while back - and nobody was interested :eek: and I don't know how to make it.

    Ok so the basic principle is this:
    It's all based on my perception of razing cities being utterly nonsensible. How can some huge cities be just wiped out - where did all the citizens go? Surely you didn't just burn them with the city?
    So, I proposed giving a small chance for a new town to rise up on a plot that was a cottage (or higher.)
    Chances are increased for each population point in the city razed, and also in order of increased chances: if the plot is cottage, hamlet, village, or town.
    Then, in the pop-up that comes when the event is triggered, you would have a chance to accept the new town (without reinforcement,) accept and reinforce the new town, or just bring the citizens into a nearby town without gaining the new city (add 2 population to the closest city.)

    I worked out all the conditions a while back, and have lost my original calculations, but I could easily work up some new numbers.
    Of course, I would be more than willing to test this out. I think it would be awesome, maybe not - that's what play-testing is for.
    So, can you help me out?
     
  17. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Your proposal isn't PyScenario related, right? Is it even RFC related? I suggest you post it on the main modding forum instead. (Be sure to include all the specifics.)
    I don't currently have time to help you out with any actual code for this. Because you're basically requesting a complete Python mod, right? If you look in my signature there is a link to a Python modding tutorial I wrote a while back when someone requested a Python mod. Because this is something you could learn to do yourself. (PM if you need help getting started. Or just post on the other forum and help should be coming.)
     
  18. sercer88

    sercer88 Emperor

    Joined:
    Oct 1, 2006
    Messages:
    1,443
    Location:
    MO, USA
    uh... good point

    Ok, posting on main modding forum - won't bother you with your time :blush:
     
  19. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    No, I'm sure I can help - as long as you're set on learning how to do this yourself. This is why I wrote the tutorial, after all. :)
     
  20. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    I uploaded the new PyScenario version in the opening post. Note that it should only be used with the current version of RFC Epic/Marathon (v1.21).

    Except the new Trigger methods there are numerous code enhancement that wouldn't be obvious for the user. But it should be easier to use, more reliable - and faster than before. :goodjob:
     

Share This Page