• Our friends from AlphaCentauri2.info are in need of technical assistance. If you have experience with the LAMP stack and some hours to spare, please help them out and post here.

[BNW] Help in modding Civ BE Units in Civ V

With or without Aliens?


  • Total voters
    13
You have a few errors in your code:
  1. You have a mis-match between 'pCity' and 'city'.
    • Since you defined your city variable as 'pCity' in this line
      Code:
      for pCity in pPlayer:Cities() do
      you need to refer to the same variable-name here, as in
      Code:
      pCity:SetPopulation(pCity:GetPopulation()*0.67)
    • You should probably also "floor" or "ceil" the result of the math. And you should probably also not adjust the city population unless the city population is above a minimum value.
  2. You have never defined 'pTeam' so you would get an error for attempting to "index" a nil value
  3. You appear to be missing an 'end'
    • 'function', 'for', and 'if' all require their own matching 'end'
Code:
local BigMistakePenalty = GameInfoTypes.FEATURE_MARSH
 local iPrereq1 = GameInfo.Technologies["TECH_BIGMISTAKE"].ID
 local iPrereq2 = GameInfo.Technologies["TECH_REMILITARIZATION"].ID

function BigMistakePenalty(iPlayer)
	local pPlayer = Players[iPlayer]
	if (Teams[pPlayer:GetTeam()]:IsHasTech(iPrereq2)) then
		for pCity in pPlayer:Cities() do
			local iCurrentPop = pCity:GetPopulation()
			if (iCurrentPop >= 2) then
				pCity:SetPopulation(math.floor(iCurrentPop * 0.67))
			end
		end
	end
end
However, you still have a larger problem in that you have not assigned your code to run when the proper 'hook' event is triggered by the gamecore. So your code will never execute.

The way you programmed your code would seem like it would work from the lua hook event called PlayerDoTurn, but the problem is that doing so would cause all city populations to be decreased every turn once the tech is discovered, essentially resulting in an empire that would have 1-pop cities.

It would be better to use the hook GameEvents.TeamTechResearched(). The gamecore passes arguments iTeam, iTech, iChange to all functions subscribed to this GameEvent. Individual players, however, do not research or own technologies. Teams do. So it is necessary to use the data passed for 'iTeam' to find all players belonging to that team. The advantage to using GameEvents.TeamTechResearched is that it only can ever fire once for a given technology for a given team.

Code:
local iPrereq1 = GameInfo.Technologies["TECH_BIGMISTAKE"].ID
local iPrereq2 = GameInfo.Technologies["TECH_REMILITARIZATION"].ID
function BigMistakePenalty(iTeam, iTech, iChange)
	if (iTech == iPrereq2) then
		for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1, 1 do
			if (Players[iPlayer] ~= nil) then
				if (Players[iPlayer]:GetTeam() == iTeam) then
					local pPlayer = Players[iPlayer]
					for pCity in pPlayer:Cities() do
						local iCurrentPop = pCity:GetPopulation()
						if (iCurrentPop >= 2) then
							pCity:SetPopulation(math.floor(iCurrentPop * 0.67))
						end
					end
				end
			end
 		end
	end
end
GameEvents.TeamTechResearched.Add(BigMistakePenalty)
The code as written will not affect City-States or Barbarians.
 
You have a few errors in your code:
  1. You have a mis-match between 'pCity' and 'city'.
    • Since you defined your city variable as 'pCity' in this line
      Code:
      for pCity in pPlayer:Cities() do
      you need to refer to the same variable-name here, as in
      Code:
      pCity:SetPopulation(pCity:GetPopulation()*0.67)
    • You should probably also "floor" or "ceil" the result of the math. And you should probably also not adjust the city population unless the city population is above a minimum value.
  2. You have never defined 'pTeam' so you would get an error for attempting to "index" a nil value
  3. You appear to be missing an 'end'
    • 'function', 'for', and 'if' all require their own matching 'end'
Code:
local BigMistakePenalty = GameInfoTypes.FEATURE_MARSH
 local iPrereq1 = GameInfo.Technologies["TECH_BIGMISTAKE"].ID
 local iPrereq2 = GameInfo.Technologies["TECH_REMILITARIZATION"].ID

