Newb with a SDK/Worldbuilder question...

RogueStates

Chieftain
Joined
May 5, 2009
Messages
3
Hello all, Ive been a long time lurker, this is my first post (I think).....anyway...Im trying to make a custom map based on a fantasy tabletop RPG setting I created and have fleshed out for years...Im trying to use machu picchu on the map to represent a special place in the world...but i cant figure out for the life of me how to place it in the worldbuilder. ive placed it in a specific city, which indeed has mountains within the needed distance, within its cultural borders, but I cant find the option anywhere. Does it just randomly generate it on one of the mountains near it? Im trying to have it be on a specific mountain everytime, is there any way to do this? Thanks in advance for any assistance.
 
You may be able to use IGE (see my sig) to add it to that city (play your map, edit it with IGE in-game, then save your game as a scenario).

Or you could add it manually through LUA when the scenario loads.
 
Ah, so I get a reply from the creator of IGE....well met sir! Ive used your mod before and its very nice for a great many purposes.

Again, Im a total newb at modding...Is there something special you do to save your game as a scenario? Also, as far as LUA goes, that's coding right?
 
Glad to meet you too. :)
In civ5's save window, there is a button to save as scenario rather than a savegame. This is as simple as that!

Regarding LUA, indeed, it's coding so unless you already know programming or are motivated enough to learn it... That being said it allows one to add plenty of features to a scenario.
 
I looked for the button to save as scenario... there is one that saves the map, but it does not save anything but the basic terrain. Otherwise, all the saves are done as saved games which I am unable to open in worldbuilder and which, I believe, cannot be used as scenario maps.

Unless I am mistaken somehow... I changed the save game extention and tried world builder but was unable to open the file.

Unless saved games can be used for scenarios... but I think the human player would already be set in a saved game.

I hope I'm wrong, because being able to save the map as a scenario would save a lot of lau work... work which I think I will not be able to do in the future.
 
I looked for the button to save as scenario... there is one that saves the map, but it does not save anything but the basic terrain.
Ah! Well, I never used that feature myself, and I never tried to actually write a scenario, I only hear what other modders report to me in IGE's context. If civ5 cannot do that, then your only hope is to use LUA. Code would looks like this (test it in Firetuner first: add a button somewhere, then attach this code to it):

Code:
	-- Enumerate players
	for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1 do	
		local pPlayer = Players[iPlayer];
		if pPlayer:IsEverAlive() then
			-- Enumerate cities
            for cityIndex = 0, player:GetNumCities() - 1, 1 do
    			local city = player:GetCityByID(cityIndex);

				-- City exists and has the proper name?
    			if city ~= nil and city:GetName() == "My city" then

					-- Add wonder
					city:SetNumRealBuilding(7, 1);	-- Replace 7 with the actual wonder ID
					break;							-- Quit
    			end
			end
		end
	end
 
I used the code in the post above in an attempt cause a city to adopt a religion fully.

In the code below, I found a religion and create a holy city. This is done in the first two functions... however, the third function, in which I use the above code, is not causing the target city to adopt the religion.

I've tried this both as part of one file, and separating out the function that is to cause a city, Bergen, to adopt Confucianism. In both cases, the religion is created, but the city fails to adopt it.

I've checked the name in firetuner, and I have the id 23,8192 so I'm certain I am spelling it right.

What have I missed?

Code:
-- Find the Swedish player and found Confucianism in their capital, returning the city

function CreateAsatruHolyCity(pCity, religion, pantheonBelief, founderBelief, followerBelief, followerBelief2, enhancerBelief)
  local iPlayer = pCity:GetOwner()
  local iReligion = GameInfoTypes[religion]

  -- Optional extra beliefs
  local iBelief4 = followerBelief2 and GameInfoTypes[followerBelief2] or -1
  local iBelief5 = enhancerBelief and GameInfoTypes[enhancerBelief] or -1

  Game.FoundPantheon(iPlayer, GameInfoTypes[pantheonBelief])
  Game.FoundReligion(iPlayer, iReligion, nil, GameInfoTypes[founderBelief], GameInfoTypes[followerBelief], iBelief4, iBelief5, pCity)
