Hi Folks,
I'm trying to make a mod where techs require certain resources (iron working demands that you have iron, horse riding needs horses, etc)
I've written an SQL that adds a prereqResource column to the technologies table, and a lua test that I think will make techs unavailable if and only if the prerequisites are not met. The database definitely updates, but I can't find any evidence in the logs that the lua is being run at all...
Here's my lua:
and the full mod is hopefully attached. Would greatly appreciate any pointers on what I'm doing wrong here... Thanks in advance.
Thanks also to Pazyryk and Whoward for their extremely helpful posts - that's the only way I got this far!
I'm trying to make a mod where techs require certain resources (iron working demands that you have iron, horse riding needs horses, etc)
I've written an SQL that adds a prereqResource column to the technologies table, and a lua test that I think will make techs unavailable if and only if the prerequisites are not met. The database definitely updates, but I can't find any evidence in the logs that the lua is being run at all...
Here's my lua:
Spoiler :
function ResourceCheck(iPlayerID, iTechType)
print ('Running Resource checker...') --test to see if it runs at all
local prereqResource = GameInfo.Technologies[iTechType].PrereqResource
if prereqResource then
local pPlayer = Players[iPlayerID]
local resourceID = GameInfo.Resources[prereqResource].ID
local resAvailable = pPlayer:GetNumResourceAvailable(resourceID, true)
if res_total > 0 then
return true
else
return false
end
print ('Tech = 'GameInfo.Technologies[iTechType] ' Status: ' GameEvents.PlayerCanEverResearch) --prints the boolean outcome of CanEverResearch on anything that had a resource dependency
end
return true
print ('Resource Checker finished')
end
GameEvents.PlayerCanEverResearch.Add(ResourceCheck)
print ('Running Resource checker...') --test to see if it runs at all
local prereqResource = GameInfo.Technologies[iTechType].PrereqResource
if prereqResource then
local pPlayer = Players[iPlayerID]
local resourceID = GameInfo.Resources[prereqResource].ID
local resAvailable = pPlayer:GetNumResourceAvailable(resourceID, true)
if res_total > 0 then
return true
else
return false
end
print ('Tech = 'GameInfo.Technologies[iTechType] ' Status: ' GameEvents.PlayerCanEverResearch) --prints the boolean outcome of CanEverResearch on anything that had a resource dependency
end
return true
print ('Resource Checker finished')
end
GameEvents.PlayerCanEverResearch.Add(ResourceCheck)
and the full mod is hopefully attached. Would greatly appreciate any pointers on what I'm doing wrong here... Thanks in advance.
Thanks also to Pazyryk and Whoward for their extremely helpful posts - that's the only way I got this far!