function BigMistakePenalty(iPlayer)
    local pPlayer = Players[iPlayer]
    if (Teams[pPlayer:GetTeam()]:IsHasTech(iPrereq2)) then
        for pCity in pPlayer:Cities() do
            local iCurrentPop = pCity:GetPopulation()
            if (iCurrentPop >= 2) then
                pCity:SetPopulation(math.floor(iCurrentPop * 0.67))
            end
        end
    end
end
However, you still have a larger problem in that you have not assigned your code to run when the proper 'hook' event is triggered by the gamecore. So your code will never execute.

The way you programmed your code would seem like it would work from the lua hook event called PlayerDoTurn, but the problem is that doing so would cause all city populations to be decreased every turn once the tech is discovered, essentially resulting in an empire that would have 1-pop cities.

It would be better to use the hook GameEvents.TeamTechResearched(). The gamecore passes arguments iTeam, iTech, iChange to all functions subscribed to this GameEvent. Individual players, however, do not research or own technologies. Teams do. So it is necessary to use the data passed for 'iTeam' to find all players belonging to that team. The advantage to using GameEvents.TeamTechResearched is that it only can ever fire once for a given technology for a given team.

Code:
local iPrereq1 = GameInfo.Technologies["TECH_BIGMISTAKE"].ID
local iPrereq2 = GameInfo.Technologies["TECH_REMILITARIZATION"].ID
function BigMistakePenalty(iTeam, iTech, iChange)
    if (iTech == iPrereq2) then
        for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1, 1 do
            if (Players[iPlayer] ~= nil) then
                if (Players[iPlayer]:GetTeam() == iTeam) then
                    local pPlayer = Players[iPlayer]
                    for pCity in pPlayer:Cities() do
                        local iCurrentPop = pCity:GetPopulation()
                        if (iCurrentPop >= 2) then
                            pCity:SetPopulation(math.floor(iCurrentPop * 0.67))
                        end
                    end
                end
            end
         end
    end
end
GameEvents.TeamTechResearched.Add(BigMistakePenalty)
The code as written will not affect City-States or Barbarians.
Thanks! Yeah I've been a bit confused by the inner workings of LUA. Had some java projects to take care of this week as as such did not have time to mess with anything more.
Now I suppose that for the other effect the process is similar right?
 
It depends entirely on whether you would want the player who discovers the -50% Production technology to suffer a permanent hit to production or a one-time hit, really.

A permanent hit of -50% implemented as a modifier from a building or policy can be done fairly "straightforwardly". You add either a dummy building with an empire-wide negative produciton effect to the player's capital, or you add a dummy building with only effects local to a given city to every city the player owns. Or you add a dummy policy that creates the -50% continuous hit to the player when they research the tech. Each of these methods has its own pluses and minuses issues, and would need to be coded in lua in a slightly different manner, including the 'hook' to which the code is subscrbed.

A one-time hit of -50% would require using the same TeamTechResearched hook, and overall approach, but the code needed for each of the player's cities owned at the time the tech is researched would be a bit more complicated than adding a building to each city, or the simple population-change effect in the previous code.

So I can't really answer the question without more info on what you are looking for, and how you would attempt to implement the effect.
 
It depends entirely on whether you would want the player who discovers the -50% Production technology to suffer a permanent hit to production or a one-time hit, really.

A permanent hit of -50% implemented as a modifier from a building or policy can be done fairly "straightforwardly". You add either a dummy building with an empire-wide negative produciton effect to the player's capital, or you add a dummy building with only effects local to a given city to every city the player owns. Or you add a dummy policy that creates the -50% continuous hit to the player when they research the tech. Each of these methods has its own pluses and minuses issues, and would need to be coded in lua in a slightly different manner, including the 'hook' to which the code is subscrbed.

A one-time hit of -50% would require using the same TeamTechResearched hook, and overall approach, but the code needed for each of the player's cities owned at the time the tech is researched would be a bit more complicated than adding a building to each city, or the simple population-change effect in the previous code.

So I can't really answer the question without more info on what you are looking for, and how you would attempt to implement the effect.
Thanks for the reply! So what I am planning to do is a one time hit whenever the player/NPC researches the technology. That would make it feel like the result of overpopulation and paired with the succeeding loss of population would provide a sort of "clean slate" to the civs.
 