end

function FoundConfucianism()
  for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do
    local pPlayer = Players[iPlayer]
    if (pPlayer:IsAlive()) then
      if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_SWEDEN) then
        local pCity = pPlayer:GetCapitalCity()
        CreateAsatruHolyCity(pCity, "RELIGION_CONFUCIANISM", "BELIEF_SACRED_WATERS",
                              "BELIEF_CEREMONIAL_BURIAL", "BELIEF_ASCETISM")

        return pCity
      end
    end
  end
end

-- Enumerate Cities with Confucianism

function AddConfucianismFollowers()	
	for iPlayer=GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_PLAYERS-2 do	
		local pPlayer = Players[iPlayer];
		if pPlayer:IsEverAlive() then
			-- Enumerate cities
            for cityIndex = 0, player:GetNumCities() - 1, 1 do
    			local city = player:GetCityByID(cityIndex);

				-- City exists and has the proper name?
    			if city ~= nil and city:GetName() == "Bergen" then

					-- Add Religion
					city:AdoptReligionFully(GameInfoTypes["RELIGION_CONFUCIANISM"]);
					break;							
    			end
			end
		end
	end
end

local pAsatruPlot = FoundConfucianism():Plot()

This stuff is going to make my ears bleed... I've searched many tutorial cites to see some of these methods in action, but the various wikis have very little practical examples (although the entries seem to have space for such)... so I'm never certain how the information such as names and/or integers, for example, are to be entered.
 
I guess you need to call pCity:AdoptReligionFully(religionID) because FoundReligion does not automatically convert the whole city.

Also forget the tutorials and the wiki (while this one may be useful sometimes, along with the link in my sig), use something like Notepad++ to search across all game files, this is your main documentation source.
 
Thanks... I've been using GERP for my searches but I'll certainly look to the others.

Bergen is not the city where the religion is founded... that one is another... the capital of Sweden. Bergen is a minor civ and not the holy city. The last function should be able to operate by itself, even in another file as it just depends upon the religion (Confucianism) having been created. It doesn't draw on anything else in the functions that create the religion or holy city.
 
Ah! Sorry, I didn't read your problem correctly. The problem lies with the third function. Did you try to add "print" instructions to check the civilizations and cities scanned by it? I think you need to use "max_civ_players - 1" rather than "max_players - 2". Actually I didn't know the latter one, I think it is related to the current number of players in your game. Just a guess, though.

Also, is "Bergen" the same in all languages or does it use a localized text key?
 
This thread, post #26 is why I used

for iPlayer=GameDefines.MAX_MAJOR_CIVS, GameDefines.MAX_PLAYERS-2 do

HTML:
http://forums.civfanatics.com/showthread.php?t=469047&page=2

and since Bergen is a minor civ, it should find it, I think.

However, that brings to mind that I will also be doing some major civ cities using the same function, and therefore I should search all cities...

I'll try:

0, GameDefines.MAX_MINOR_CIVS-1

and see what happens.
 
Now I just have to figure out how to put "print" calls into the code... :) .

