1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

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

Discussion in 'Civ5 - Creation & Customization' started by Electric_Gamers, Oct 15, 2018.

?

With or without Aliens?

  1. With

    69.2%
  2. Without

    7.7%
  3. Without, but replace the Harmony Special Units with the GDR and/or the XCOM

    7.7%
  4. With but call them Mutants

    15.4%
  1. LeeS

    LeeS Imperator Supporter

    Joined:
    Jul 23, 2013
    Messages:
    6,867
    Location:
    Illinois, USA
    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.
     
  2. Electric_Gamers

    Electric_Gamers Chieftain

    Joined:
    Oct 15, 2018
    Messages:
    61
    Gender:
    Male
    Location:
    Portugal
    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?
     
  3. LeeS

    LeeS Imperator Supporter

    Joined:
    Jul 23, 2013
    Messages:
    6,867
    Location:
    Illinois, USA
    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.
     
  4. Electric_Gamers

    Electric_Gamers Chieftain

    Joined:
    Oct 15, 2018
    Messages:
    61
    Gender:
    Male
    Location:
    Portugal
    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.
     
  5. LeeS

    LeeS Imperator Supporter

    Joined:
    Jul 23, 2013
    Messages:
    6,867
    Location:
    Illinois, USA
    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
     
  6. bane_

    bane_ Howardianism High-Priest

    Joined:
    Nov 27, 2013
    Messages:
    1,559
    Will you upload the creatures/aliens too?

    Asking for a friend (myself, my only friend).
     
  7. YINGCHENG

    YINGCHENG Warlord

    Joined:
    Oct 25, 2016
    Messages:
    136
    Gender:
    Male
    Location:
    Vancouver BC, Canada
    Can we expect an update happening before the Christmas Eve?
     
  8. Electric_Gamers

    Electric_Gamers Chieftain

    Joined:
    Oct 15, 2018
    Messages:
    61
    Gender:
    Male
    Location:
    Portugal
    Don't really know if that is possible, since I have an Important university test on 21. Might look into it however.
     
  9. YINGCHENG

    YINGCHENG Warlord

    Joined:
    Oct 25, 2016
    Messages:
    136
    Gender:
    Male
    Location:
    Vancouver BC, Canada
    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.
     
  10. Electric_Gamers

    Electric_Gamers Chieftain

    Joined:
    Oct 15, 2018
    Messages:
    61
    Gender:
    Male
    Location:
    Portugal
    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.
     
    YINGCHENG likes this.
  11. Electric_Gamers

    Electric_Gamers Chieftain

    Joined:
    Oct 15, 2018
    Messages:
    61
    Gender:
    Male
    Location:
    Portugal
  12. Electric_Gamers

    Electric_Gamers Chieftain

    Joined:
    Oct 15, 2018
    Messages:
    61
    Gender:
    Male
    Location:
    Portugal
    Here it is, the tech tree. Next step, the unit icons. upload_2019-1-16_17-44-34.png
     
    YINGCHENG likes this.
  13. Electric_Gamers

    Electric_Gamers Chieftain

    Joined:
    Oct 15, 2018
    Messages:
    61
    Gender:
    Male
    Location:
    Portugal
    Sorry to take a long time, just got some free time now. Unit Icons done.
    Spoiler pics :
    upload_2019-2-27_18-20-12.png upload_2019-2-27_18-21-21.png

    Going to release it today. (This is version 2, BTW)
     
    Nutty and YINGCHENG like this.
  14. YINGCHENG

    YINGCHENG Warlord

    Joined:
    Oct 25, 2016
    Messages:
    136
    Gender:
    Male
    Location:
    Vancouver BC, Canada
    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?
     
  15. Electric_Gamers

    Electric_Gamers Chieftain

    Joined:
    Oct 15, 2018
    Messages:
    61
    Gender:
    Male
    Location:
    Portugal
    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!
     
    YINGCHENG likes this.
  16. YINGCHENG

    YINGCHENG Warlord

    Joined:
    Oct 25, 2016
    Messages:
    136
    Gender:
    Male
    Location:
    Vancouver BC, Canada
    I was wondering how the progress is going?
     
  17. Electric_Gamers

    Electric_Gamers Chieftain

    Joined:
    Oct 15, 2018
    Messages:
    61
    Gender:
    Male
    Location:
    Portugal
    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
     
  18. TheOneHitPupper

    TheOneHitPupper Chieftain

    Joined:
    Jun 15, 2017
    Messages:
    84
    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.
     

Share This Page