Requesting following features

mmm if I was to use
The CyCity.getCivilizationType() method takes no parameters, so you shouldn't use any. Check with the API. (Are you able to read the API, or are you simply not worrying about not understanding it?)

Also, you haven't defined the name cyCity anywhere. You're using the while command incorrectly. (Its not a conditional statement but used for iteration - looping.) And you can't use elif by itself - you probably need else instead.

You still need to learn more before attempting your own scripts.
 
EDIT: cyCity needs to be defined? as what?

I don't really know how to use the API no... (I thought you read and feel happy about yourself :lol:) So how would you use the cyCity.getCivilizationType() then? (and use it to find the current owner of the city.)

I kinda thought that elif was wrong and that I should be using else but that was when I was not at my computer... does else need to be indented past if or just on it's own underneath?

EDIT2: I don't need else... If I use != instead of == it will work MUCH better
 
btw the first code posted was for my conquor Byzantium prompt to make humans conquor it so the ERE will have more chance of spawning. post 497
Lets just worry about this one later.

The event I am making that you asked me to try and do is triggered on a specific game turn (currently -3800 but will be changed later) and spawns 3 axes on a certain tile (let's call them 0,1 for the moment) and post 498 is related to that
This is pretty straight forward. But you need to know where to start.

Ok, so you wanna make sure that the event only triggers on one single game turn, corresponding to some game date. Firstly add this helper function to your module (we could add it to the Utils module later and simply import it):
Code:
def isDate(iDate):
    return Game.getTurnYear(Game.getGameTurn() +1) > iDate and Game.getGameTurnYear() <= iDate
Don't forget to add this line at the top of the module (after the import statements):
Code:
Game = CyGame()
Now we can effectively and accurately fire the code at any desired game date - and only once. The conditional statement would look like this:
Code:
if isDate(-3800):
But we still need a game event to trigger your code. So we put the whole Spartacus script into a function - so that it can be called from the Event Manager:
Code:
def eventSpartacus():
    if isDate(-3800):
        pass
(The pass statement is there just as a place holder and does nothing.)

Since its a game turn event we wanna call on eventSpartacus() on BeginGameTurn in CvEventManager. If you look at the beginning of the module you see that the callback is mapped to the onBeginGameTurn() method. This is where you put the ModEvents.eventSpartacus() function call.

Note however that you need to import the ModEvents module to CvEventManager to get access to it. This is what I suggest you do (at the bottom of the module):
Code:
def initiateCustomPython():
	if gc.getGame().isFinalInitialized():
		global Powers, Rebellion, Custom, CC[COLOR="Red"], ModEvents[/COLOR]
		import Powers, Rebellion, CustomFeatures as Custom, CatapultConstruction as CC[COLOR="Red"], ModEvents[/COLOR]
		if not Rebellion.getGlobalScriptDict():
			Rebellion.setup()
		CC.load()
		from CvGameUtils import CvGameUtils
		CvGameUtils.powers = Powers
		Custom.gameTurn()
(Scroll to right to see the rest of the code.)

Next up we have to replace the pass statement with the unit spawns. But I think you have enough to chew for now.
 
This is the API entry for the method:
CivilizationType getCivilizationType ()
The color coded stuff at the beginning of the line is the return value of the method. This one returns a CivilizationType value. The "types" are mostly integer values though, but not always. (Not knowing is part of what makes Python modding hard.)

But I guess this method is what you're looking for:
PlayerType getOwner ()
Because it returns the player ID (integer).

Not all method return SomeType values however. There are BOOL methods (returns True/False), STRING (returns a string type), INT (return a integer type) and so on. But you should take special note of the methods labeled VOID - these return a None value and happen to be used for changing various CyClass objects. (Like CyCity instances.) This is where the action is.

Lets take a look at this method, belonging to the CyPlayer class:
CyUnit initUnit (UnitType iIndex, INT iX, INT iY, UnitAIType eUnitAI, DirectionType eFacingDirection)
So the method returns a CyUnit value - a CyUnit instance to be exact. This is actually what a new unit is! (An instance of the CyUnit class, that is.)

It takes 5 parameters, separated by commas. The first one is the Unit Type and as it says "iIndex" after "UnitType" this means that you should feed it a integer value. The second and third parameters (map coordinates) are also integers, as specified by INT. The last two parameters aren't integers however, and you can tell by the lack of anything referring to integers. Instead, eUnitAI and eFacingDirection is specified. (The e is short of enumeration. So its a enumerated value inherited from the SDKs C++ code.)

This last bit makes this particular method almost stupidly complicated to use for beginners, so we're not gonna bother with it in your module. At all. Instead, there is a wrapper method in the PyHelpers module belonging to the PyPlayer class (itself a wrapper for the CyPlayer class). You don't need to worry about how it works though. We'll get to the practical side of this later.
 
ok so I re-re-edited the code and this is what I have so far:

Code:
[COLOR="Orange"]from[/COLOR] CvPythonExtensions [COLOR="orange"]import[/COLOR] *
[COLOR="orange"]from[/COLOR] PyHelpers [COLOR="orange"]import[/COLOR] *
[COLOR="orange"]from[/COLOR] Popup [COLOR="orange"]import[/COLOR] PyPopup


[COLOR="Red"]##Sparticus rebellion##[/COLOR]
iYear = -3800
gc = CyGlobalContext()
eBarbarian = gc.getBARBARIAN_PLAYER()
pyBarbarian = PyPlayer(eBarbarian)
popupHeader = [COLOR="Green"]"Sparticus"[/COLOR]
popupMessage = [COLOR="Green"]"Sparticus has invaded southern Italy as revenge for his cruel mistreatment.\n\n A barbarian army will spawn in sourthern Italy"[/COLOR]
iX = 0
iY = 0
Game = CyGame()
[COLOR="orange"]def[/COLOR] [COLOR="Blue"]showPopup[/COLOR]():
    modPopup = PyPopup()
    modPopup.setHeaderString(popupHeader)
    modPopup.setBodyString(popupMessage)
    modPopup.launch()

[COLOR="orange"]def[/COLOR] [COLOR="blue"]isDate[/COLOR](iDate):
    [COLOR="orange"]return[/COLOR] Game.getTurnYear(Game.getGameTurn() +1) > iDate [COLOR="Orange"]and[/COLOR] Game.getGameTurnYear() <= iDate

[COLOR="orange"]def[/COLOR] [COLOR="blue"]eventSpartacus[/COLOR]():
    [COLOR="orange"]if[/COLOR] isDate(iYear):
        showPopup()

included IDLE colours for your enjoyment!

btw when typing in isDate IDLE turned is orange (just like while or if)... so what does it do on it's own?

EDIT: forgot to add Game = CyGame()
 
ok I think I understand the API a little more... You should definatly add a tutorial on this!
 
This is the PyPlayer.initUnit() method that we will be using (from PyHelpers):
PHP:
	def initUnit(self, unitID, X, Y, iNum = 1):
		"none - spawns unitIdx at X, Y - ALWAYS use default UnitAIType"
		if (iNum > 1): #multiple units
			for i in range(iNum):
				self.player.initUnit(unitID, X, Y, UnitAITypes.NO_UNITAI, DirectionTypes.NO_DIRECTION)
		else:
			return self.player.initUnit(unitID, X, Y, UnitAITypes.NO_UNITAI, DirectionTypes.NO_DIRECTION)
Its API entry could look like this:
VOID / CyUnit ( UnitType unitID, INT X, INT Y, INT iNum=1 )
Firstly we should note that the last parameter is optional, as it is already defined as 1 (as in one unit should be spawned by default). The return value of the method can either be None - with the default iNum value - or a CyUnit instance - that of the spawned unit. Because if we supply the iNum parameter with another value than 1, then there will be several units spawned - meaning several CyUnit instances. But the method doesn't support something like returning a tuple containing the objects of all the newly created units. Unfortunately.

The reason I strongly recommend using this wrapper instead of the CyPlayer variety is firstly that you don't have to worry about UnitAIType and DirectionType values. These are set automatically by the wrapper function. And secondly because of the iNum parameter. There is no reason to call it several times to create multiple units on the same tile. Which is convenient.
 
I'll be back later on more on this. Or tomorrow at the latest.

Its all pretty much covered in my tutorial however, so I suggest continue reading it if you get stuck.
 
nice so for the axemen I would put in
Code:
initUnit(self, unitID, iX, iY, iNum = 3)

iX and iY have both been defined as 0 (see 2 posts ago)

what would I use to tell it to make axemen? and does that go in self or unitID?
 
ok I repaired the Senate code (I know... you said not to worry about it now but I wanted to add it before I forgot) so here it is

Code:
[COLOR="Red"]##Byzantium Senate Prompt##[/COLOR]
iYear = -3800
iEndYear = -3000
popupHeader = [COLOR="Green"]"Senate"[/COLOR]
popupMessage = [COLOR="Green"]"The glorius senate of Rome requests that you take the city of Byzantium. If you take it and hold it at the end of 30 turns (turn X) you will be greatly rewarded"[/COLOR]
iX = 0
iY = 0
Game = CyGame()
[COLOR="Orange"]def[/COLOR] [COLOR="Blue"]showPopup[/COLOR]():
    modPopup = PyPopup()
    modPopup.setHeaderString(popupHeader)
    modPopup.setBodyString(popupMessage)
    modPopup.launch()

[COLOR="orange"]def[/COLOR] [COLOR="blue"]isDate[/COLOR](iDate):
    [COLOR="orange"]return[/COLOR] Game.getTurnYear(Game.getGameTurn() +1) > iDate [COLOR="orange"]and[/COLOR] Game.getGameTurnYear() <= iDate

[COLOR="orange"]def[/COLOR] [COLOR="blue"]eventSenate[/COLOR]():
    [COLOR="orange"]if[/COLOR] isDate(iYear):
        [COLOR="orange"]if[/COLOR] CyPlot.getOwner() != 0:
            showPopup()
            [COLOR="orange"]if[/COLOR] isDate(iEndYear):
                [COLOR="orange"]if[/COLOR] CyPlot.getOwner() == 0:
                    [COLOR="Red"]#give reward#[/COLOR]
I don't know how to tell CyPlot.getOwner() what co-ordinates I want it to return (yet) and I will define it as a function later (probs as def PlotOwner()...)I'm not sure what the reward could be... Gold? Units at capital? not sure yet... Need something motivating.

otherwise (if reward and stuff were filled in) would this work?

BTW this is in the ModEvent module so imports have already been made.

in fact I might add a second popup for if the city has already been taken (therefore using else) which just asks the player to make sure they hold byzantium (but maybe not)
what can be used to replace the {} in: if {player} == 0:?

EDIT: the more I look at the very end of the code the more I think it will not work... it says if isDate(iEndYear): but I also said if isDate(iYear): as it's Grand-Parent. but if it is iYear then how can it also be iEndYear? Am I right or would this work? How should the iEndYear be dealt with?
 
nice so for the axemen I would put in
Code:
initUnit(self, unitID, iX, iY, iNum = 3)

iX and iY have both been defined as 0 (see 2 posts ago)

what would I use to tell it to make axemen? and does that go in self or unitID?
Look at my stab at a API entry for PyPlayer.initUnit(). Did I mention any "self" parameter? No, I did not.

If you haven't already read up on classes and methods (Object-Oriented Programming) you can simply ignore any instance of self. Because this is just something that goes with the territory - you can look it up if you wanna know what it is.

The programmer who wrote the PyPlayer class (and its methods) chose to name the parameter for the UnitType value unitID. It could have been iUnitType, eUnit or whatever. It just happens to be unitID in this particular case.

It should be noted however that since the method belongs to a class - the PyPlayer class - it has to be invoked on an instance of that class. This is the actual code from PyHelpers:
PHP:
class PyPlayer:
	' CyPlayer Helper Functions - Requires Player ID to initialize instance '
	
	def __init__(self, iPlayer):
		' Called whenever a new PyPlayer instance is created '
		if iPlayer:
			self.player = gc.getPlayer(iPlayer)
		else:
			self.player = gc.getPlayer(0)
The __init__() method is called the class constructor. Still ignoring the self bit it takes one argument, iPlayer. If you read the documentation (second line) it refers to the player ID. And that is the same as the PlayerType.

So you basically need the PlayerType value referring to the Barbarian player for your event. Well, I already defined it as a constant in the Utils module:
Code:
eBarbarian = gc.getBARBARIAN_PLAYER()
All you need to do in order to access it is to import the Utils module:
Code:
import Utils
Then you can access the constant with Utils.eBarbarian. If you go like this however:
Code:
from Utils import *
...then you instantly add everything in the Utils module into your own module. And there is a lot of stuff there:
Spoiler :
Code:
### Settings for Jamie's Rome Mod

from CvPythonExtensions import *
from CivPlayer import *

Interface = CyInterface()
Translator = CyTranslator()

# constants

iNumMajorPlayers = 8
pHumanCiv = instance(Game.getActivePlayer())
eBarbarian = gc.getBARBARIAN_PLAYER()
pBarbarianCiv = CivPlayer(eBarbarian)

# eNums

def getIndex(category, entry):
        """
        Returns the enumerated index value (integer) of the specified entry belonging to the
        specified category, as specified by the XML.
        """
        key = category.replace(" ", "") + "_" + entry.replace(" ", "_")
        return gc.getInfoTypeForString(key.upper())

ePalace = getIndex("Building", "Palace")
eNaval = getIndex("Unit Combat", "Naval")
eQuintrireme = getIndex("Unit Class", "Quintrireme")
ePrivateer = getIndex("Unit Class", "Privateer")
eAdvancedSwordsman = getIndex("Unit Class", "Swordsman II")
eWarrior = getIndex("Unit", "Warrior")
eAxeman = getIndex("Unit", "Axeman")
eSwordsman = getIndex("Unit", "Swordsman")
eSpearmanII = getIndex("Unit", "Spearman II")
eSwordsmanII = getIndex("Unit", "Swordsman II")
eCatapult = getIndex("Unit", "Catapult")
eConstruction = getIndex("Tech", "Construction")
eBronzeWorking = getIndex("Tech", "Bronze Working")
eIronWorking = getIndex("Tech", "Iron Working")
eAdvancedBronzeWorking = getIndex("Tech", "Advanced Bronze Working")
eAdvanceIronWorking = getIndex("Tech", "Advanced Iron Working")
eFood = YieldTypes.YIELD_FOOD
eProduction = YieldTypes.YIELD_PRODUCTION
eCommerce = YieldTypes.YIELD_COMMERCE
eSea = getIndex("Domain", "Sea")
eHills = PlotTypes.PLOT_HILLS
eDesert = getIndex("Terrain", "Desert")
ePlains = getIndex("Terrain", "Plains")
eForest = getIndex("Feature", "Forest")
eUniversalSuffrage = getIndex("Civic", "Universal Suffrage")
eSlavery = getIndex("Civic", "Slavery")
eLabor = getIndex("Civic Option", "Labor")
eMinorEvent = InterfaceMessageTypes.MESSAGE_TYPE_MINOR_EVENT
eRed = getIndex("Color", "Red")
eGreen = getIndex("Color", "Green")
eWhite = getIndex("Color", "White")
eAttackCity = UnitAITypes.UNITAI_ATTACK_CITY
eUnknownAI = UnitAITypes.UNITAI_UNKNOWN
eNoDirection = DirectionTypes.NO_DIRECTION

# helper functions

def addMessage(tag, tStrings, tColor, tCoords=(-1, -1)):
        eColor = getColor(*tColor)
        if eColor == None: return
        message = Translator.getText(tag, tStrings)
        bArrow = tCoords != (-1, -1)
        Interface.addMessage(pHumanCiv.get(playerID), True, 20, message, "", eMinorEvent, "", eColor, tCoords[0], tCoords[1], bArrow, bArrow)

def getColor(bHuman, bAI, bOther=None):
        if bHuman:
                return eGreen
        elif bAI:
                return eRed
        elif bOther:
                return eWhite

def getCoords(pInstance):
        return (pInstance.getX(), pInstance.getY())

def isChance(iProbability):
        return getRandNum(100, "isChance()") < iProbability

def getRandNum(iRange, debug="getRandNum()"):
        return Game.getSorenRandNum(iRange, debug)

def getUnitClass(pUnit):
        return gc.getUnitInfo(pUnit.getUnitType()).getUnitClassType()

def isEnemyTerritory(pUnit, pPlot, pTeam):
        return pUnit.isRivalTerritory() and pTeam.isAtWar(pPlot.getTeam())
This assignment statement would be of interest to you:
Code:
eAxeman = getIndex("Unit", "Axeman")
So, now you have both a eBarbarian and eAxeman constant ready for use. What you need now is a PyPlayer instance to invoke the initUnit() method on. You get one by going:
Code:
PyHelpers.PyPlayer(eBarbarian)
You might wanna assign the class instance to a variable/name of some sort, but you could also use it directly:
Code:
PyHelpers.PyPlayer(eBarbarian).initUnit(eAxeman, iX, iY, 3)
Done. :king:

In case you wonder: The getIndex() function is a helper function defined in the Utils module:
Spoiler :
PHP:
def getIndex(category, entry):
        """
        Returns the enumerated index value (integer) of the specified entry belonging to the
        specified category, as specified by the XML.
        """
        key = category.replace(" ", "") + "_" + entry.replace(" ", "_")
        return gc.getInfoTypeForString(key.upper())
Its basically a wrapper for the CyGlobalContext.getInfoTypeForString() method. Check out the documentation (second line)!
 
look at the top of post 507 and it says self so that was why I put that...:p

ok then That makes me happy :D I will Re-Re-Re-edit the code and it should be final
 
I made three new variables Sparticus, Axeman and iAxe

Sparticus = PyHelpers.PyPlayer(eBarbarian)
iAxe = 3
Axeman = initUnit(eAxeman, iX, iY, iAxe)

Code:
[COLOR="Orange"]from[/COLOR] CvPythonExtensions [COLOR="orange"]import[/COLOR] *
[COLOR="orange"]from[/COLOR] PyHelpers [COLOR="orange"]import[/COLOR] *
[COLOR="orange"]from[/COLOR] Popup [COLOR="orange"]import[/COLOR] PyPopup
[COLOR="orange"]from[/COLOR] Utils [COLOR="orange"]import[/COLOR] *


[COLOR="Red"]##Sparticus rebellion##[/COLOR]
iYear = -3800
popupHeader = [COLOR="Green"]"Sparticus"[/COLOR]
popupMessage = [COLOR="green"]"Sparticus has invaded southern Italy as revenge for his cruel mistreatment.\n\n A barbarian army will spawn in sourthern Italy"[/COLOR]
iX = 0
iY = 0
Game = CyGame()
Sparticus = PyHelpers.PyPlayer(eBarbarian)
iAxe = 3
Axeman = initUnit(eAxeman, iX, iY, iAxe)
[COLOR="orange"]def[/COLOR] [COLOR="Blue"]showPopup[/COLOR]():
    modPopup = PyPopup()
    modPopup.setHeaderString(popupHeader)
    modPopup.setBodyString(popupMessage)
    modPopup.launch()

[COLOR="orange"]def[/COLOR] [COLOR="blue"]isDate[/COLOR](iDate):
    [COLOR="orange"]return[/COLOR] Game.getTurnYear(Game.getGameTurn() +1) > iDate [COLOR="orange"]and[/COLOR] Game.getGameTurnYear() <= iDate

[COLOR="orange"]def[/COLOR] [COLOR="blue"]eventSpartacus[/COLOR]():
    [COLOR="orange"]if[/COLOR] isDate(iYear):
        showPopup()
        Sparticus.Axeman

so that is the finished code for the Sparticus event! Does it all work fine do you think?

BTW: I looks at Utils and found: pHumanCiv = instance(Game.getActivePlayer())
if I was to say if pHumanCiv == 0: would that take info from the WBS and say (in english) if human player is playing as rome:?

anyway... Thanks so much for the information!!!

EDIT: made NEW module named CustomFunctions.py which contains functions for use in my modding which currently goes:
Code:
##custom functions for use in modding etc##
##use if required/wanted!##
from Popup import PyPopup

def save():
    print "Save"

def showPopup():
    modPopup = PyPopup()
    modPopup.setHeaderString(popupHeader)
    modPopup.setBodyString(popupMessage)
    modPopup.launch()

so this will be imported into ModEvents.py so that instead of defining showPopup(): in everything I/we can just import this and just define popupHeader and popupMessage! In fact earlier you said about adding isdate() to the Utils module, well why don't I just add it to this module? that would mean you just need to import this module to use popups and isdate!
 
This doesn't work:
Code:
Axeman = initUnit(eAxeman, iX, iY, iAxe)
Because there is no initUnit name defined anywhere in the module. Sure, there is a initUnit() method in CvPythonExtensions (belonging to the CyPlayer class) and there is another initUnit() method in PyHelpers (belonging to the PyPlayer class) but on its own it simply isn't defined anywhere.

In order to keep things simple, just invoke the method on the Sparticus value (the PyPlayer instance referring to the Barbarian player):
Code:
Sparticus.initUnit(eAxeman, iX, iY, iAxe)
BTW: I looks at Utils and found: pHumanCiv = instance(Game.getActivePlayer())
if I was to say if pHumanCiv == 0: would that take info from the WBS and say (in english) if human player is playing as rome:?
What is happening there is that the return value of the instance() function is being assigned to the name pHumanCiv. The function is part of the CivPlayer module and the return value is a CivPlayer class instance. This is all for my own amusement/convenience however and you don't need to get into that now. (I can totally teach you how to use CivPlayer once you know more of the basics.)

EDIT: made NEW module named CustomFunctions.py which contains functions for use in my modding which currently goes:
Code:
##custom functions for use in modding etc##
##use if required/wanted!##
from Popup import PyPopup

def save():
    print "Save"

def showPopup():
    modPopup = PyPopup()
    modPopup.setHeaderString(popupHeader)
    modPopup.setBodyString(popupMessage)
    modPopup.launch()

so this will be imported into ModEvents.py so that instead of defining showPopup(): in everything I/we can just import this and just define popupHeader and popupMessage! In fact earlier you said about adding isdate() to the Utils module, well why don't I just add it to this module? that would mean you just need to import this module to use popups and isdate!
You're welcome to make whatever modules you like and it might even be a good practical exercise to do so. But other than that I already made such a module - you guessed it: Utils. The name even indicates that the module contains "custom functions" (utilities) but I also happen use it to define constants. But we could have a Constants module for that, if you like.

The showPopup() function won't work however with this setup. Because the names/variables popupHeader and popupMessage aren't defined anywhere in the module. You could of course import them from ModEvents, but then both modules are importing each-other. It would just make more sense to have everything in one module. (Its not like your trying to manage 10000 lines of code or anything.)

It would also make sense to make the showPopup() function more generic, so that it can take any strings for the header and body messages respectively. This can be done by simply adding those names as arguments:
Code:
def showPopup([B]popupHeader, popupMessage[/B]):
    modPopup = PyPopup()
    modPopup.setHeaderString(popupHeader)
    modPopup.setBodyString(popupMessage)
    modPopup.launch()
Now you need to include the strings you wanna include in the popup whenever you call the function:
Code:
showPopup(spartacusHeader, spartacusMessage)
You of course need to define both variables before using them, but that probably goes without saying.

Also, I suggest you move all constants to the Utils module in the future (not right now, because I'm still working on it!) and all mod setting to the ModSettings module (see above). Right now you're fine with keeping everything in the same module however. Or your own modules, at least. (I'll hand everything over to you soon enough.)
 
Actually, it would make sense to add a helper function for unit spawning to your mod (whatever module it ends up living in):
Code:
def spawnUnits(ePlayer, eUnitType, tCoords, iNum):
	iX, iY = tCoords
	PyHelpers.PyPlayer(ePlayer).initUnit(eUnitType, iX, iY, iNum)
Example of use:
Code:
spawnUnits(eBarbarians, eAxeman, (iX, iY), iAxe)
You could define the map coordinates as a tuple however and use that:
Code:
tSpartacus = (0, 0)
spawnUnits(eBarbarians, eAxeman, tSpartacus, iAxe)
If we instead use the CivPlayer module/class the same function could look like this:
Code:
def spawnUnits(ePlayer, eUnitType, tCoords, iNum):
	iX, iY = tCoords
	instance(ePlayer).get(PyPlayer).initUnit(eUnitType, iX, iY, iNum)
But we could instead add the feature missing from PyPlayer.initUnit(), namely the ability to return a list of all the CyUnit instances that were created. This would be useful if we, for example, wanna name all units or grant them XP or Promotions. But then we wouldn't be able to use the PyPlayer class for our function...
Code:
def spawnUnits(ePlayer, eUnitType, tCoords, iNum):
	pPlayer = gc.getPlayer(ePlayer)
	iX, iY = tCoords
	lUnits = list()
	while iNum > 0:
		pUnit = pPlayer.initUnit(eUnitType, iX, iY, eNoAI, eNoDirection)
		lUnits.append(pUnit)
		iNum = iNum - 1
	return lUnits
But we'd have to define the constant eNoAI somewhere (preferably in the same place that eNoDirection - in the Utils module):
Code:
eNoAI = UnitAITypes.NO_UNITAI
What do you think? Because then you woundn't actually have to use the initUnit() method again - you could just use spawnUnits() for all your scenario events. :king:
 
sounds good, I have breifly read it so I will go over it again and add it to my CustomFunctions.py (I know, I love it:D). so the pop-up can still be defined there it just needs parameters put into it? thats fine! I dont know wether to use promotions and names for now but in the future I will edit these events again to make them like that! so I will use
Code:
def spawnUnits(ePlayer, eUnitType, tCoords, iNum):
	iX, iY = tCoords
	instance(ePlayer).get(PyPlayer).initUnit(eUnitType, iX, iY, iNum)
for the moment! Regarding tuples (I looked over them a little which originaly learning this) tSparticus = (0,0) is all I need to define (replacing iX and iY) and define a new tuple in each event?
 
ok so once again!
Code:
from Utils import *
from CustomFunctions import *


##Sparticus rebellion##
iYear = -3800
sparticusHeader = "Sparticus"
sparticusMessage = "Sparticus has invaded southern Italy as revenge for his cruel mistreatment.\n\n A barbarian army will spawn in sourthern Italy"
#unit definitions: coordinates, player, number to be spawned, unit type (defined by Utils)#
tSparticus = (0, 0)
eSparticus = eBarbarians
iSparticusUnitNumber = 3
eSparticusUnit = eAxeman
def eventSpartacus():
    if isDate(iYear):
        showPopup(sparticusHeader, sparticusMessage)
        spawnUnits(eSparticus, eSparticusUnit, tSpartacus, iSparticusUnitNumber)

that is the final(?:lol:) code for the sparticus event

and:

Code:
##custom functions for use in modding etc##
##use if required/wanted!##
from Popup import PyPopup
from CvPythonExtensions import *
from PyHelpers import *

def save():
    print "Save"

def showPopup(popupHeader, popupMessage):
    modPopup = PyPopup()
    modPopup.setHeaderString(popupHeader)
    modPopup.setBodyString(popupMessage)
    modPopup.launch()

Game = CyGame()
def isDate(iDate):
    return Game.getTurnYear(Game.getGameTurn() +1) > iDate and Game.getGameTurnYear() <= iDate

def spawnUnits(ePlayer, eUnitType, tCoords, iNum):
	iX, iY = tCoords
	instance(ePlayer).get(PyPlayer).initUnit(eUnitType, iX, iY, iNum)

there is the CustomFunctions module that goes with it!
 
I dont know wether to use promotions and names for now but in the future I will edit these events again to make them like that! so I will use
Code:
def spawnUnits(ePlayer, eUnitType, tCoords, iNum):
	iX, iY = tCoords
	instance(ePlayer).get(PyPlayer).initUnit(eUnitType, iX, iY, iNum)
The nice thing with defining functions like this, is that once you realize you need to add/change something you only have to edit one single function. Instead of going through 1000s of lines of code looking some code you copy-pasted earlier.

Regarding tuples (I looked over them a little which originaly learning this) tSparticus = (0,0) is all I need to define (replacing iX and iY) and define a new tuple in each event?
Yeah, and I do suggest you start to make up some system for all the constants used as scenario settings. Like iSpartacusDate, eSpartacusPlayer, eSpartacusUnitType, tSpartacusTarget, iSpartacusNumUnits and so on. Because each event you add will give you a new set of constants and it will become hard to keep up with time.

But on the other hand, you don't have to define any values in this manner. Since you already know some Python you could as easily edit the eventSpartacus() function directly.
Code:
def eventSpartacus():
    if isDate(-3800):
        showPopup("Spartacus Header", "Spartacus Message")
        spawnUnits(eBarbarians, eAxeman, (45, 56), 3)
It wouldn't be very hard to change the specifics at a later date, right?
 
I could do that but I like the things all layed out in front of me :D. I will define most things a little more and what you said about the functions is right and I am greatfull that I have my little module for functions just for that purpose!

did you see the final(authough I now know I will have to carry on defining) code I posted a minute ago?
 
Back
Top Bottom