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

[GS] Help to Create a New Table (with Lua?)

Discussion in 'Mod Creation Help' started by Zegangani, Oct 16, 2020.

  1. Zegangani

    Zegangani Prince

    Joined:
    Oct 9, 2020
    Messages:
    310
    Gender:
    Male
    I want to add a new table for Buildings (and maybe also for Units) that would require multiple resources cost and maintenance, ie: Buildings_Requirements (BuildingType, MainResourceType, MainResourceCosts, SecondResourceType, SecondResourceCosts, MaintenanceRecourceType, MaintenanceResourceAmount, SecondMaintenanceResourceType, SecondMaintenanceResourceAmount)

    For Example: Building A requires 10 Iron and 5 Horses To be produced, 2 Niter and 2 Coal per turn for maintenance.

    So my Question is: Is this possible? If Yes, do I just need to code it normaly in SQL or do I need to refer this code to Lua in order for the game to make use of it (and how can I make this in lua)?

    Any Help is apreciated!
     
  2. LeeS

    LeeS Imperator Supporter

    Joined:
    Jul 23, 2013
    Messages:
    7,082
    Location:
    Illinois, USA
    There's already a table available for this sort of thing in Gathering Storm. The Definition of the table in the Schema Definitions for Expac2 is
    Code:
    CREATE TABLE "Building_ResourceCosts" (
    		"BuildingType" TEXT NOT NULL,
    		"ResourceType" TEXT NOT NULL,
    		"StartProductionCost" INTEGER NOT NULL,
    		"PerTurnMaintenanceCost" INTEGER NOT NULL,
    		PRIMARY KEY(BuildingType, ResourceType),
    		FOREIGN KEY (BuildingType) REFERENCES Buildings(BuildingType) ON DELETE CASCADE ON UPDATE CASCADE,
    		FOREIGN KEY (ResourceType) REFERENCES Resources(ResourceType) ON DELETE CASCADE ON UPDATE CASCADE);
    Since the PRIMARY KEY requirements of the table is that each new row added to the table must be a unique combination of BuildingType and ResourceType the table should allow multiple different ResourceTypes for the same building.

    The problem with trying to implement such a thing via an lua script for Vanilla and Rise and Fall is that there is no way via lua to directly disable construction of a Building. You can however disable construction of a unit when running Gathering Storm via lua (and later restore construction of the same unit), but I have not checked whether this lua method is valid in Vanilla and Rise and Fall, and you cannot use the available method in GS to allow one city to construct the unit while another city cannot. You can via lua alter (ie, Change) a player's available resource amounts but you cannot tie this directly to the construction of a building via an lua script. And neither Vanilla nor Rise and Fall are really structured to handle "resource consumption" as Gathering Storm is.

    In order to disable/enable construction of a unit on a city-by-city basis it would be necessary to have every unit require a specific dummy building, and place or remove that dummy building from each city as needed as a player used up the available resources to "start" the construction of the unit when more than one resource-type is to be required. The script could get a bit complicated I would think based on my experience using dummy building to allow/disallow construction of "real" buildings within cities.
     
    Last edited: Oct 17, 2020
    Zegangani likes this.
  3. Zegangani

    Zegangani Prince

    Joined:
    Oct 9, 2020
    Messages:
    310
    Gender:
    Male
    Thank you LeeS for the answer!
    I knew of the GS table but I didn't thought you can list the same building type more than one time (forgot about the primary key). I've just tested it and it works just fine for the buildings (with the new tooltip I've made for buildings showing all the Resources required), but not for Units (of course).

    Another question: I've tried to make a New table for Improvements to make use of the Bridge column from Buildings_XP2 for imrovements (I want to make a Bridge Improvement), but it didn't work out, I mean the Improvement which I've tested with the bridge boolean activated couldn't make a bridge (units crossing the improvement would still embark), despite I have built the improvement in a plot which resembles the plot requirement for the San Fransisco Bridge (that use the bridge effect from Buildings_XP2). Is that because the bridge effect is tied to the DLL or some lua code? And is it possible to make plot requirements for building something on the map via lua (ie: an improvements requires 1 plot behind it to be Land and 3 plots in front of her to be ocean/coast)? Any idea of how I can make the units to not embark on the improvement?

    Thanks in advance!
     
    Last edited: Oct 17, 2020
  4. LeeS

    LeeS Imperator Supporter

    Joined:
    Jul 23, 2013
    Messages:
    7,082
    Location:
    Illinois, USA
    Every column is specific to the table where it appears. They are not universally usable in other tables. This is because the effect of every column within a table is specifically coded within the game's DLL. Even when two or more table have the same column-name, each of these columns in each of these tables is specifically coded within the DLL. So you cannot "borrow" column-names from one table into another.

    I can't think of any way this can be done since lua cannot effect whether or not a plot can have improvement-X other than to alter the base terrain itself or the features/resources the plot contains. Even though we can alter base plot terrain via lua, the alteration does not generally show graphically until a save and reload of the game. And if you did alter the plot from a coastal or ocean plot to a land plot of some TerrainType, the plot would be a land plot, and sea units would not be able to traverse it.
     
    Zegangani likes this.
  5. Zegangani

    Zegangani Prince

    Joined:
    Oct 9, 2020
    Messages:
    310
    Gender:
    Male
    Thank you for those informations! I really appreciate your help LeeS!!
     

Share This Page