#Tech removal on death
1 messages ยท Page 1 of 1 (latest)
Hm, I might have been to quick to give you a solution. When you say descendants, what do you mean?
what I mean is that, for example, if you remove the military 4 science, it should clear spidertron, uranium ammo, atomic bomb, etc.
Yup, that is something different D:
maybe checking every tech that has the selected tech as a dependency?

Question, do you want these two also un-researched? or just the single row?
Else, only the ones in the rect will be un-researched
Test this out whenever you have the chance:
local function get_tech_and_neighbour(force, tech_name)
local tech = force.technologies[tech_name]
local main_req
for _, data in pairs(tech.prerequisites) do
main_req = data.name
break
end
for _, data in pairs(force.technologies) do
for _, req in pairs(data.prerequisites) do
if main_req and req.name == main_req then
force.technologies[data.name].researched = false
end
end
end
end
script.on_event(
defines.events.on_player_died,
function(event)
local player_index = event.player_index
local player = game.get_player(player_index)
local force = player.force
local techs = {}
for _, data in pairs(force.technologies) do
if data.researched then
techs[#techs + 1] = data.name
end
end
local count = #techs
if count > 0 then
local tech_name = techs[math.random(1, count)]
if tech_name then
get_tech_and_neighbour(force, tech_name)
end
end
end
)
I think I got this idea when discussing challenges
I'll eventually add more death events, like an atomic bomb
or a behemoth biter spawning
it'd be better with the ones below
pls
uhh.. it... didn't work?
I'm going to sleep right now, I'll continue working on this tomorrow ๐
Final version perhaps? 
local function clear_tech(force, tech_name)
local t = {}
local function get_tech_and_neighbour(filtered_tech)
-- iterate over all technologies and check if they have the filtered tech as a prerequisite
-- if they do, set them to not researched
for _, data in pairs(force.technologies) do
for _, req in pairs(data.prerequisites) do
if req.name == filtered_tech then
force.technologies[data.name].researched = false
force.technologies[req.name].researched = false
t[#t + 1] = data.name
end
end
end
end
get_tech_and_neighbour(tech_name)
if #t > 0 then
for _, tech in pairs(t) do
get_tech_and_neighbour(tech)
end
end
end
script.on_event(
defines.events.on_player_died,
function(event)
local player_index = event.player_index
local player = game.get_player(player_index)
local force = player.force
local techs = {}
for _, data in pairs(force.technologies) do
-- only add researched technologies to the list
if data.researched then
techs[#techs + 1] = data.name
end
end
local count = #techs
if count then
local tech_name = techs[math.random(1, count)]
if tech_name then
-- clear the tech and all its prerequisites
clear_tech(force, tech_name)
game.print('Cleared ' .. tech_name .. ' for ' .. force.name)
end
end
end
)
Hey @lethal badger , sorry to ask you that but could you explain to me the last code you sent, as I'm currently re-writing it to add more features?
and when I started this project I didn't really know what I was copy-pasting

All the code does is, whenever a player dies it removes a technology recursive, meaning if a high tech was picked then all the sub-techs will be unresearched
I got this, I just don't understand lines 5, 6, 7, 19 and 33
Added some comments, let me know if it helps you