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

Introducing: PyScenario - easy-to-use scenario event scripting for RFC

Discussion in 'Rhye's and Fall Modmods' started by Baldyr, May 16, 2010.

  1. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    No, unfortunately not.
     
  2. Baron03

    Baron03 Baron

    Joined:
    Nov 7, 2010
    Messages:
    254
    Can I use pyscenario (if not, anything else?) to make an RFC mod from scratch? And if so how do I apply the py data to the custom map I made?
     
  3. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Baron03, no you can't. You need to learn proper Python for that. But thankfully its not very hard - see my signature below for some obvious entry points.
     
  4. BenZL43

    BenZL43 awkward cat

    Joined:
    Sep 25, 2010
    Messages:
    3,199
    Gender:
    Male
    Location:
    Indonesia
    Where can I get info for like Russia is player(27) or China is player(2) ? And info for Market is buildings(59) ?

    Thanks :)
     
  5. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Rhye stores all the constants in the Consts.py file. Everything that is BtS standards can also be found here.
     
  6. LuKo

    LuKo The Royal Guard

    Joined:
    Aug 28, 2006
    Messages:
    1,501
    Location:
    Poland
    I have a request: can you add to captured() something like: bByPlayer=None (which triggers regardless of who captured the unit, True for player in the trigger [so just like it is n ow] and False if player in trigger was an owner of the captured unit)?
     
  7. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    LuKo, I'm not currently developing PyScenario due to not having a proper home. (I'm redecorating.) If you prompt me at a later date (like this summer or whatever) I would probably pick this PyScenario thing up once again, since there still is interest in the application.
     
  8. LuKo

    LuKo The Royal Guard

    Joined:
    Aug 28, 2006
    Messages:
    1,501
    Location:
    Poland
  9. Bonci

    Bonci King

    Joined:
    Oct 22, 2005
    Messages:
    738
    Location:
    Tridentum - Italia
    I'm trying to add a functionality to my pyscenario but i can't understand very well how it works.
    I want to add the prob(iProb) function that fires the trigger randomly with an iProb probability.

    So i added the following code to Pyscenario.py

    Code:
    import random
    
            def prob(self, iProb):
                    self.Conditions.appendEntry(CheckRandom(iProb))
                    return self
    
    class CheckRandom(Conditions):
    
            def __init__(self, iProb):
                    self.prob = iProb
                    self.notTurnTrigger = None
    
            def check(self, pContext):
                    #pContext.debug(("CheckFired.check()", self.binding, self.fired), {})
                    #if random.random()*100<self.iProb:
                    return random.random()*100<self.iProb
                    #else:
                            #return False
    
    
    now...i don't get errors...but if i write
    Code:
    Trigger().player(iEgypt).date(-2990).check(True,False).message("ROFLCOPTER").popup(True).prob(100)
    
    it never triggers :(
     
  10. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Did you ever try the interval() method with built-in random turn check?
     
  11. Bonci

    Bonci King

    Joined:
    Oct 22, 2005
    Messages:
    738
    Location:
    Tridentum - Italia
    umm but i want it to fire with a certain probability in one specific turn/year...not to fire in a random interval of turns.
    Can I do it with that method?
     
  12. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Try using both date() and interval(). My reasoning is that the first Condition is met only at the desired date, while the second has a random chance of that game turn being valid.

    It was a while since I lastly looked at this stuff myself, so I'm trying to traceback my own thinking here. :D
     
  13. BenZL43

    BenZL43 awkward cat

    Joined:
    Sep 25, 2010
    Messages:
    3,199
    Gender:
    Male
    Location:
    Indonesia
    Could you make so Dynamic Civ names is changeable via PyScenario?
     
  14. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Those are done in C++, while PyScenario is a Python module. PyScenario doens't ship with a new DLL file, and never will.

    I might, however, make another scenario making tool in C++ one day. Not this year, though.
     
  15. BenZL43

    BenZL43 awkward cat

    Joined:
    Sep 25, 2010
    Messages:
    3,199
    Gender:
    Male
    Location:
    Indonesia
    Okay..
    will be looking forward to the C++ Scenario tool if one day you make it ;)

    Some questions.
    How do I spawn a independent city that mustn't belong to any AI before a coded turn?

    Some requests.
    Will you add some example how to flip a cities, in the front page? I'm a bit confused.
    Please do teach me how to flip cities from AI to Player, AI to minor, Minor to AI, all vice versa :D

    Big Thanks!
    P.S : I'm having unknown error with the Google Talk installation.
     
  16. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    You mean that you need one Trigger for spawning the city, and then another one that automatically flips it back to a minor player if acquired by a major player?

    As with any PyScenario event you need to define a Trigger for it. Each Trigger has a Target Player and a Target Tile. For flipping cities you use the flip() method. From the API:
    So flipping London to the English on AD 900 you would go:
    Code:
    Trigger("flip London").date(900).flip("London",iEngland)
    There are additional parameters you could use; restricting the flip to minor players only or restricting the flip to AI players only, or to safeguard the current owner from collapse due to the flip. These are all enabled (True) by default, but can easily be disabled (False), like this:
    Code:
    Trigger("flip London").date(900).flip("London",iEngland,False,False,False)
    Now London will flip regardless of who owns it (minor/major or AI/human) and the previous owner isn't protected from collapse.

    Note however that the dynamic city names (or player named cities) will disable the flip. If you wanna flip any city on the London tile (regardless of its actual name), then you can define a Map Target instead. Look in the documentation for the various ways of defining one. The important thing is to set the name parameter to a None value, which disables it. An example:
    Code:
    Trigger("flip London").target(53,54).date(900).flip(None,iEngland)
    You could do this also, because then the flip() method will simply use all the default parameters:
    Code:
    Trigger("flip London").target(53,54).player(iEngland).date(900).flip()
    This is a good example of how to build your Triggers; Firstly you name it (optional), then you define a map target, and a player target, then some Condition method(s) and finally you use a Action method (or several).
     
  17. BenZL43

    BenZL43 awkward cat

    Joined:
    Sep 25, 2010
    Messages:
    3,199
    Gender:
    Male
    Location:
    Indonesia
    Yeah..
    Not just back to minor, any AI major city conquered by any another AI Major before the rightful time should be returned automatically to prevent unhistorical event...

    So, if I want to flip a city (27,38) that belong to any (major,minor,etc) to Inca civilization, at 728AD, the code simply goes like this?

    Code:
    Trigger("flip Example").target(27,38).player(iInca).date(728).flip()
    
    How do I activate the bSafe=True if the player owning (27,38) at 728 is a Major Civs?
     
  18. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    So you wanna script the whole game? I don't think PyScenario is the easiest way to achieve this...

    No, because the default settings of flip() are:
    Those True values mean that only minor Civs are allowed, and only AI Civs. What you wanna do is set those parameters to False:
    Code:
    Trigger("flip Example").target(27,38).player(iInca).date(728).flip(bMinorsOnly=False, bAIOnly=False)
    There seems to be no support for this sort of thing. But if you learn Python scripting for real, then you'll be able to do whatever you want. It would be less work for you than it would be for me to rewrite the application.
     
  19. BenZL43

    BenZL43 awkward cat

    Joined:
    Sep 25, 2010
    Messages:
    3,199
    Gender:
    Male
    Location:
    Indonesia
    I'm currently learning Python from your signature, etc..
    Slow but sure ;)

    Okay thanks for the code fix..
    Oh, and never mind the rest..

    EDIT

    Baldyr,
    when the screen show No Valid Scenario Module found, is that mean there's something wrong with Scenario.py only or there's might be something wrong with the CvRFCEventHandler.py or PyScenario.py as well?
    I was playing with CvRFCEventHandler a bit..
    But the game is not crashing =_=
     
  20. Baldyr

    Baldyr "Hit It"

    Joined:
    Dec 5, 2009
    Messages:
    5,530
    Location:
    Sweden
    Ok, I'm finally ready to continue work on PyScenario. I have about a one month window for programming/modding and after that I may not get another chance. (I will be technically home-less for a while and my desktop computer will be stored away.)

    As soon as I can muster the focus I'll start compiling a to-do-list for what needs to be done for the next (final?) version. This would also be the time to remind me of what needs to be added/fixed - and to put forward new requests. Hopefully I will get something finished during next week, but no promises.
     

Share This Page