forked from JohnnyCheese/TTS_X-Wing2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTractor.ttslua
144 lines (120 loc) · 3.66 KB
/
Tractor.ttslua
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
-- ~~~~~~
-- Script by dzikakulka
-- Issues, history at: http://github.com/tjakubo2/TTS_xwing
--
-- Target lock color and name script
-- ~~~~~~
-- Scripted token properties
__XW_Token = true
__XW_TokenIdle = true
__XW_TokenType = 'tractor'
-- Was this lock tinted and named already?
set = false
-- Colors for tinting on pickup
-- Save self state
function onSave()
if set then
local state = {set=set}
return JSON.encode(state)
end
end
-- Restore self state
function onLoad(save_state)
if save_state ~= '' and save_state ~= 'null' and save_state ~= nil then
set = JSON.decode(save_state).set
--[[
assetTable = {
{name="BoostS", url="http://cloud-3.steamusercontent.com/ugc/816750219423811083/7C1C7A560593EDFF93D9D5DA5A79B44ADF504860/"},
{name="BarrelL", url="http://cloud-3.steamusercontent.com/ugc/816750219423807162/1DA310CD1B412508B5213EE37476F2A2EB9B4A38/"},
{name="BarrelLF", url="http://cloud-3.steamusercontent.com/ugc/816750219423808004/8BEBBB8A447DA3F335AE361885BD3E8599C95490/"},
{name="BarrelLB", url="http://cloud-3.steamusercontent.com/ugc/816750219423808688/985FC18E99432A2C05B54F2B0E5C151BD6B582D2/"},
{name="BarrelR", url="http://cloud-3.steamusercontent.com/ugc/816750219423809409/5196FEE75132E292D9E22F7B3054F396CC4EB04A/"},
{name="BarrelRF", url="http://cloud-3.steamusercontent.com/ugc/816750219423809765/75916DF74C1B0A8AC752204D20622EAC349D7723/"},
{name="BarrelRB", url="http://cloud-3.steamusercontent.com/ugc/816750219423810373/C796629CCC0BE925B9CCFF9090439C21534EB9EC/"}}
self.UI.setCustomAssets(assetTable)--]]
end
end
-- Set function for external calls
function manualSet(arg)
ship=arg.ref
set = true
self.UI.setAttribute("Center", "active", "true")
end
-- Set name on drop near a ship
function onDropped()
local spos = self.getPosition()
local nearest = nil
local minDist = 3.6125 -- 100 mm
for k,ship in pairs(getAllObjects()) do
if ship.tag == 'Figurine' and ship.getName() ~= '' then
local pos = ship.getPosition()
local dist = math.sqrt(math.pow((spos[1]-pos[1]),2) + math.pow((spos[3]-pos[3]),2))
if dist < minDist then
nearest = ship
minDist = dist
end
end
end
if nearest ~= nil then
ship = nearest
set = true
self.setRotation(nearest.getRotation())
printToAll(ship.getName().." takes a tractor token")
else
ship = nil
set = false
end
end
stat=false
function onContextOpen(player_color)
showBtn()
end
function showBtn()
if stat==false and ship~=nil then
if self.is_face_down then
self.UI.setAttribute("btnPanel", "rotation", "180 0 0")
self.UI.setAttribute("btnPanel", "position", "0 0 30")
else
self.UI.setAttribute("btnPanel", "rotation", "0 0 180")
self.UI.setAttribute("btnPanel", "position", "0 0 -30")
end
self.UI.show("btnPanel")
stat=true
end
end
function hideBtn()
if stat==true then
self.UI.hide("btnPanel")
stat=false
end
end
function BstS()
ship.setDescription('s1b')
end
function BlF()
ship.setDescription('rl1')
end
function Bl()
ship.setDescription('rl2')
end
function BlB()
ship.setDescription('rl3')
end
function BrF()
ship.setDescription('rr1')
end
function Br()
ship.setDescription('rr2')
end
function BrB()
ship.setDescription('rr3')
end
function RotL()
ship.setDescription('tl4')
end
function RotR()
ship.setDescription('tr4')
end
function Delete()
self.destruct()
end