LUA script to check first time a tech is researched
Posted: Thu May 11, 2017 3:48 pm
I'm trying to write a script to place strategic resources in the map when certain tech is researched the first time.
Something like this:
Can someone help me to modify this script to verify if it is the first time that the tech is researched?
I have seen a new feature for v3.0 (appearance_reqs) that allows what I want without need of any script, but I'm trying to do the script for v2.6
Something like this:
Code: Select all
function place_extra_resources(tech, player, reason)
local tech_name = tech:rule_name()
-- and first time researched
if tech_name == "Gunpowder" then
for place in whole_map_iterate() do
local terr = place.terrain
local tname = terr:rule_name()
if random(1, 100) <= 1 then
if tname == "Desert" then
place:create_extra("Niter")
elseif tname == "Plains" then
place:create_extra("Niter")
end
end
end
end
signal.connect("tech_researched", "place_extra_resources")
I have seen a new feature for v3.0 (appearance_reqs) that allows what I want without need of any script, but I'm trying to do the script for v2.6