[Lua] Troller0001's stupid questions that may actually not be that stupid

The first scenario fails twice, because checking for nil with:
Code:
if not table == nil then
doesn't work. "not table" is being thrown together as a boolean function itself, and then being compared to nil.

This would work to alleviate that problem:
Code:
if not (table == nil) then
But these methods are a lot cleaner:
Code:
if table ~= nil then
if table then

And looking back whoward beat me to the punch.
 
Thank you both for your replies! :D

EDIT: The code now properly functions (or well, now does what I want it to do :p:lol:). Again, thanks a lot! :D
 
So this is not a lua-question, though I still decided to post it here. Anyhow, this one is regarding SQL and apostrophes:
Is there any way to ignore apostrophes within a TXT_KEY-definition?. I can always try to avoid the use of either the single apostrophe or the double apostrophe but in this case that would just look really bad/look really confusing.

This is how it shows in modbuddy
Code:
--snipped lines--
('TXT_KEY_UNIT_WALI_PEDIA',	"--snipped txt-- Abangan itself are also thought to be a corruption of arabic word "aba[COLOR="DarkRed"]'an" ("not diligent enough" in English) that changes its pronunciation in the tongue of native people there. Javanese people couldn'[/COLOR]t pronounce a lot of foreign words correctly back then, meaning that they just went with it."),
--more snipped lines--

So is there any way to make the code ignore the double apostrophes and the single apostrophes in between the first and final " of the Pedia entry?

EDIT: Oh and a completely other question (probably regarding xml):
If the Terra Nova music keeps playing after I have selected a custom civilization, then what did I not define? (I can recall several people had similair issues, so I tried looking for those threads with the search tool on the forums. However, all I could find were discussions on how bad/annoying 'Terra Nova' actually is :lol:)
Could the issue perhaps lie in not defining a DoM-audio, or is it something completely different?
 
Define your text in XML, and use <Text>Your Text</Text> format. Single ' will not be misinterpretted as commands or 'doubled' to "

Just remember that even this will not always work around all the issues with using apostrophe within text that will be related to concatenating the contents of a TXT_KEY with other text via an lua method such as

Code:
local sText = Locale.ConvertTextKey(TXT_KEY_BLAH) .. ' and fourty-seven.'

--------------------------------------------------------------------------------------------

You've probably not done as like this:
Code:
	<Audio_Sounds>
		<Row>
			<SoundID>SND_LEADER_MUSIC_SCIPIO_PEACE</SoundID>
			<Filename>Ceasar_Peace</Filename>
			<LoadType>DynamicResident</LoadType>
		</Row>
		<Row>
			<SoundID>SND_LEADER_MUSIC_SCIPIO_WAR</SoundID>
			<Filename>Ceasar_War</Filename>
			<LoadType>DynamicResident</LoadType>
		</Row>
	</Audio_Sounds>
	<Audio_2DSounds>
		<Row>
			<ScriptID>AS2D_LEADER_MUSIC_SCIPIO_PEACE</ScriptID>
			<SoundID>SND_LEADER_MUSIC_SCIPIO_PEACE</SoundID>
			<SoundType>GAME_MUSIC</SoundType>
			<MinVolume>50</MinVolume>
			<MaxVolume>50</MaxVolume>
			<IsMusic>true</IsMusic>
		</Row>
		<Row>
			<ScriptID>AS2D_LEADER_MUSIC_SCIPIO_WAR</ScriptID>
			<SoundID>SND_LEADER_MUSIC_SCIPIO_WAR</SoundID>
			<SoundType>GAME_MUSIC</SoundType>
			<MinVolume>50</MinVolume>
			<MaxVolume>50</MaxVolume>
			<IsMusic>true</IsMusic>
		</Row>
	</Audio_2DSounds>
Or you've not checked the 'Reload Audio System' checkbox in modbuddy. Or you have not defined your _WAR and _PEACE references as Leugi shows how it must be done:

Audio Add-ins Tutorials:
  1. [TUTORIAL] Making a custom Leader use Custom Music! (by Leugi)
  2. [TUTORIAL] Creating your own Soundtrack! (by Leugi)
 
Dang, I was hoping there would've been some hidden trick to that. I guess I'll have to go back to the good ol' XML ;). Thanks!

------

I had not defined any of that, so that's definitely the issue! Thank you very much LeeS!
 
Dang, I was hoping there would've been some hidden trick to that. I guess I'll have to go back to the good ol' XML ;). Thanks!
You can "escape" any special character in SQL to get the literal character by doubling them, e.g., %% if you're using LIKE (though in that case you could also change the wildcard character).

If you don't have any quotation marks (double quotes) in your string but you do have apostrophes (single quotes), you could just enclose the whole string in quotation marks instead of apostrophes and not worry about extra escape characters. But if you have both like in your example, then you'll need to double up one or the other.

Code:
--snipped lines--
('TXT_KEY_UNIT_WALI_PEDIA',"--snipped txt-- Abangan itself are also thought to be a corruption of arabic word ""aba'an"" (""not diligent enough"" in English) that changes its pronunciation in the tongue of native people there. Javanese people couldn''t pronounce a lot of foreign words correctly back then, meaning that they just went with it."),
--more snipped lines--

EDIT: I swapped the text back to quotation marks to make it more clear since '' looks so similar to ", but
Code:
'... "aba''an" ("not diligent enough" in English) ...'
would have worked too.
 
You can "escape" any special character in SQL to get the literal character by doubling them, e.g., %% if you're using LIKE (though in that case you could also change the wildcard character).

If you don't have any quotation marks (double quotes) in your string but you do have apostrophes (single quotes), you could just enclose the whole string in quotation marks instead of apostrophes and not worry about extra escape characters. But if you have both like in your example, then you'll need to double up one or the other.

Code:
--snipped lines--
('TXT_KEY_UNIT_WALI_PEDIA',"--snipped txt-- Abangan itself are also thought to be a corruption of arabic word ""aba'an"" (""not diligent enough"" in English) that changes its pronunciation in the tongue of native people there. Javanese people couldn''t pronounce a lot of foreign words correctly back then, meaning that they just went with it."),
--more snipped lines--

EDIT: I swapped the text back to quotation marks to make it more clear since '' looks so similar to ", but
Code:
'... "aba''an" ("not diligent enough" in English) ...'
would have worked too.

That was the trick I was looking for! Thank you very much Nutty!
 
New question!
I was messing with Artdefines (to add the SV-icon to a custom unit), but the only result I keep getting is the Spearman SV-icon and the Spearman 3D Model, whereas I want a custom missionary SV-icon with the standard missionary 3D model:

Code:
<ArtDefine_UnitInfos>
		<Row>
			<Type>ART_DEF_UNIT_WALI_ABANGAN</Type>
			<DamageStates>1</DamageStates>
			<Formation>EarlyGreatArtist</Formation>
		</Row>
		<Row>
			<Type>ART_DEF_UNIT_WALI_PUTIHAN</Type>
			<DamageStates>1</DamageStates>
			<Formation>EarlyGreatArtist</Formation>
		</Row>
	</ArtDefine_UnitInfos>
	<ArtDefine_UnitInfoMemberInfos>
		<Row>
			<UnitInfoType>ART_DEF_UNIT_WALI_ABANGAN</UnitInfoType>
			<UnitMemberInfoType>ART_DEF_UNIT_MEMBER_MISSIONARY</UnitMemberInfoType>
			<NumMembers>1</NumMembers>
		</Row>
		<Row>
			<UnitInfoType>ART_DEF_UNIT_WALI_ABANGAN</UnitInfoType>
			<UnitMemberInfoType>ART_DEF_UNIT_MEMBER_MISSIONARY_01</UnitMemberInfoType>
			<NumMembers>1</NumMembers>
		</Row>
		<Row>
			<UnitInfoType>ART_DEF_UNIT_WALI_ABANGAN</UnitInfoType>
			<UnitMemberInfoType>ART_DEF_UNIT_MEMBER_MISSIONARY_02</UnitMemberInfoType>
			<NumMembers>1</NumMembers>
		</Row>
		<Row>
			<UnitInfoType>ART_DEF_UNIT_WALI_PUTIHAN</UnitInfoType>
			<UnitMemberInfoType>ART_DEF_UNIT_MEMBER_MISSIONARY</UnitMemberInfoType>
			<NumMembers>1</NumMembers>
		</Row>
		<Row>
			<UnitInfoType>ART_DEF_UNIT_WALI_PUTIHAN</UnitInfoType>
			<UnitMemberInfoType>ART_DEF_UNIT_MEMBER_MISSIONARY_01</UnitMemberInfoType>
			<NumMembers>1</NumMembers>
		</Row>
		<Row>
			<UnitInfoType>ART_DEF_UNIT_WALI_PUTIHAN</UnitInfoType>
			<UnitMemberInfoType>ART_DEF_UNIT_MEMBER_MISSIONARY_02</UnitMemberInfoType>
			<NumMembers>1</NumMembers>
		</Row>
	</ArtDefine_UnitInfoMemberInfos>
	
	
	
	<ArtDefine_StrategicView>
		<Row>
			<StrategicViewType>ART_DEF_UNIT_WALI_ABANGAN</StrategicViewType>
			<TileType>Unit</TileType>
			<Asset>Art/SV_Wali_Abangan.dds</Asset>
		</Row>
		<Row>
			<StrategicViewType>ART_DEF_UNIT_WALI_PUTIHAN</StrategicViewType>
			<TileType>Unit</TileType>
			<Asset>Art/SV_Wali_Putihan.dds</Asset>
		</Row>
	</ArtDefine_StrategicView>
And This was within the unit definitions (with all the other unit stuff) (I'm only posting this line to show that I made no typos; This is NOT the only line in the Units.xml file!)
Code:
<UnitArtInfo>ART_DEF_UNIT_WALI_PUTIHAN</UnitArtInfo>
Both SV-icons have generated Mipmaps, have 128*128px dimensions, and have VFS=true.
EDIT: No compression and default formatting as well

I'm probably overlooking something, but I can't see what it is :cry:
 
Got Reload Unit System checked in ModBuddy? Also, where is the rest of your art define ?

This is for defining an "early" Great General Unit:
Spoiler :
Code:
<GameData>
	<ArtDefine_UnitInfos>
		<Row>
			<Type>ART_DEF_UNIT_ROMAN_PROCONSUL</Type>
			<DamageStates>1</DamageStates>
			<Formation>LooseCivilian</Formation>
		</Row>
	</ArtDefine_UnitInfos>
	<ArtDefine_UnitMemberInfos>
		<Row>
			<Type>ART_DEF_UNIT_MEMBER_ROMAN_PROCONSUL_EARLY</Type>
			<Scale>0.12</Scale>
			<Model>Assets/Units/GreatPeople/General/Early/GreatGeneral_Early.fxsxml</Model>
			<MaterialTypeTag>CLOTH</MaterialTypeTag>
			<MaterialTypeSoundOverrideTag>FLESH</MaterialTypeSoundOverrideTag>
		</Row>
	</ArtDefine_UnitMemberInfos>
	<ArtDefine_UnitInfoMemberInfos>
		<Row>
			<UnitInfoType>ART_DEF_UNIT_ROMAN_PROCONSUL</UnitInfoType>
			<UnitMemberInfoType>ART_DEF_UNIT_MEMBER_ROMAN_PROCONSUL_EARLY</UnitMemberInfoType>
			<NumMembers>1</NumMembers>
		</Row>
	</ArtDefine_UnitInfoMemberInfos>
	<ArtDefine_UnitMemberCombats>
		<Row>
			<UnitMemberType>ART_DEF_UNIT_MEMBER_ROMAN_PROCONSUL_EARLY</UnitMemberType>
			<EnableActions>Idle Death BombardDefend Run</EnableActions>
			<HasRefaceAfterCombat>1</HasRefaceAfterCombat>
		</Row>
	</ArtDefine_UnitMemberCombats>
	<ArtDefine_StrategicView>
		<Row>
			<StrategicViewType>ART_DEF_UNIT_ROMAN_PROCONSUL</StrategicViewType>
			<TileType>Unit</TileType>
			<Asset>sv_greatgeneral.dds</Asset>
		</Row>
	</ArtDefine_StrategicView>
</GameData>
and this is for defining the "late" version and to keep the Unit Icon (as opposed to SV and Flag Icon) originally defined in the <Units> table (and which for Great People only applies to the "Early" version):
Spoiler :
Code:
<GameData>
	<ArtDefine_UnitInfos>
		<Row>
			<Type>ART_DEF_UNIT_ROMAN_PROCONSUL_LATE</Type>
			<DamageStates>1</DamageStates>
			<Formation>LooseCivilian</Formation>
			<PortraitIndex>0</PortraitIndex>
			<IconAtlas>ATLAS_PROCONSUL_ICON</IconAtlas>
		</Row>
	</ArtDefine_UnitInfos>
	<ArtDefine_UnitMemberInfos>
		<Row>
			<Type>ART_DEF_UNIT_MEMBER_ROMAN_PROCONSUL_LATE</Type>
			<Scale>0.12</Scale>
			<Model>Assets/Units/GreatPeople/General/Late/GreatGeneral_Late.fxsxml</Model>
			<MaterialTypeTag>CLOTH</MaterialTypeTag>
			<MaterialTypeSoundOverrideTag>FLESH</MaterialTypeSoundOverrideTag>
		</Row>
	</ArtDefine_UnitMemberInfos>
	<ArtDefine_UnitInfoMemberInfos>
		<Row>
			<UnitInfoType>ART_DEF_UNIT_ROMAN_PROCONSUL_LATE</UnitInfoType>
			<UnitMemberInfoType>ART_DEF_UNIT_MEMBER_ROMAN_PROCONSUL_LATE</UnitMemberInfoType>
			<NumMembers>1</NumMembers>
		</Row>
	</ArtDefine_UnitInfoMemberInfos>
	<ArtDefine_UnitMemberCombats>
		<Row>
			<UnitMemberType>ART_DEF_UNIT_MEMBER_ROMAN_PROCONSUL_LATE</UnitMemberType>
			<EnableActions>Idle Death BombardDefend Run</EnableActions>
			<HasRefaceAfterCombat>1</HasRefaceAfterCombat>
		</Row>
	</ArtDefine_UnitMemberCombats>
	<ArtDefine_StrategicView>
		<Row>
			<StrategicViewType>ART_DEF_UNIT_ROMAN_PROCONSUL_LATE</StrategicViewType>
			<TileType>Unit</TileType>
			<Asset>sv_greatgeneral.dds</Asset>
		</Row>
	</ArtDefine_StrategicView>
</GameData>
 
I had not checked that option, so that might do the trick!

I thought I could use the UNIT_MEMBER info from the normal missionary (since I don't have a custom model, animations, or other stuff one could think of. I just want a new icon)
Now that I think of it, is reloading the Strategic View system also required for SV-flags to work, because I didn't check that either now that I think of it...

EDIT: Did some research, yes it is required to check the 'reload SV system' in Modbuddy...

Thanks a lot LeeS :thumbsup: (and what is up with that new creepy profile pic :eek:)


EDIT2:
Just checked those two options, and it worked perfectly (even without defining new Unit members are re-using the Missionary's Member info; so the only thing I changed from the code above was checking the 'Reload Unit System' and 'Reload Strategic View System' buttons.)
 
Okay a new question, which doesn't regard XML, Lua, or anything at all, and is more of a 'small but important'-mechanic question:
Will militaristic City States gift unique Civilian units to their allies (= the unit appears when you hover over the 'militaristic'-trait in the City State Overview)?
E.g. Can they gift their ally a settler UU, or a worker UU? Does this also include Great People Civilian units or is that only limited to finishing the Patronage Social Policy Tree? And does finishing that tree also allow the CS to gift modded Great People? (For that last one, I assume they do)

Oh and some fun facts:
Checking which UU a militaristic CS will gift can be done via pMinor:GetMinorCivUniqueUnit().
Setting which UU a militaristic CS will gift can be done via pMinor:SetMinorCivUniqueUnit(iUnitType);
 
Okay a new question, which doesn't regard XML, Lua, or anything at all, and is more of a 'small but important'-mechanic question:
Will militaristic City States gift unique Civilian units to their allies (= the unit appears when you hover over the 'militaristic'-trait in the City State Overview)?
E.g. Can they gift their ally a settler UU, or a worker UU? Does this also include Great People Civilian units or is that only limited to finishing the Patronage Social Policy Tree?

I'm pretty sure militaristic CSes only gift land-based military UUs: no civilians, and no naval or air units either.

And does finishing that tree also allow the CS to gift modded Great People? (For that last one, I assume they do)

Yeah, I've definitely gotten a few modded GPs from the Patronage finisher before.
 
That's good to know! Thanks a lot :D
 
Military CS gift units are

Only land (including ranged) units with a non-zero combat value, no non-ranged defensive only (via promotion) units, no recon units, no UUs from in play civs, must not be a default unit, must have a pre-req tech, only units after the starting era, two CSes cannot have the same unit

Great people gifts (via the policy finisher) can be any (in the base game you'll get Mongol Kahns and Venice Merchants)
 
I have a new question! This one regards the 'Custom Missions' from William's VMC DLL:

I was trying to add an instantiations custom mission to a unit, though it appeared that my events never fired:
Code:
print("TRL_TikiTakGeneral is loaded");

-- The custom mission we're interested in
local iMissionHypnotize = GameInfoTypes.MISSION_TRL_HYPNOTIZE --both these are correct in regards to spelling
local iTiki = GameInfoTypes.UNIT_TRL_TIKI

-- Return value constants needed by CustomMissionStart, do not change these, just use them
local CUSTOM_MISSION_NO_ACTION       = 0
local CUSTOM_MISSION_ACTION          = 1
local CUSTOM_MISSION_DONE            = 2
local CUSTOM_MISSION_ACTION_AND_DONE = 3

function OnCustomMissionPossible(iPlayer, iUnit, iMission, iData1, iData2, _, _, iPlotX, iPlotY, bTestVisible)
	[COLOR="darkred"]print("OnCustomMissionPossible fires");[/COLOR] --this never shows in the logs

  if (iMission == iMissionHypnotize) then
    local pPlayer = Players[iPlayer]
    local pUnit = pPlayer:GetUnitByID(iUnit)

    -- Can this particular unit type for this player perform this mission?  In our case only Clan Magicians can
    if (pUnit:GetUnitType() == iTiki) then
		print("Tiki mission possible; This unit is a Tiki");
      -- So we know the unit could perform the mission, but does it meet all the circumstantial conditions, ie, is the unit within our territory? (this is still some 'junk-text' left from the Tutorial; ignore)
      if (AnyAdjacentUnitsAtWar(iPlayer,iUnit)) then --AnyAdjacentUnitsAtWar is defined below and not part of my current question
        print("Tiki mission possible; Adjacent units that are at war");
		-- Circumstantial conditions NOT met (not adjacent to any units), return the value of bTestVisible
        return bTestVisible
      end

      -- All conditions met, so we can perform the action
      return true
    end
  end

  -- The unit can't perform the mission - return false
  return false
end
GameEvents.CustomMissionPossible.Add(OnCustomMissionPossible)

--CustomMissionStart, etc. are all below; I didn't paste them here since I never even got to testing them...
[...]

When I went to look for a solution, which involved downloading William's Morindim-civilization (since that example was also used in the Tutorial), and adding a similar 'print' to see if the thing would fire when I would expect it to fire, it did something strange*: The print from both my file and from Whowards file seemed to show in the logs!
Thus, to conclude, the events in my file seem to fire only if Morindim is enabled (even if I renamed my functions)!?

Spoiler :

The 'print' I added in Whowards file for testing:
Code:
[...]
function OnCustomMissionPossible(iPlayer, iUnit, iMission, iData1, iData2, _, _, iPlotX, iPlotY, bTestVisible)
[COLOR="DarkRed"]print("OnCustomMissionPossible (Morindim) is firing");[/COLOR]
if (IsMorindimPlayer(iPlayer)) then
[...]



*by strange I mean that it did something COMPLETELY unexpected!

NOTE: My mod has the VMC DLL as a dependency so load orders shouldn't be a problem


If I can't find a solution, I can always set Morindim as a dependency :p
------------------------------------

EDIT: I though I replied to your last post Whoward... Turns out I didn't... Anyhow, thanks for that clarification on CS gifts!
 
Sounds like you've omitted to switch on the mission events in the CustomModOptions database table
 
Yes, that did it! (Well, what else could you expect from the mod author himself? :p)
Thanks a lot! :D

EDIT: It seems it was mentioned in the 'Durational custom missions' but not in the 'instantaneous custom missions', which I happened to be referencing :cry:
 
New question, this one regards pUnit:SetEmbarked(bValue) and Visual updates

So I have this piece of code (cut out of context), which functions properly. If the original unit was embarked, the copy of that unit will be embarked as well.
Code:
[...]

local pUnitToHypnotize = tNewUnits[j];
local pNewUnit = pPlayer:InitUnit(pUnitToHypnotize:GetUnitType(), pUnitToHypnotize:GetX(), pUnitToHypnotize:GetY()) 
pNewUnit:Convert(pUnitToHypnotize);
print("pNewUnit was converted to "..GameInfo.Units[pNewUnit:GetUnitType()].Type);

if pNewUnit:CanEmbark(pNewUnit:GetPlot()) then --if the converted unit was embarked, our new unit should be embarked as well!
	print("The converted unit is now embarked");
	pNewUnit:SetEmbarked(true);
end

[...]

However, normally, embarked units have these little boats 3D models, whereas my copied unit simply uses its "I'm on the land" 3D model. This model is not changed to the boats again until I disembark and re-embark again! Is there any way of solving this?
 
Code:
  <api object="Team" method="UpdateEmbarkGraphics">
      <method class="CvTeam" fn="UpdateEmbarkGraphics"/>
      <ret type="void"/>
  </api>
  • It's a Teams rather than Players method so effects all units belonging to the same team.
  • You should handle all other code and then use the method as the final 'fix' to the graphics after all other actions have been performed. So, if you were running the 'hypnotize' code as part of PlayerDoTurn, you would want to perform all the 'hyptnotizing', and then you would want to update the embarked graphics.
Code:
local iTeam = pPlayer:GetTeam()
local pOurTeam = Teams[iTeam]
pOurTeam:UpdateEmbarkGraphics()
 
Top Bottom