xxhe
Prince
Hi everybody:
I want to add xml tags that work through Lua as the title said. However, I want to do it by inserting tables instead of columns to fulfill my goal. The reason is that I find adding tables is more modular then adding columns, and thus it's easier to be used as mod components. Below is my lua code and XML code, I'm now at work so I cannot try it. Could anybody look at it to tell me if I made any mistakes?
Thank you!
Edit: Sorry that I don't know why but the format of the code became a mess when I put it the spoiler
XML:
<GameData>
<Table name="Building_PrereqPolicy">
<Column name="BuildingType" type="text" reference="Buildings(Type)"/>
<Column name="PolicyType" type="text" reference="Policies(Type)"/>
</Table>
<Building_PrereqPolicy>
<Row>
<BuildingType>BUILDING_MONUMENT</BuildingType>
<PolicyType>POLICY_PIETY</PolicyType>
</Row>
</Building_PrereqPolicy>
</GameData>
Lua:
function BuildingPrereqPolicy(iPlayer, buildingTypeID)
local buildingType = GameInfo.Buildings[buildingTypeID].Type;
local prereqPolicy = GameInfo.Building_PrereqPolicy[buildingType].PolicyType;
local player = Players[iPlayer];
if prereqPolicy then
local policyID = GameInfo.Policies[PrereqPolicy].ID
if not player:HasPolicy(policyID) then
return false
end
end
return true
end
GameEvents.PlayerCanConstruct.Add( BuildingPrereqPolicy );
I want to add xml tags that work through Lua as the title said. However, I want to do it by inserting tables instead of columns to fulfill my goal. The reason is that I find adding tables is more modular then adding columns, and thus it's easier to be used as mod components. Below is my lua code and XML code, I'm now at work so I cannot try it. Could anybody look at it to tell me if I made any mistakes?
Thank you!
Edit: Sorry that I don't know why but the format of the code became a mess when I put it the spoiler
XML:
Spoiler :
<GameData>
<Table name="Building_PrereqPolicy">
<Column name="BuildingType" type="text" reference="Buildings(Type)"/>
<Column name="PolicyType" type="text" reference="Policies(Type)"/>
</Table>
<Building_PrereqPolicy>
<Row>
<BuildingType>BUILDING_MONUMENT</BuildingType>
<PolicyType>POLICY_PIETY</PolicyType>
</Row>
</Building_PrereqPolicy>
</GameData>
Lua:
Spoiler :
function BuildingPrereqPolicy(iPlayer, buildingTypeID)
local buildingType = GameInfo.Buildings[buildingTypeID].Type;
local prereqPolicy = GameInfo.Building_PrereqPolicy[buildingType].PolicyType;
local player = Players[iPlayer];
if prereqPolicy then
local policyID = GameInfo.Policies[PrereqPolicy].ID
if not player:HasPolicy(policyID) then
return false
end
end
return true
end
GameEvents.PlayerCanConstruct.Add( BuildingPrereqPolicy );