ModModder's Guide

for i in xrange(pUnit.getNumInvisibleTypes()):
if (pUnit.getInvisibleType(i) > 0):
do stuff

Unfortunately setInvisibleType is not available in python, so you can't set it as not being invisible. Nor is setSeeInvisibleType so you can't make your unit able to see it either, unless you give it a promotion which allow it.

Thanks snarko, that was the missing piece. Exactly what I needed. I'm not sure if I want to set the unit visible (if it's easy to do, I'll probably give a promotion that makes them visible, and then have it expire at the end of the turn). What I *do* want to do is damage every deceptive unit that's trying to hide or disguise its nationality. :D

(Meh, I don't see an easy way to set a unit Visible with a promotion. So maybe I'll give the caster SEE INVISIBLE for a turn...)
 
Ok... thats even easier, thx:)

I'm not sure it will work, but I believe it will. Worth a shot. :p

Thanks snarko, that was the missing piece. Exactly what I needed. I'm not sure if I want to set the unit visible (if it's easy to do, I'll probably give a promotion that makes them visible, and then have it expire at the end of the turn). What I *do* want to do is damage every deceptive unit that's trying to hide or disguise its nationality. :D

(Meh, I don't see an easy way to set a unit Visible with a promotion. So maybe I'll give the caster SEE INVISIBLE for a turn...)

He wrote out the code that I'd already described, you know. :p
 
could it be that if you make a mod you can't change something only add.:confused:

I wanted to remove the <PrereqInCity>1</PrereqInCity> form Bronze... Weapons Promo
with changing it to "0" but it doesen't disappeared.
 
No, you can change or add things very easy.

What you are trying to do is remove information; This is not as easy. Basically, modules work by loading changes you've made... But they ignore default values. If they didn't, you'd have to list every single tag on the unit/building/whatever. Not good, makes modules more likely to run into compatibility errors.

However, to remove things this causes issues, as when you remove something you set it to default. So it is ignored. To get it to work, you have to force it to overwrite; All you need to do is add the <bForceOverwrite>1</bForceOverwrite> tag to the entry.

HOWEVER: This also means it will remove anything you leave off the entry. So when using this tag, you must have the entire object in the file. If you only list the changed tags, then that is all that will be left on it!
 
OK, I'm bashing my head against a brick wall trying to do the simplest things, so I figured it open it up to the brains trust as mine has evidently gone AWOL.

I wanted to hack some of the units from Colonisation into the game to beef up the guilds a little. If I ever get anywhere I'll put it up online for your delectation and derision. After a bit of a fight I got a Grigori Statesman with the Inquisitor ability at Code of Laws. Even got it to use the right art!

Next up a Fisherman 'cos sometimes it's easier to travel five tiles across land rather than sail all the way round the Cape of Good Hope. I've copied and pasted the text from my statesman entry and changed the class to Fisherman, likewise the UnitClassInfo. However when I load I get a cryptic error about unitClass_Fisherman. I'm sure it's something incredibly simple that I'm missing, but I'm jiggered if I can spot it.

Files enclosed.
 

Attachments

  • Units.7z
    1.2 KB · Views: 62
Thanks snarko, that was the missing piece. Exactly what I needed.

He wrote out the code that I'd already described, you know. :p

Well, you could say that. Except that what you described caused an exception on any unit that wasn't invisible, and he let me know about the pUnit.getNumInvisibleTypes() function which was the missing piece that I mentioned. :p

Not that I don't appreciate your help either way! :D
 
OK, I'm bashing my head against a brick wall trying to do the simplest things, so I figured it open it up to the brains trust as mine has evidently gone AWOL.

I wanted to hack some of the units from Colonisation into the game to beef up the guilds a little. If I ever get anywhere I'll put it up online for your delectation and derision. After a bit of a fight I got a Grigori Statesman with the Inquisitor ability at Code of Laws. Even got it to use the right art!

Next up a Fisherman 'cos sometimes it's easier to travel five tiles across land rather than sail all the way round the Cape of Good Hope. I've copied and pasted the text from my statesman entry and changed the class to Fisherman, likewise the UnitClassInfo. However when I load I get a cryptic error about unitClass_Fisherman. I'm sure it's something incredibly simple that I'm missing, but I'm jiggered if I can spot it.

Files enclosed.

It's your UnitClassInfos file.

Here is your file. I colored the problem lines.
Code:
<Civ4UnitClassInfos xmlns="x-schema:Magpie_CIV4UnitSchema.xml">
	[COLOR="Red"]<UnitClassInfos>[/COLOR]
		<UnitClassInfo>		<!-- STATESMAN -->
			<Type>UNITCLASS_STATESMAN</Type>
			<Description>Grigori Statesman</Description>
			<iMaxGlobalInstances>-1</iMaxGlobalInstances>
			<iMaxTeamInstances>-1</iMaxTeamInstances>
			<iMaxPlayerInstances>-1</iMaxPlayerInstances>
			<iInstanceCostModifier>0</iInstanceCostModifier>
			<DefaultUnit>UNIT_STATESMAN</DefaultUnit>
		</UnitClassInfo>
	[COLOR="Red"]</UnitClassInfos>
	<UnitClassInfos>[/COLOR]
		<UnitClassInfo>
			<Type>UNITCLASS_FISHERMAN</Type>
			<Description>Fisherman</Description>
			<iMaxGlobalInstances>-1</iMaxGlobalInstances>
			<iMaxTeamInstances>-1</iMaxTeamInstances>
			<iMaxPlayerInstances>-1</iMaxPlayerInstances>
			<iInstanceCostModifier>0</iInstanceCostModifier>
			<DefaultUnit>UNIT_FISHERMAN</DefaultUnit>
		</UnitClassInfo>
	[COLOR="Red"]</UnitClassInfos>[/COLOR]
