2018-12-31 04:47:53 +02:00
|
|
|
-- enemy units yield coins -- by mewmew
|
|
|
|
|
|
|
|
local event = require 'utils.event'
|
|
|
|
local insert = table.insert
|
|
|
|
|
|
|
|
local coin_yield = {
|
|
|
|
["small-biter"] = 1,
|
|
|
|
["medium-biter"] = 2,
|
|
|
|
["big-biter"] = 3,
|
2019-01-01 18:17:18 +02:00
|
|
|
["behemoth-biter"] = 5,
|
2018-12-31 04:47:53 +02:00
|
|
|
["small-spitter"] = 1,
|
|
|
|
["medium-spitter"] = 2,
|
|
|
|
["big-spitter"] = 3,
|
2019-01-01 18:17:18 +02:00
|
|
|
["behemoth-spitter"] = 5,
|
2018-12-31 04:47:53 +02:00
|
|
|
["spitter-spawner"] = 32,
|
|
|
|
["biter-spawner"] = 32,
|
|
|
|
["small-worm-turret"] = 8,
|
|
|
|
["medium-worm-turret"] = 16,
|
2019-10-15 05:56:30 +02:00
|
|
|
["big-worm-turret"] = 24,
|
|
|
|
["behemoth-worm-turret"] = 32,
|
2018-12-31 04:47:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
local entities_that_earn_coins = {
|
|
|
|
["artillery-turret"] = true,
|
|
|
|
["gun-turret"] = true,
|
|
|
|
["laser-turret"] = true,
|
|
|
|
["flamethrower-turret"] = true
|
|
|
|
}
|
|
|
|
|
|
|
|
local function on_entity_died(event)
|
2019-02-10 06:16:01 +02:00
|
|
|
if not event.entity.valid then return end
|
2018-12-31 04:47:53 +02:00
|
|
|
if event.entity.force.name ~= "enemy" then return end
|
|
|
|
if not coin_yield[event.entity.name] then return end
|
|
|
|
|
|
|
|
local players_to_reward = {}
|
|
|
|
local reward_has_been_given = false
|
|
|
|
|
|
|
|
if event.cause then
|
|
|
|
if event.cause.valid then
|
2019-05-02 21:17:22 +02:00
|
|
|
if event.cause.name == "character" then
|
2018-12-31 04:47:53 +02:00
|
|
|
insert(players_to_reward, event.cause)
|
|
|
|
reward_has_been_given = true
|
|
|
|
end
|
|
|
|
if event.cause.type == "car" then
|
2019-10-14 20:38:27 +02:00
|
|
|
local player = event.cause.get_driver()
|
|
|
|
local passenger = event.cause.get_passenger()
|
2018-12-31 04:47:53 +02:00
|
|
|
if player then insert(players_to_reward, player.player) end
|
|
|
|
if passenger then insert(players_to_reward, passenger.player) end
|
|
|
|
reward_has_been_given = true
|
|
|
|
end
|
|
|
|
if event.cause.type == "locomotive" then
|
2019-10-14 20:38:27 +02:00
|
|
|
local train_passengers = event.cause.train.passengers
|
2018-12-31 04:47:53 +02:00
|
|
|
if train_passengers then
|
|
|
|
for _, passenger in pairs(train_passengers) do
|
|
|
|
insert(players_to_reward, passenger)
|
|
|
|
end
|
|
|
|
reward_has_been_given = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for _, player in pairs(players_to_reward) do
|
|
|
|
player.insert({name = "coin", count = coin_yield[event.entity.name]})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if entities_that_earn_coins[event.cause.name] then
|
|
|
|
event.entity.surface.spill_item_stack(event.cause.position,{name = "coin", count = coin_yield[event.entity.name]}, true)
|
|
|
|
reward_has_been_given = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if reward_has_been_given == false then
|
|
|
|
event.entity.surface.spill_item_stack(event.entity.position,{name = "coin", count = coin_yield[event.entity.name]}, true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
event.add(defines.events.on_entity_died, on_entity_died)
|