You would need to run the following lines on every city belonging to the player when Tech_X is discovered via the TeamTechResearched hook event. Use the previous code as a template for implementing this slightly-different effect for the second technology.

As written it will only affect the Building or Unit currently under production. "Projects" aren't as modder-friendly as far as being able to adjust production amounts at a city level. An entire city build-qeue with any "saved-up" production on each qeued item can also be created but to be honest that's a far far more complicated bit of work to do.
Code:
if pCity:GetProductionNeeded() > 0 then
	local iItemProduction = 0
	if pCity:GetProductionUnit() ~= -1 then
		local iCityProducingItem = pCity:GetProductionUnit()
		iItemProduction = pCity:GetUnitProduction(iCityProducingItem)
	elseif pCity:GetProductionBuilding() ~= -1 then
		local iCityProducingItem = pCity:GetProductionBuilding()
		iItemProduction = pCity:GetBuildingProduction(iCityProducingItem)
	end
	if (iItemProduction >= 2) then
		pCity:ChangeProduction((math.floor(iItemProduction / 2)) * -1)
	end
end
 
Hopefully you wont give up developing this mod. It has many potentials to be fulfilled to be honest. I quite like this mod, it sets a Bridge between Civ 5 and BE, which is amazing! I hope you can broaden its compatibility with many relatable mods.
 
Hopefully you wont give up developing this mod. It has many potentials to be fulfilled to be honest. I quite like this mod, it sets a Bridge between Civ 5 and BE, which is amazing! I hope you can broaden its compatibility with many relatable mods.
Oh , I surely won't, I am planning on reworking the icons nextly. I just made this mod because it was something that I needed for a long time and no-one had made it. Since that is the case, I will, from time to time, release updates.
 
Here it is, the tech tree. Next step, the unit icons.
upload_2019-1-16_17-44-34.png
 
Thanks for updating this mod, lad. I want to also seek this chance to mention one of my old request, could you release a version that is compatible with the future world mod?
 
Thanks for updating this mod, lad. I want to also seek this chance to mention one of my old request, could you release a version that is compatible with the future world mod?
Don't worry, it has been on my ToDo list since you first asked, there's just 4 things in front of it(some a bit difficult, but if they are too much I might skip them) Thank you for enjoying it!
 
Hey guys, so I halted the project because in order for me to continue the LUA scripts would have to be implemented. I gave it a shot while I was developing this and unfortunately it didn't work out. (as a student in computer science, I still only know how to code in Java, C and a bit of Assembly, currently taking an online course on Python) I am willing to release the mod files and resources here in this thread if someone talented is willing to take over this project and give it the attention it very much deserves.

My plan for it included:
-Having the buildings (not all, but some) and resources
-Making the techs exclusive (is that even doable? maybe with a wonder)
-Having the tech cut 1/3 - 2/3 of your pops, since it was a global catastrophe
 
Hey guys, so I halted the project because in order for me to continue the LUA scripts would have to be implemented. I gave it a shot while I was developing this and unfortunately it didn't work out. (as a student in computer science, I still only know how to code in Java, C and a bit of Assembly, currently taking an online course on Python) I am willing to release the mod files and resources here in this thread if someone talented is willing to take over this project and give it the attention it very much deserves.

My plan for it included:
-Having the buildings (not all, but some) and resources
-Making the techs exclusive (is that even doable? maybe with a wonder)
-Having the tech cut 1/3 - 2/3 of your pops, since it was a global catastrophe
I'm currently working on a complete tech overhaul mod spanning from the Paleolithic Era to the Interplanetary Era and I think I could incorporate your project quite a bit into it. If you're interested, feel free to reply or PM me.
 
I'm currently working on a complete tech overhaul mod spanning from the Paleolithic Era to the Interplanetary Era and I think I could incorporate your project quite a bit into it. If you're interested, feel free to reply or PM me.
Cheers! Sorry for the late reply, but with everything that has happened, it has been a wild ride! Anyway, here's most of the assets and project files: (https://drive.google.com/file/d/1f_9FbhO9LzgV9uGHpqR1x7zFBmQvKcde/view?usp=sharing) (I think it's from the latest build), and here's the packaged, game-ready mod: (https://drive.google.com/file/d/1TuoBgGZ-tJjks4EASgVl7lFzQbIm6-4g/view?usp=sharing).

Good Luck!
 
Back
Top Bottom