-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
181 lines (158 loc) · 5.12 KB
/
Copy pathmain.lua
File metadata and controls
181 lines (158 loc) · 5.12 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
function update()
playerList = tm.players.CurrentPlayers()
for key, player in pairs(playerList) do
pos = tm.players.GetPlayerPosition(player.playerId)
end
if autospawn then
if os.time() - lasttime > 0 then
spawnObject(spawnCallbackData)
lasttime = os.time()
end
end
end
function addUiForPlayer(playerId)
tm.playerUI.AddUIText(playerId, "setSpawnAmount", "1", onSetSpawnAmountTxt)
tm.playerUI.AddUIText(playerId, "objectToSpawn", "Ball", onObjectToSpawnChanged);
tm.playerUI.AddUIButton(playerId, "spawnObject", "Spawn Item", spawnObject, nil)
tm.playerUI.AddUIButton(playerId, "cleanup", "Cleanup spawns ", onCleanupSpawns, nil)
tm.playerUI.AddUIButton(playerId, "enableautospawn", "enable auto spawn", OnAutoSpawnEnable, nil)
tm.playerUI.AddUIButton(playerId, "disableautospawn", "disable auto spawn", OnAutoSpawnDisable, nil)
-- tm.playerUI.AddUIButton(playerId, "Spawnlist", "Spawnlist", Spawnlist, nil)
-- tm.playerUI.AddUIButton(playerId, "PlayerLog", "PlayerLog", PlayerLog, nil)
end
spawnAmount = 1
autospawn = false
lasttime = 0
spawnCallbackData = nil
objectToSpawn = "PFB_MovePuzzleBall"
iscustomobject = false
function OnAutoSpawnEnable(callbackData)
autospawn = true
lasttime = os.time()
spawnCallbackData = callbackData
end
function OnAutoSpawnDisable(callbackData)
autospawn = false
end
function onObjectToSpawnChanged(callbackData)
iscustomobject = false
objectToSpawn = spawnTable[string.lower(callbackData.value)]
if objectToSpawn == nil then
iscustomobject = true
objectToSpawn = customSpawnTable[string.lower(callbackData.value)]
end
end
function onSetSpawnAmountTxt(callbackData)
spawnAmount = tonumber(callbackData.value)
end
function spawn(name, callbackData)
local pos = tm.players.GetPlayerPosition(callbackData.playerId)
local counter = 0
local j = 0
while counter < spawnAmount do
for i = 0, 9 do
if counter >= spawnAmount then
break
end
tm.physics.SpawnObject(tm.vector3.Create(pos.x + 10 + i * 2, pos.y + 2, pos.z + j * 2), name)
counter = counter + 1
end
j = j + 1
end
end
function spawnObject(callbackData)
if iscustomobject then
spawnCustom(objectToSpawn, callbackData)
else
spawn(objectToSpawn, callbackData)
end
end
function spawnCustom(ctable, callbackData)
local pos = tm.players.GetPlayerPosition(callbackData.playerId)
local counter = 0
local j = 0
while counter < spawnAmount do
for i = 0, 9 do
if counter >= spawnAmount then
break
end
tm.physics.SpawnCustomObject(tm.vector3.Create(pos.x + 10 + i * 2, pos.y + 2, pos.z + j * 2), ctable.mesh,
ctable.tex, ctable.static, 1)
counter = counter + 1
end
j = j + 1
end
end
function onCleanupSpawns(callbackData)
tm.physics.ClearAllSpawns()
end
function Spawnlist(callbackData)
spawnList = tm.physics.SpawnableNames()
for k, v in pairs(spawnList) do
tm.os.Log(v)
end
end
function onPlayerJoined(player)
tm.os.Log("player joined")
addUiForPlayer(player.playerId)
end
tm.players.OnPlayerJoined.add(onPlayerJoined)
spawnTable = {
metalball = "PFB_MovePuzzleBall",
ball = "pfb_Ball",
runner = "PFB_Runner",
monkey = "PFB_Runner-Monkey",
ark = "PFB_ArkCollected",
mine = "PFB_Mine",
height = "PFB_Heightjump",
ejs = "PFB_EpicJumpSequence",
redcontainer = "PFB_Container_Red_Dynamic",
orangecontainer = "PFB_Container_Orange_Dynamic",
bluecontainer = "PFB_Container_Blue_Dynamic",
barrel = "PFB_Barrel",
redbarrel = "PFB_ExplosiveBarrel",
wheelstack = "PFB_PropWheelStack",
shipwreck = "PFB_ShipWreck",
ring = "PFB_RacingCheckPoint",
halfring = "PFB_RacingCheckPoint_Halfcircle",
halfpipe = "PFB_Tube3-NoHoles2",
spinner = "PFB_Spinner",
grinder = "PFB_Grinderv2",
hoop = "PFB_BasketBallHoop",
pinetree = "PFB_BulkyPineTree_FBX",
poison = "PFB_PoisonCloud_Explosion",
salvageball = "PFB_SalvageItem_Ball",
salvageballm = "PFB_SalvageItem_Ball_M",
salvageballl = "PFB_SalvageItem_Ball_L",
salvage = "PFB_SalvageItem",
salvagem = "PFB_SalvageItem_M",
salvagel = "PFB_SalvageItem_L",
salvagexl = "PFB_SalvageItem_XL",
rampwedge = "RampWedge",
ringoffire = "PFB_RingofFire",
no = "PFB_IronCrate",
whale = "PFB_Whale"
}
tm.physics.AddMesh("capsule.obj", "capsule")
tm.physics.AddTexture("capsule0.jpg", "capsuleTex")
-- tm.physics.AddMesh("companioncube.obj", "portalcube")
-- tm.physics.AddTexture("companioncube.mtl", "companionCubeTex")
tm.physics.AddMesh("spike.obj", "spike")
tm.physics.AddTexture("spike.mtl", "spikeTex")
customSpawnTable = {
capsule = {
mesh = "capsule",
tex = "capsuleTex",
static = false
},
capsulestatic = {
mesh = "capsule",
tex = "capsuleTex",
static = true
},
spike = {
mesh = "spike",
tex = "nil",
static = false
}
}