I'm new.
You're going to love me then. :)
Put the first line right after you got pPlayer (and checked it's alive) and the second line right after you got pCity (the two dots are the concatenation operator, I add a whitespace in the inner loop to make formatting better).
Code:
print(pPlayer:GetName())
print(" "..pCity:GetName())

Regarding the name, no problem then.
 
Well, this is just strange...

I added print in various areas of my code.

As expected, in function CreateAsatruHolyCity and function FoundConfucianism(), pPlayer and pCity resulted in the relevant names being printed...

however, printing pPlayer and city in AddConfucianismFollowers(), had no result.

I changed things up by searching for a different city under a major civ. Still no result...
so I decided to separate out the AddConfucianismFollowers() function to a different file.

That did not work either...

so I eliminated all but the local pPlayer part... still nothing is printing out. I copied the part of FoundConfucianism() which I know printed out the proper result, and still nothing...

I'm certain I've added the file itself as an action in properties. The database doesn't indicate any problems loading it.

Here is the latest code that did not work:

Code:
-- Lua Script1
-- Author: Craig and Nancy
-- DateCreated: 7/21/2012 8:14:37 AM
--------------------------------------------------------------
-- Enumerate Cities with Confucianism

function AddConfucianismFollowers()	
	 for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do 
		local pPlayer = Players[iPlayer] print (pPlayer:GetName())
		--if pPlayer:IsEverAlive() then
			-- Enumerate cities
           -- for cityIndex = 0, player:GetNumCities() - 1, 1 do
    			--local city = player:GetCityByID(cityIndex) print (city:GetName())

				-- City exists and has the proper name?
    			--if city ~= nil and city:GetName() == "Roskilde" then

					-- Add Religion
				--	city:AdoptReligionFully(GameInfoTypes["RELIGION_CONFUCIANISM"])
				--	break;							
    		--	end
			--end
		--end
	end
end

Everything is blanked out except the player call. The exact same code works in another function. Could pPlayer be some sort of global that I created in another file? I don't think so, as it is in use in two other lua files and causing no problem.

Should I change pPlayer to another variable?

Have to go to work for now, but that is where I'm at...
 
Craig, are you sure your function is ever called? I suggest you add a print at the beginning to make sure. Also a couple of notes regarding LUA:
  • Putting things in different files does not matter: when you use "include", it does the same thing as if you copied-pasted the content of the whole included file. On the contrary, if you do not include your second file into the one being run, it's like the second file does not even exist.
  • It does not matter if you define a local variable (explicitly through the "local" keyword, or implicitly for the variable iterated by "for") that has the same name than a a global variable. They're still two different variables and the code will only see the local one within the scope where it is declared (and the scopes nested within that one). Without that imagine how much trouble it could be: adding a global variable somewhere could suddenly break functions, this would be a very bad design. This is why, afaik, in all programming languages, the code always use the "closest" variable (as long as the variable is declared "at same level or higher": on the same scope or a nesting scope, not a nested scope). So, no problem with pPlayer
  • You can comment out many lines at once: start the block with --[[ and ends it with ]]
  • Unless there is a AddConfucianismFollowers in the files you included, there is no interference possible: by default, your code only includes the standard LUA functions, the civ5 API, and nothing else. The LUA files from the game are not included by default and therefore what's defined in them does not interfere with your code. A mod runs in its own context: a LUA context is an isolated set of global variables: if some LUA file from the game defines a global variable named Schmurtz, it is not defined in your mod.
 
Well I've been plugging away and making progress..

I'm a newb... looking at all the lua scripts, I thought that necessarily had to be encapsulated in a function, so I did.

That was a mistake, it seems, and I removed the function from my code... it was not called by any other script in any case.

Using database logs, I also determined that minor civ players were not being called upon... perhaps because they do not have leaders (when I called them, using code that would call all civs including minors, their cities and "leader" never showed up in the print output. I may have to figure what to do about that later.

So going on...

Using the print function as was suggested, I was able to correct some mistakes in the code... this is what I now have:

Code:
-- Lua Script1
-- Author: Craig and Nancy
-- DateCreated: 7/21/2012 8:14:37 AM
--------------------------------------------------------------
-- Enumerate Cities with Confucianism

for iPlayer=0, GameDefines.MAX_MAJOR_CIVS-1 do
	local pPlayer = Players[iPlayer] print (pPlayer:GetName())
		if pPlayer:IsEverAlive() then
			
			-- Enumerate cities
			for cityIndex = 0, pPlayer:GetNumCities() - 1, 1 do
    			local city = pPlayer:GetCityByID(cityIndex) print (city:GetName())

				-- City exists and has the proper name?
    			if city ~= nil and city:GetName() == "Roskilde" then 
					print ("it works for Roskilde")
				elseif city ~= nil and city:GetName() == "Oslo" then
					print ("and it works for Oslo")
				elseif city ~= nil and city:GetName() == "Nidaros" then
					print ("and it works for Nidaros")
					-- Add Religion
					--city:AdoptReligionFully(GameInfoTypes["RELIGION_CONFUCIANISM"])
					break							
    			end
			end
		end
end

However, there is a problem. Civ 5 crashes at this point. It iterates through all instance, then it just stops.

I suspect I need to put in some command or other that tells the script to stop running once all, or the last city I am looking for, are found.

Here is the portion of the database log that is relevant... notice how it hits each leader than proceeds through that civ's cities, then does the next. Oddly, some cities are missing... Haakon is missing two cities, for instance, after Nidaros is found. The other sample civs have all of their cities found. I wonder if it is relevant that Haakon is also the last player in the search scheme.

Anyhow, it then crashes at that point. My print functions show where it has found the appropriate cities.

Spoiler :

[9600.223] ReligionAsatruFollowers: Harald Bluetooth
[9600.223] ReligionAsatruFollowers: Lund
[9600.223] ReligionAsatruFollowers: Roskilde
[9600.223] ReligionAsatruFollowers: it works for Roskilde
[9600.223] ReligionAsatruFollowers: Odense
[9600.223] ReligionAsatruFollowers: OLAF
[9600.223] ReligionAsatruFollowers: Kaupang
[9600.223] ReligionAsatruFollowers: Oslo
[9600.223] ReligionAsatruFollowers: and it works for Oslo
[9600.223] ReligionAsatruFollowers: Hamar
[9600.223] ReligionAsatruFollowers: TURLOUGH
[9600.223] ReligionAsatruFollowers: Cruachan
[9600.223] ReligionAsatruFollowers: Kilmore
[9600.223] ReligionAsatruFollowers: Mayo
[9600.223] ReligionAsatruFollowers: ANGUS
[9600.223] ReligionAsatruFollowers: Inverness
[9600.223] ReligionAsatruFollowers: CLOVIS
[9600.223] ReligionAsatruFollowers: Cambrai
[9600.223] ReligionAsatruFollowers: Tournai
[9600.223] ReligionAsatruFollowers: Bologne
[9600.223] ReligionAsatruFollowers: RIDERCH
[9600.223] ReligionAsatruFollowers: Dumfries
[9600.223] ReligionAsatruFollowers: Stranraer
[9600.223] ReligionAsatruFollowers: Dumbarton
[9600.223] ReligionAsatruFollowers: WITTEKIND
[9600.223] ReligionAsatruFollowers: Munster
[9600.223] ReligionAsatruFollowers: Osnabruck
[9600.223] ReligionAsatruFollowers: Bremen
[9600.223] ReligionAsatruFollowers: William
[9600.223] ReligionAsatruFollowers: Amiens
[9600.223] ReligionAsatruFollowers: Eu
[9600.223] ReligionAsatruFollowers: BORU
[9600.223] ReligionAsatruFollowers: Cashel
[9600.223] ReligionAsatruFollowers: Emly
[9600.223] ReligionAsatruFollowers: Birr
[9600.223] ReligionAsatruFollowers: Kenny
[9600.223] ReligionAsatruFollowers: Dunaverty
[9600.223] ReligionAsatruFollowers: Dunadd
[9600.223] ReligionAsatruFollowers: Iona
[9600.223] ReligionAsatruFollowers: Alfred
[9600.223] ReligionAsatruFollowers: Winchester
[9600.223] ReligionAsatruFollowers: PENDA
[9600.223] ReligionAsatruFollowers: Norwich
[9600.223] ReligionAsatruFollowers: Brancaster
[9600.223] ReligionAsatruFollowers: Lincoln
[9600.223] ReligionAsatruFollowers: OSWALD
[9600.223] ReligionAsatruFollowers: Scarborough
[9600.223] ReligionAsatruFollowers: York
[9600.223] ReligionAsatruFollowers: Bamburough
[9600.223] ReligionAsatruFollowers: Elisedd
[9600.223] ReligionAsatruFollowers: Wroxeter
[9600.223] ReligionAsatruFollowers: Chester
[9600.223] ReligionAsatruFollowers: Haakon
[9600.223] ReligionAsatruFollowers: Nidaros
[9600.223] ReligionAsatruFollowers: and it works for Nidaros
[9600.223] ReligionAsatruFollowers: ERIK
[9600.223] ReligionAsatruFollowers: Verdun
[9600.223] ReligionAsatruFollowers: Hamburg
[9600.223] ReligionAsatruFollowers: Deventer
[9600.223] ReligionAsatruFollowers: Visby
[9600.223] ReligionAsatruFollowers: Utrecht
[9600.223] ReligionAsatruFollowers: Groningen
[9600.223] ReligionAsatruFollowers: Pevensey
[9600.223] ReligionAsatruFollowers: Canterbury
[9600.223] ReligionAsatruFollowers: Birka
[9600.223] ReligionAsatruFollowers: Uppsala
[9600.223] ReligionAsatruFollowers: Chichester
[9600.223] ReligionAsatruFollowers: Colchester
[9600.223] ReligionAsatruFollowers: London
[9600.223] ReligionAsatruFollowers: Dorchester
[9600.223] ReligionAsatruFollowers: Cambridge
[9600.223] ReligionAsatruFollowers: Oxford
[9600.223] ReligionAsatruFollowers: Towcaster
[9600.223] ReligionAsatruFollowers: Bath
[9600.223] ReligionAsatruFollowers: Gloucester
[9600.223] ReligionAsatruFollowers: Leicester
[9600.223] ReligionAsatruFollowers: Tamworth
[9600.223] ReligionAsatruFollowers: Manchester
[9600.223] ReligionAsatruFollowers: Catterick
[9600.223] ReligionAsatruFollowers: Conway
[9600.223] ReligionAsatruFollowers: Lancaster
[9600.223] ReligionAsatruFollowers: Stavanger
[9600.223] ReligionAsatruFollowers: Corbridge
[9600.223] ReligionAsatruFollowers: Carlisle
[9600.223] ReligionAsatruFollowers: Edinburgh
[9600.223] ReligionAsatruFollowers: Tara
[9600.223] ReligionAsatruFollowers: Gula
[9600.223] ReligionAsatruFollowers: Scone
[9600.223] ReligionAsatruFollowers: Nectansimere
[9600.223] ReligionAsatruFollowers: Constantine
[9600.223] ReligionAsatruFollowers: Treguier
[9600.223] ReligionAsatruFollowers: Glastonbury
[9600.223] ReligionAsatruFollowers: Exeter
[9600.223] ReligionAsatruFollowers: OTTO
[9600.223] ReligionAsatruFollowers: Cologne
[9600.223] ReligionAsatruFollowers: Aachen
[9600.223] ReligionAsatruFollowers: Leige
[9600.223] ReligionAsatruFollowers: Alaric
[9600.223] ReligionAsatruFollowers: Saintes
[9600.223] ReligionAsatruFollowers: Poitiers
[9600.223] ReligionAsatruFollowers: Thouars


My question is, how do I tell the script to stop coding and go on to the next part before it crashes?

I think that is the problem since the last portion:

elseif city ~= nil and city:GetName() == "Nidaros" then
print ("and it works for Nidaros")

seems to have caused some trouble (it did not complete going through all of its cities but stopped upon finding the target).

I notice some script have a command like: return city. I'll try that to see if it might work.

Bye the way, thank-you for all the advice. I am becoming more aware of how I can track things down if an error occurs. I hope to go to the well, so to speak, less often as I learn more about the commands and such.
 
Back
Top Bottom