Cannot get script to work

Aqueous

Chieftain
Joined
Aug 25, 2015
Messages
6
Hiya,

I'm trying to use a lua script to disable wonders (lua so it'll work better with wonders added by mods) but I cannot get it to work - all wonders are still buildable.

It's just a slightly changed version of something whoward69 wrote:

Code:
function CityCanConstructWonder(iPlayer, iCity, iBuilding)

  if (GameInfo.BuildingClasses[GameInfo.Buildings[iBuilding].BuildingClass].MaxGlobalInstances == 1) then

	return false
  end
end
GameEvents.CityCanConstruct.Add(CityCanConstructWonder)

Am I missing the point here? Will hooking it onto this event not work for what is selectable to the player (ie. only works for the AI)?

Thanks in advance.
 
Hiya,

I'm trying to use a lua script to disable wonders (lua so it'll work better with wonders added by mods) but I cannot get it to work - all wonders are still buildable.

It's just a slightly changed version of something whoward69 wrote:

Code:
function CityCanConstructWonder(iPlayer, iCity, iBuilding)

  if (GameInfo.BuildingClasses[GameInfo.Buildings[iBuilding].BuildingClass].MaxGlobalInstances == 1) then

	return false
  end
end
GameEvents.CityCanConstruct.Add(CityCanConstructWonder)

Am I missing the point here? Will hooking it onto this event not work for what is selectable to the player (ie. only works for the AI)?

Thanks in advance.
PLEASE IGNORE ALL THE FOLLOWING SILLY WANKERING
Compare this construction:
Code:
GameInfo.Buildings[iBuilding].BuildingClass
to this one:
Code:
local sStuff = GameInfo.Buildings[iBuilding].BuildingClass
In which case sStuff will be the name of the desired BuildingClass, ie: BUILDINGCLASS_WALLS if the original iBuilding is the ID# for either the Walls or Walls of Babylon building.
  • The important part to remember for the moment is that iBuilding was an integer, whereas sStuff will be a string
Now paste sStuff into the following and consider what the resulting value for iMaxInstances would be, if anything:
Code:
local iMaxInstances = GameInfo.BuildingClasses[sStuff].MaxGlobalInstances
 
Well, you learn something every day because that construction is indeed working, which I did not expect. Your code in post #1 should be fine as far as it goes. But you should probably add a clause in there so that the function will guarantee to return "true" (ie, the building can be constructed) for all buildings that don't match MaxGlobalOccurances == 1.
Code:
function CityCanConstructWonder(iPlayer, iCity, iBuilding)

  if (GameInfo.BuildingClasses[GameInfo.Buildings[iBuilding].BuildingClass].MaxGlobalInstances == 1) then
	return false
  else return true
  end
end
GameEvents.CityCanConstruct.Add(CityCanConstructWonder)
For the file that had your code in post #1, what settings did you have in ModBuddy to "activate" the file? See whoward69's what ModBuddy setting for what file types tutorial Post #3 for the activation method that would be required for this sort of lua program. Even though he showed an xml file in Post #3 of that thread, it is the correct method for your lua script.
 
Yeah I set it as an InGameUIAddin etc. the only thing I'm not sure about is whether to set it to VFS or not. I've read you shouldn't for an lua file that doesn't replace an existing lua file so I set it to False.

I just wondered though - do you know if the CityCanConstruct event is just for AI or does it apply to the player too? If it's just for the AI then this may explain why I can still see the wonders available for building - I want to block my own use of them too!

I will add an else statement to the script like you said but otherwise yeah I cannot workout why it isn't working :( - I do really want to try to remove wonders because for me the wonder race kind of takes over everything in the first 1/3 of the game....

Thanks for the help.
 
Change the text within your lua file to this:
Code:
-- Disabled Wonders
-- Author: Cosmos
-- DateCreated: 8/25/2015 6:58:22 PM
--------------------------------------------------------------

function CityCanConstructWonder(iPlayer, iCity, iBuilding)
	-- Is this building a World Wonder?
	-- (Note.  We should optimise this by caching a list of building IDs (iBuilding) which are world wonders at load time)
	if (GameInfo.BuildingClasses[GameInfo.Buildings[iBuilding].BuildingClass].MaxGlobalInstances == 1) then
		return false
	else return true
	end
end
GameEvents.CityCanConstruct.Add(CityCanConstructWonder)

print("Wonders Disabled loaded to the end")
You really do require the "else" clause in order to not disable everything from the <Buildings> table. With the "else" clause missing, all I was able to build was units.

I did not look into whether or not your xml file's updates were working properly to turn those world wonders into national wonders.
 
Thank you, I'll give it a try now :)

Edit: Tried it just now and unfortunately it's still not working. All Wonders still available on the Production pane. Siiiiigh.

I would've thought such a simple mod would've been easy to get working...it just doesn't seem to be firing at all.
 
Thank you, I'll give it a try now :)

Edit: Tried it just now and unfortunately it's still not working. All Wonders still available on the Production pane. Siiiiigh.

I would've thought such a simple mod would've been easy to get working...it just doesn't seem to be firing at all.
Strange, because your mod as posted in Post #7 with the changes I show in Post #8 works just fine for me.
 
Yeah I made those changes and have checked the actual .lua file itself in Notepad to make sure they got saved OK. I don't know, it's like the mod simply isn't firing at all, I'm wondering if it's something wrong in the config in ModBuddy rather than the script.

Edit: I changed the GUID of the mod and it seems *fingers crossed* to be working.

It doesn't seem to work with saved games but from a new game I -think- it's working. I need to play more to make sure no Wonders pop up but thank you for all the help :).
 
Can't be anything to do with ModBuddy.
  1. I downloaded the mod from post #7
  2. I unzipped
  3. I made the changes to the lua file as noted in post #8
  4. I saved the changes in the lua file
  5. I copy/pasted the resulting mod into my ~/MODS/ folder
  6. I started the game and enabled the mod by going into the game's MODS menu
  7. I progressed to the successive modded-games menus by pressing NEXT in the lower-right corner of the MODS menu
  8. I selected START NEW GAME at the appropriate menu to start a new modded game
  9. At no point did I click any button called "BACK"
  10. Mod works flawlessly with the changes made to the lua file as noted that I made in step #3

Select, subscribe, enable and play a mod Note that you would be bypassing steps # 4, 5, and 6 and would be going directly from # 3 to # 7.

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

[edit]From your mod's xxx.modinfo file:
Code:
<AffectsSavedGames>1</AffectsSavedGames>
This means you must have the mod enabled when you start the game and you cannot add it into the list of enabled mods when loading a saved game. This is also the proper setting for your mod. Otherwise you will make a hash of a saved game, I would think.

You can turn this attribute off in ModBuddy, but can is nearly always not equivalent to should. Especially in the case of your mod, it needs to be set this way.

Stuff above the 'bar' in this post is there because the proper usage of mods is very often the primary reason why someone cannot get a perfectly fine mod to, as you say, "fire"
 
Back
Top Bottom