· 6 years ago · Jan 12, 2020, 06:24 PM
1local requiredAPIVersion = 2.42
2
3pcall(dofile,"scripts/ssccssccAPI.lua")
4
5if not interface_s or interface_s.Version < requiredAPIVersion then
6
7 if tpt.confirm("Download and install file", "Interface API is required to run script. Download it now?") then
8
9 fs.makeDirectory("scripts")
10
11 tpt.getscript(172, "scripts/ssccssccAPI.lua", 1, 0)
12
13 else
14
15 tpt.log("Script is unavailable due to lack of required files.")
16
17 end
18
19end
20
21local DefaultTheme = interface_s.DefaultTheme
22
23local power
24
25local stkm_id = nil
26
27local stkm_direction_y = "none"
28
29local stkm_direction_x = "none"
30
31function setupInterface()
32
33 local MainWindow = interface_s.Components.Window:new(40, 40, 150, 50,true, DefaultTheme.Window)
34
35 MainWindow.AllowResize = false
36
37 MainWindow.AlwaysFocused = true
38
39 local idLabel = interface_s.Components.Label:new(6, 12, "STKM: ", DefaultTheme.Label)
40
41 local idText = interface_s.Components.Textbox:new(45, 10, 70, 12, DefaultTheme.Textbox)
42
43 local idButton = interface_s.Components.Button:new(95, 32, 50, 12, "Submit", DefaultTheme.Button)
44
45 idButton:AddHint("Submit ID")
46
47 local powerLabel = interface_s.Components.Label:new(6, 12, "Power: ", DefaultTheme.Label)
48
49 local powerSelect = interface_s.Components.Combobox:new(45, 10, 70, 12, {"None", "Fly", "Teleport"}, DefaultTheme.Combobox)
50
51 local powerButton = interface_s.Components.Button:new(95, 32, 50, 12, "Select", DefaultTheme.Button)
52
53 powerButton:AddHint("Give Power")
54
55 idButton.OnPressed = function ()
56
57 stkm_id = tonumber(idText.Text)
58
59 if simulation.partProperty(stkm_id, "type") == elements.DEFAULT_PT_STKM then
60
61 idLabel:Hide()
62
63 idText:Hide()
64
65 idButton:Hide()
66
67 powerLabel:Show()
68
69 powerSelect:Show()
70
71 powerButton:Show()
72
73 end
74
75 end
76
77 powerButton.OnPressed = function ()
78
79 power = powerSelect.Items[powerSelect.SelectedIndex + 1]
80
81 end
82
83 local exitButton = interface_s.Components.Button:new(142, 0, 8, 8, "x", DefaultTheme.Button)
84
85 exitButton.OnPressed = (function ()
86
87 interface_s.RemoveComponent(MainWindow)
88
89 end)
90
91 MainWindow:AddComponent(idLabel)
92
93 MainWindow:AddComponent(idText)
94
95 MainWindow:AddComponent(idButton)
96
97 MainWindow:AddComponent(powerLabel)
98
99 MainWindow:AddComponent(powerSelect)
100
101 MainWindow:AddComponent(powerButton)
102
103 MainWindow:AddComponent(exitButton)
104
105 powerLabel:Hide()
106
107 powerSelect:Hide()
108
109 powerButton:Hide()
110
111 interface_s.addComponent(MainWindow)
112
113end
114
115
116
117event.register(event.keypress, function (key, scan, rep, shift, ctrl, alt)
118
119 if scan == 13 and ctrl == true then
120
121 setupInterface()
122
123 end
124
125 if scan == 82 then
126
127 stkm_direction_y = "up"
128
129 end
130
131 if scan == 80 then
132
133 stkm_direction_x = "left"
134
135 end
136
137 if scan == 79 then
138
139 stkm_direction_x = "right"
140
141 end
142
143end)
144
145event.register(event.keyrelease, function (key, scan, rep, shift, ctrl, alt)
146
147 if scan == 82 then
148
149 stkm_direction_y = "none"
150
151 end
152
153 if scan == 80 then
154
155 stkm_direction_x = "none"
156
157 end
158
159 if scan == 79 then
160
161 stkm_direction_x = "none"
162
163 end
164
165end)
166
167event.register(event.mousedown, function (x, y, button)
168
169 if power == "Teleport" then
170
171 if button == 1 then
172
173 if tpt.selectedl == "DEFAULT_PT_STKM" then
174
175 simulation.partProperty(stkm_id, "x", x)
176
177 simulation.partProperty(stkm_id, "y", y)
178
179 end
180
181 end
182
183 end
184
185end)
186
187event.register(event.tick, function ()
188
189 if stkm_id ~= nil then
190
191 if simulation.partProperty(stkm_id, "type") ~= elements.DEFAULT_PT_STKM then
192
193 power = "None"
194
195 end
196
197 end
198
199 if power == "Fly" then
200
201 if stkm_direction_y == "up" then
202
203 simulation.partProperty(stkm_id, "vy", -3)
204
205 end
206
207 if stkm_direction_x == "left" then
208
209 simulation.partProperty(stkm_id, "vx", -1.5)
210
211 end
212
213 if stkm_direction_x == "right" then
214
215 simulation.partProperty(stkm_id, "vx", 1.5)
216
217 end
218
219 end
220
221end)