</Civ4UnitClassInfos>

You should only have one set of <UnitClassInfos></UnitClassInfos> tags. Same goes for any other <....Infos> tag; They open and close the file.

Corrected file, with the tags in question highlighted again.

Code:
<Civ4UnitClassInfos xmlns="x-schema:Magpie_CIV4UnitSchema.xml">
	[COLOR="Red"]<UnitClassInfos>[/COLOR]
		<UnitClassInfo>		<!-- STATESMAN -->
			<Type>UNITCLASS_STATESMAN</Type>
			<Description>Grigori Statesman</Description>
			<iMaxGlobalInstances>-1</iMaxGlobalInstances>
			<iMaxTeamInstances>-1</iMaxTeamInstances>
			<iMaxPlayerInstances>-1</iMaxPlayerInstances>
			<iInstanceCostModifier>0</iInstanceCostModifier>
			<DefaultUnit>UNIT_STATESMAN</DefaultUnit>
		</UnitClassInfo>
		<UnitClassInfo>
			<Type>UNITCLASS_FISHERMAN</Type>
			<Description>Fisherman</Description>
			<iMaxGlobalInstances>-1</iMaxGlobalInstances>
			<iMaxTeamInstances>-1</iMaxTeamInstances>
			<iMaxPlayerInstances>-1</iMaxPlayerInstances>
			<iInstanceCostModifier>0</iInstanceCostModifier>
			<DefaultUnit>UNIT_FISHERMAN</DefaultUnit>
		</UnitClassInfo>
	[COLOR="Red"]</UnitClassInfos>[/COLOR]
</Civ4UnitClassInfos>

Well, you could say that. Except that what you described caused an exception on any unit that wasn't invisible, and he let me know about the pUnit.getNumInvisibleTypes() function which was the missing piece that I mentioned. :p

Not that I don't appreciate your help either way! :D

....I didn't mention that function? I thought I did... :eekdance:
 
Next up a Fisherman 'cos sometimes it's easier to travel five tiles across land rather than sail all the way round the Cape of Good Hope. I've copied and pasted the text from my statesman entry and changed the class to Fisherman, likewise the UnitClassInfo. However when I load I get a cryptic error about unitClass_Fisherman. I'm sure it's something incredibly simple that I'm missing, but I'm jiggered if I can spot it.

Try removing these two lines between your two unitclasses in unitclassinfo:
</UnitClassInfos>
<UnitClassInfos>

I haven't checked the schema to be sure, but it seems like UnitClassInfos should only be allowed once in each file, with multiple UnitClassInfo (no 's') tags inside it.

Edit: Damn, stupid ninjas.
 
Thanks guys. I'd better sneak away quietly. There appear to be a host of ninjas in this thread ;)

If there appears to be a host of ninjas then you're safe. You should really be worried about the threads with no apparent ninjas. Those ones are infested with ninja.
 
for i in xrange(pUnit.getNumInvisibleTypes()):
if (pUnit.getInvisibleType(i) > 0):
do stuff

Actually, this didn't quite work for me either. pUnit.getNumInvisibleTypes() returns 1 for all of the various invisible things that I put around my unit. So that's good. Which means that i will be 0 (and the interior of the for loop is executed once per unit), which is fine. pUnit.getInvisibleType(0) is 3 for Giant Spider (and I'm assuming for any INVISIBLE_ANIMAL) unit. But for Shadow, Trackless, and Ghost (which are others that I checked), pUnit.getInvisibleType(0) is 0.

So, since I still can't tell exactly what the int argument or int return of that function means (if argument and return were both invisible type, then I'd expect them to be the same, not 0 arg, 3 return for spiders. but if it's an ordinal meaning give me the 0th invisibility type this unit has, I'd expect non-zero for shadows)... I'm planning on just using:
Code:
pUnit.getNumInvisibleTypes() > 0

Without spending any more time on teaching me something which it's quite possible I'm too dense to learn... is there any situation where getNumInvisibleTypes() will be greater than 0 for a unit that has no invisibility? I.e. it's not like a regular, fully-visible unit will have INVISIBLE_NONE and have that be counted as 1 by the function, right? Because that's the easiest way to do what I want...
 
ah, sorry, getInvisibleType return the type of invisibility. You're right that you can use pUnit.getNumInvisibleTypes() > 0 if all you want to know is that the unit is invisible.

The only way I can see that would make NO_INVISIBLE be counted would be if INVISIBLE_TYPE in GlobalDefines was broken. Not likely to happen, nor something you should have to take into account.
 
How would one go about adding a variable (integer) to terrain? Or more accurately, to plots? Is it possible through XML and python, or do I have to go .dll diving?
 
If you want an entirely new variable on plots, it would have to be done in the DLL. It is a VERY simple addition, though, in just CvPlot(cpp and h), CyPlot(cpp and h), and CyPlotInterface.

Last three are just for python access.

I thought as much. This does mean it couldn't be modular, though, right?
 
right, DLL changes can't be modular. You can use CyPlot::getScriptData() and CyPlot::setScriptData(std::string szNewValue) but do remember that other things can use this as well, so you need to take that into account. (usually done by pickle.)
 
Top Bottom