forked from JumpyDuke/UniversalProcessKit_FS15
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUPK_PlayerSpawner.lua
69 lines (57 loc) · 2.14 KB
/
UPK_PlayerSpawner.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
-- by mor2000
--------------------
-- PlayerSpawner
local UPK_PlayerSpawner_mt = ClassUPK(UPK_PlayerSpawner,UniversalProcessKit)
InitObjectClass(UPK_PlayerSpawner, "UPK_PlayerSpawner")
UniversalProcessKit.addModule("playerspawner",UPK_PlayerSpawner)
UPK_PlayerSpawner.spawner = {}
UPK_PlayerSpawner.spawnerIndex = 1
function UPK_PlayerSpawner:new(nodeId, parent)
printFn('UPK_PlayerSpawner:new(',nodeId,', ',parent,')')
local self = UniversalProcessKit:new(nodeId, parent, UPK_PlayerSpawner_mt)
registerObjectClassName(self, "UPK_PlayerSpawner")
table.insert(UPK_PlayerSpawner.spawner,self)
self:printFn('UPK_PlayerSpawner:new done')
return self
end
function UPK_PlayerSpawner:delete()
self:printFn('UPK_PlayerSpawner:delete()')
removeValueFromTable(UPK_PlayerSpawner.spawner,self)
UPK_PlayerSpawner.superClass().delete(self)
end
function UPK_PlayerSpawner:setEnable(isEnabled,alreadySent) -- ??
UPK_PlayerSpawner.superClass().setEnable(self,isEnabled,alreadySent)
end
function UPK_PlayerSpawner.togglePlayerSpawner(delta)
self:printFn('UPK_PlayerSpawner.togglePlayerSpawner(',delta,')')
local nrPlayerSpawner = #UPK_PlayerSpawner.spawner
self:printAll('nrPlayerSpawner ',nrPlayerSpawner)
if nrPlayerSpawner > 0 then
local index = UPK_PlayerSpawner.spawnerIndex
local found = false
for i=1,nrPlayerSpawner do
index = index + delta
if index < 1 then
index = nrPlayerSpawner
elseif index > nrPlayerSpawner then
index = 1
end
self:printAll('index ',index)
if UPK_PlayerSpawner.spawner[index].isEnabled then
found = true
break
end
end
if found then
self:printAll('next spawner found!')
self:printAll('index ',index)
UPK_PlayerSpawner.spawnerIndex = index
local spawner = UPK_PlayerSpawner.spawner[index]
local x, y, z = getWorldTranslation(spawner.nodeId)
local miny = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x, 0, z) + 0.5
local dx, _, dz = localDirectionToWorld(spawner.nodeId, 0, 0, 1)
g_client:getServerConnection():sendEvent(PlayerTeleportEvent:new(x, mathmin(y,miny), z))
g_currentMission.player.rotY = Utils.getYRotationFromDirection(dx, dz) + math.pi
end
end
end