-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathVehicleSpawnerUI.lua
More file actions
160 lines (153 loc) · 5.89 KB
/
Copy pathVehicleSpawnerUI.lua
File metadata and controls
160 lines (153 loc) · 5.89 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
-- Register the behaviour
behaviour("VehicleSpawnerUI")
function VehicleSpawnerUI:Start()
self.isActive = false
self.dropDownMenu = nil
self.selectedVehicle = nil
self.listOfTurrets = {}
self.cstmKey = KeyCode.K
self.listOfVehicles = {}
self.canvasVehicleSpawner = self.targets.canvasTar
self.dropDownMenu = self.targets.dropdownMenu.GetComponent(Dropdown)
self.scriptvar = self.script
self.targets.buttonTar.GetComponent(Button).onClick.AddListener(self, "ButtonPress")
self.targets.selectedTeamButton.GetComponent(Button).onClick.AddListener(self, "SelTeamButton")
self.isActive = false
self.currentTeam = Player.actor.team
if self.currentTeam == Team.Blue then
self.targets.selectedTeamButton.GetComponentInChildren(Text).text = "Eagle"
self.targets.selectedTeamButton.GetComponentInChildren(Text).color = Color(0, 0, 1)
else
self.targets.selectedTeamButton.GetComponentInChildren(Text).text = "Raven"
self.targets.selectedTeamButton.GetComponentInChildren(Text).color = Color(1, 0, 0)
end
self.canvasVehicleSpawner.setActive(false)
self.script.StartCoroutine("GetVehicles")
self.script.StartCoroutine("getKeyFromString")
self.vehiclePrefabList = {}
self.turretPrefabList = {}
end
function VehicleSpawnerUI:getKeyFromString()
coroutine.yield(WaitForSeconds(1.3))
local go = GameObject.Find("Custom Keybinds")
if (go ~= nil) then
local customKB = ScriptedBehaviour.GetScript(go)
local key = self.script.mutator.GetConfigurationString("ctmKey")
if (key ~= nil or key ~= "") then
local kcode = customKB:getKeyCodeFromCustomKey(key)
if (kcode ~= nil and kcode ~= KeyCode.None) then
self.cstmKey = kcode
end
end
end
end
function VehicleSpawnerUI:SelTeamButton()
if self.currentTeam == Team.Blue then
self.currentTeam = Team.Red
self.targets.selectedTeamButton.GetComponentInChildren(Text).text = "Raven"
self.targets.selectedTeamButton.GetComponentInChildren(Text).color = Color(1, 0, 0)
else
if self.currentTeam == Team.Red then
self.currentTeam = Team.Blue
self.targets.selectedTeamButton.GetComponentInChildren(Text).text = "Eagle"
self.targets.selectedTeamButton.GetComponentInChildren(Text).color = Color(0, 0, 1)
end
end
self.script.StartCoroutine("GetVehicles")
end
function VehicleSpawnerUI:GetVehicles()
local tempArray = {}
for k in pairs(self.listOfVehicles) do
self.listOfVehicles[k] = nil
end
for k in pairs(self.listOfTurrets) do
self.listOfTurrets[k] = nil
end
local jeep = VehicleSpawner.GetPrefab(self.currentTeam, VehicleSpawnType.Jeep)
local quad = VehicleSpawner.GetPrefab(self.currentTeam, VehicleSpawnType.Quad)
local jeepMG = VehicleSpawner.GetPrefab(self.currentTeam, VehicleSpawnType.JeepMachineGun)
local tank = VehicleSpawner.GetPrefab(self.currentTeam, VehicleSpawnType.Tank)
local ah = VehicleSpawner.GetPrefab(self.currentTeam, VehicleSpawnType.AttackHelicopter)
local ap = VehicleSpawner.GetPrefab(self.currentTeam, VehicleSpawnType.AttackPlane)
local rhib = VehicleSpawner.GetPrefab(self.currentTeam, VehicleSpawnType.Rhib)
local ab = VehicleSpawner.GetPrefab(self.currentTeam, VehicleSpawnType.AttackBoat)
local bp = VehicleSpawner.GetPrefab(self.currentTeam, VehicleSpawnType.BomberPlane)
local th = VehicleSpawner.GetPrefab(self.currentTeam, VehicleSpawnType.TransportHelicopter)
local apc = VehicleSpawner.GetPrefab(self.currentTeam, VehicleSpawnType.Apc)
self.dropDownMenu.ClearOptions()
for i = 0, 10, 1 do
local prefab = VehicleSpawner.GetPrefab(self.currentTeam, i)
local name = prefab.GetComponent(Vehicle).name
self.dropDownMenu.AddOptions({name})
table.insert(self.listOfVehicles, {prefab, name})
end
local mg = TurretSpawner.GetPrefab(self.currentTeam, TurretSpawnType.MachineGun)
local at = TurretSpawner.GetPrefab(self.currentTeam, TurretSpawnType.AntiTank)
local aa = TurretSpawner.GetPrefab(self.currentTeam, TurretSpawnType.AntiAir)
for turret = 0, 2, 1 do
local prefab = TurretSpawner.GetPrefab(self.currentTeam, turret)
local name = prefab.gameObject.GetComponent(Vehicle).name
self.dropDownMenu.AddOptions({name})
table.insert(self.listOfTurrets, {prefab, name})
table.insert(self.listOfVehicles, {prefab, name})
end
self.dropDownMenu.RefreshShownValue()
end
function VehicleSpawnerUI:ButtonPress()
local ray =
Ray(
PlayerCamera.activeCamera.main.transform.position + PlayerCamera.activeCamera.main.transform.forward * 1,
PlayerCamera.activeCamera.main.transform.forward
)
local raycast = Physics.Raycast(ray, 50, RaycastTarget.ProjectileHit)
self.selectedVehicle = nil
if raycast ~= nil then
for i, y in ipairs(self.listOfVehicles) do
if y[2] == self.dropDownMenu.captionText.text then
self.selectedVehicle = y[1].gameObject
end
end
if (self.selectedVehicle == nil) then
print("self.selectedVehicle was nil. No " .. tostring(self.dropDownMenu.captionText.text) .. " found")
return
end
local vehicle = GameObject.Instantiate(self.selectedVehicle)
local isTurret = false
if vehicle ~= nil then
local pos = raycast.point - PlayerCamera.activeCamera.main.transform.forward
local vehicletransform = vehicle.transform
for z, t in ipairs(self.listOfTurrets) do
if self.selectedVehicle.gameObject.name == t[1].name then
isTurret = true
end
end
if not isTurret then
pos = pos + Vector3(0, 2, 0)
else
pos = pos + Vector3(0, 0, 0)
end
local direction = pos - Player.actor.position
direction = Vector3(direction.x, 0, direction.z)
vehicle.transform.rotation = Quaternion.LookRotation(direction)
vehicle.transform.position = pos
else
print("<color=red>Vehicle not found</color>")
end
else
print("Raycast was nil")
end
end
function VehicleSpawnerUI:Update()
if Input.GetKeyDown(self.cstmKey) then
if self.isActive then
Screen.UnlockCursor()
self.canvasVehicleSpawner.setActive(false)
self.isActive = false
Screen.LockCursor()
else
self.canvasVehicleSpawner.setActive(true)
self.isActive = true
Screen.UnlockCursor()
end
end
end