-
Notifications
You must be signed in to change notification settings - Fork 4
/
onelife.lua
123 lines (113 loc) · 3.77 KB
/
onelife.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
113
114
115
116
117
118
119
120
121
122
123
-- Carl Frank Otto III
-- carlotto81@gmail.com
-- GitHub: https://github.com/M45-Science/SoftMod
-- License: MPL 2.0
-- Safe console print
function ONELIFE_Main(event)
if not storage.SM_Store.oneLifeMode then
return
end
if not event or not event.player_index then
return
end
local player = game.players[event.player_index]
if not player or not player.valid then
return
end
if UTIL_Is_Banished(player) then
return
end
player.set_controller {
type = defines.controllers.spectator
}
UTIL_SmartPrint(player, "Game over! you are now a spectator.")
ONLINE_UpdatePlayerList()
if not player.character or not player.character.valid then
return
end
local character = player.character
-- Stop player states, or they will continue forever
character.walking_state = {
walking = false,
direction = defines.direction.south
}
character.riding_state = {
acceleration = defines.riding.acceleration.braking,
direction = defines.riding.direction.straight
}
character.shooting_state = {
state = defines.shooting.not_shooting,
position = character.position
}
character.mining_state = {
mining = false
}
character.picking_state = false
character.repair_state = {
repairing = false,
position = character.position
}
end
function ONELIFE_Clicks(event)
if not storage.SM_Store.oneLifeMode then
return
end
if not event or not event.player_index then
return
end
local player = game.players[event.player_index]
if not player or not player.valid then
return
end
if UTIL_Is_Banished(player) then
return
end
if not player.character or not player.character.valid then
UTIL_SmartPrint("You are already dead!")
return
end
if event.element and event.element.valid and event.element.name == "spec_button" then
-- Otherwise confirm
if storage.PData[player.index].permDeath then
if storage.PData[player.index].permDeath >= 2 then
storage.PData[player.index].permDeath = nil
player.character.die("player")
ONELIFE_Main(event)
return
elseif storage.PData[player.index].permDeath < 2 then
UTIL_SmartPrintColor(player,
"[color=red](NO UNDO, PERM-DEATH) -- click " .. 2 - storage.PData[player.index].permDeath ..
" more times to confirm.[/color]")
end
storage.PData[player.index].permDeath = storage.PData[player.index].permDeath + 1
end
end
end
function ONELIFE_MakeButton(player)
if not player then
return
end
if player.gui.top.spec_button then
player.gui.top.spec_button.destroy()
end
if storage.SM_Store.oneLifeMode and storage.SM_Store.oneLifeMode == false then
if player.controller_type == defines.controllers.spectator then
player.set_controller {
type = defines.controllers.character,
character = game.surfaces[1].create_entity({ name = "character", position = game.surfaces[1].find_non_colliding_position("character", { x = 0, y = 0 }, 1024, 1, false), force = game.forces.player })
}
UTIL_SmartPrint(player, "You have been revived!")
ONLINE_UpdatePlayerList()
end
return
end
if not player.gui.top.spec_button then
local m45_32 = player.gui.top.add {
type = "sprite-button",
name = "spec_button",
sprite = "file/img/buttons/spectate.png",
tooltip = "Kills you forever to become spectator (NO UNDO)"
}
m45_32.style.size = { 64, 64 }
end
end