first lua mod help

RandyG

Chieftain
Joined
Mar 18, 2012
Messages
60
Location
Huntsville, AL
I made a new civ mod using xml and it works, so no problems there. Now I want to make my UB do something, well... unique, so I need to expand beyond xml.

I have been looking at the lua mod wiki for civ5 and at lua code in other mods, but I am still not sure how to get started with this. Lua is new to me, but I have done some programming in the past, so I understand for and while loops and if statements. I have been experimenting with file tuner, but it does not seem to be very helpful at the moment. I guess I am just not sure how to get started or how to go about debugging. Anyways, here is what I am trying to do:

if player city has UB then
N = number of nations player is trading with this turn
On the next turn, give percent increase in gold genertated by this city equal to N times a constant
end

I would like to exclude things like open boarders agreements, acceptance of embassies, and research agreements. Basically, when I say trade I am just thinking of interactions involving gold, luxuries, and resources. And by trading with this turn, I mean that if the player makes a trade agreement for say 240 gold for gyms or 5 gpt for 3 iron for 30 turns then for the next 30 turns the player's city with the UB would get a bonus. Multiple trades with the same nation would not stack.

Right now I am looking for someone to help me get started with lua or at least point me to a relevant thread. Of course, if anyone would like to write some of this code for me, I would certainly appreciate it. Also if this is not possible please let me know.
 
I'm not sure if player:getNumTradeResourceImports() will return the number you want but this pseudo code may do what you're aiming for:

Code:
GameEvents.PlayerDoTurn.Add(myFunc);

function myFunc(playerID)
  thisPlayer = Players[playerID];

  forEach(otherPlayer in Players[])
    if(thisplayer:getNumTradeResourceImports(otherPlayer) > 0)
      increment counter;
    endIf
  endForEach

  -- Now give out bonuses
  forEach(city in thisPlayer:cities)
    city:SetNumRealBuilding(myBuildingType, counter)
  endForEach
end

You'll need to define a new building "myBuildingType" that gives +N% gold.
 
thanks for the help so far

You'll need to define a new building "myBuildingType" that gives +N% gold.

Is it possible to create a new building class/type?

I searched through the forums looking for an answer to this question but with no success. I know how to change what an existing building does using xml, but obviously that will not work here.
 
Is it possible to create a new building class/type?

Alternatively, would it be possible to update the <Building_YieldModifiers> at the end of a turn. For example, the market:

Code:
<Row> 
<BuildingType>BUILDING_MARKET</BuildingType> 
<YieldType>YIELD_GOLD</YieldType> 
<Yield>25</Yield> 
</Row>

Is is possible to update the yield amount at the end of every turn.
 
So I still have not been able to figure this one out, but I thought of another way that it may be possible. This is a little bit more complicated than the my previous idea, but other modders are doing similar things so there are more examples for me to look at.

The new idea is to write a lua script that checks to see if the unique building is in a city. If the building is there, then the bonus would be applied to the city directly. In other words the building modifier would not be updated or even need to exist in the first place.

There are mods that initiate random events at the beginning of a turn, so this would work somewhat like that. Instead of being random the lua script would check at the end or beginning of every turn and then apply the city bonuses if the building is there.

what I need to do at the beginning/end of a turn:

1) check to see if the civ is my new civ, if it is then
2) determine gold produced by each city individually
3) determine gold bonus based on number of trading partners
4) apply bonus to each city
5) display bonus amount somewhere (e.g. where you mouse over the gold icon in the top left of the screen)

Machiavelli24 has given me some code for 1 and 3. If anyone would like to expand on this, knows how to do the rest, or knows of a mod that does something similar that I can look at, please let me know. Thanks.
 
Top Bottom