-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.lua
112 lines (86 loc) · 3.77 KB
/
control.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
local reloadP = require("scripts.reloadPods")
local Unlink = function(event)
if event.entity then
if event.entity.grid then
--reloadP.UnloadPods({event.entity}, nil, nil)
--reloadP.GridLosesOwnerEntity(event.entity.grid) -- if factorio keeps grid and destroys only inventory
reloadP.GridIsDead(nil, event.entity.grid) -- if factorio destroys grid too
-- else game.print ("Mined vehicle has no equipment grid!")
end
end
end
local Link = function(event)
-- reloadP.GridGetsOwner(event.created_entity, false)
reloadP.EntityBuiltRaised(event) -- assuming someone is playing with entities, transferring grid equipment and other things
end
local KilledGridOwner = function(event)
if event.entity and event.entity.grid then reloadP.GridIsDead(nil, event.entity.grid) end
end
local function add_hooks()
if settings.startup["zd-AllVehiclesSupport"].value then
-- ** any vehicle support
-- ?? on_entity_destroyed event.unit_number
script.on_event( defines.events.on_built_entity, Link, {{filter = "vehicle"}} )
script.on_event( defines.events.on_robot_built_entity, Link, {{filter = "vehicle"}} )
script.on_event( defines.events.on_entity_died, KilledGridOwner, {{filter = "vehicle"}} )
script.on_event( defines.events.on_pre_player_mined_item, Unlink, {{filter = "vehicle"}} )
script.on_event( defines.events.on_robot_pre_mined, Unlink, {{filter = "vehicle"}} )
script.on_event( defines.events.script_raised_destroy, reloadP.EntityDestruction, {{filter = "vehicle"}} )
script.on_event( defines.events.script_raised_built, reloadP.EntityBuiltRaised, {{filter = "vehicle"}} )
else
-- ** only driven vehicles support
script.on_event(defines.events.on_player_driving_changed_state, function (event)
local player = game.get_player(event.player_index)
reloadP.DrivingState(player)
end)
end
if settings.startup["zd-PlayerArmorSupport"].value then
-- ** human armor support option
-- on_player_armor_inventory_changed
-- ?? on_player_died
-- ~~ ?? and multiplayer is supported ???
-- on_player_removed
-- on_player_kicked
-- on_player_left_game
-- on_player_joined_game
end
end
script.on_init(function()
reloadP.Init()
add_hooks()
end)
script.on_load(function()
reloadP.OnLoad()
add_hooks()
end)
script.on_configuration_changed(function()
reloadP.AddMagazines()
for _, surface in pairs(game.surfaces) do
local vehicles = surface.find_entities_filtered({ type = {"car"}, force = "player" })
for _, entity in pairs(vehicles) do
reloadP.GridGetsOwner(entity, true)
end
end
end)
script.on_event(defines.events.on_runtime_mod_setting_changed, function(e)
if e.setting == "zd-AllowChangeAmmo" then global.reloadP.AllowChangeAmmo = settings.global["zd-AllowChangeAmmo"].value end
--game.print("Auto ammunition reset setting was changed!")
end)
script.on_event(defines.events.on_tick, function(event)
reloadP.EveryTick(global.reloadPods.equipped_weapon_id, game.ticks_played)
if global.reloadPods.equipped_weapon_id >= global.reloadPods.equipped_weapon_last then global.reloadPods.equipped_weapon_id = 1
else global.reloadPods.equipped_weapon_id = global.reloadPods.equipped_weapon_id + 1 end
end)
script.on_event(defines.events.on_player_selected_area, function (event)
local player = game.get_player(event.player_index)
if event.item == "zd-ammo-unload" then
reloadP.UnloadPods(event.entities, player, event.area, event.tick + 1200)
end
end)
script.on_event(defines.events.on_player_placed_equipment, function (event)
reloadP.NewEquipment(event.equipment, event.grid)
end)
script.on_event(defines.events.on_player_removed_equipment, function (event)
local player = game.get_player(event.player_index)
reloadP.RemoveEquipment(event.equipment, event.grid, event.count, player)
end)