-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCustomFlag.lua
More file actions
179 lines (154 loc) · 5.95 KB
/
Copy pathCustomFlag.lua
File metadata and controls
179 lines (154 loc) · 5.95 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
-- Register the behaviour
-- If you use this in a mod just give me credit somewhere
-- This is currently really messy, because there is no event for checking if a player is capturing a flag
behaviour("CustomFlag")
local customFlagMat
local customFlagMatBlue
local customFlagMatNeutral
local customFlagMatRed
local setFlag = false
function CustomFlag:Start()
-- customFlagMatBlue = self.targets.customFlagBlueTeam
-- customFlagMatNeutral = self.targets.customFlagNeutral
-- customFlagMatRed = self.targets.customFlagRedTeam
customFlagMatBlue = GameObject.Find("CustomFlagBlue")
customFlagMatRed = GameObject.Find("CustomFlagRed")
customFlagMatNeutral = GameObject.Find("CustomFlagNeutral")
local testSpawnPoint = ActorManager.RandomSpawnPoint()
if testSpawnPoint.gameObject.Find("Simulated Flag") == nil then
print("<color=red>Enable Cloth Physics to use Custom Flags!</color>")
return
end
if customFlagMatBlue == nil then
print("<color=yellow>CustomFlagMatBlue not found. Make sure your GameObject is named \"CustomFlagBlue\"</color>")
customFlagMatBlue = self.targets.customFlagBlueTeam
else
customFlagMatBlue = customFlagMatBlue.GetComponent(SkinnedMeshRenderer).material
end
if customFlagMatRed == nil then
print("<color=yellow>CustomFlagMatRed not found. Make sure your GameObject is named \"CustomFlagRed\"</color>")
customFlagMatRed = self.targets.customFlagRedTeam
else
customFlagMatRed = customFlagMatRed.GetComponent(SkinnedMeshRenderer).material
end
if customFlagMatNeutral == nil then
print("<color=yellow>CustomFlagMatNeutral not found. Make sure your GameObject is named \"CustomFlagNeutral\"</color>")
customFlagMatNeutral = self.targets.customFlagNeutral
else
customFlagMatNeutral = customFlagMatNeutral.GetComponent(SkinnedMeshRenderer).material
end
self.script.StartCoroutine("SetFlagCurrent")
self.script.StartCoroutine("SetDefaultFlag")
GameEvents.onCapturePointCaptured.AddListener(self, "OnFlagCapture")
GameEvents.onCapturePointNeutralized.AddListener(self,"OnFlagNeutralized")
print("<color=#32c904>Replaced flag texture!</color>")
end
function CustomFlag:SetDefaultFlag()
local sps = ActorManager.spawnPoints
if sps == nil then
print("<color=red>Flags not found</color>")
else
for i= 1, #sps, 1 do
local cp = sps[i].capturePoint.defaultOwner
local SkinnedMeshRFlag = sps[i].gameObject.GetComponentInChildren(SkinnedMeshRenderer)
if cp == Team.Blue then
local tempArray = {} -- Probably don't need this
table.insert(tempArray, customFlagMatBlue) -- Probably don't need this
SkinnedMeshRFlag.materials = tempArray
else if cp == Team.Red then
local tempArray = {}
table.insert(tempArray, customFlagMatRed)
SkinnedMeshRFlag.materials = tempArray
else if cp == Team.Neutral then
local tempArray = {}
table.insert(tempArray, customFlagMatNeutral)
SkinnedMeshRFlag.materials = tempArray
end
end
end
end
end
print("Set flag materials")
end
function CustomFlag:OnFlagCapture(capturePoint, newOwner)
self.script.StartCoroutine(self:SetFlagCaptured(capturePoint, newOwner))
end
function CustomFlag:OnFlagNeutralized(capturePoint, previousOwner)
self.script.StartCoroutine(self:SetFlagNeutralized(capturePoint, previousOwner))
end
function CustomFlag:SetFlagNeutralized(capturePoint, previousOwner)
return function()
local cp = capturePoint.owner
if cp == Team.Blue then
local tempArray = {} -- Probably don't need this
table.insert(tempArray, customFlagMatBlue) -- Probably don't need this
local SkinnedMeshRFlag = capturePoint.gameObject.GetComponentInChildren(SkinnedMeshRenderer)
SkinnedMeshRFlag.materials = tempArray
else if cp == Team.Red then
local tempArray = {}
table.insert(tempArray, customFlagMatRed)
local SkinnedMeshRFlag = capturePoint.gameObject.GetComponentInChildren(SkinnedMeshRenderer)
SkinnedMeshRFlag.materials = tempArray
else if cp == Team.Neutral then
local tempArray = {}
table.insert(tempArray, customFlagMatNeutral)
local SkinnedMeshRFlag = capturePoint.gameObject.GetComponentInChildren(SkinnedMeshRenderer)
SkinnedMeshRFlag.materials = tempArray
end
end
end
end
end
function CustomFlag:SetFlagCaptured(capturePoint,newOwner)
return function()
local cp = capturePoint.owner
local SkinnedMeshRFlag = capturePoint.gameObject.GetComponentInChildren(SkinnedMeshRenderer)
if cp == Team.Blue then
local tempArray = {} -- Probably don't need this
table.insert(tempArray, customFlagMatBlue) -- Probably don't need this
SkinnedMeshRFlag.materials = tempArray
else if cp == Team.Red then
local tempArray = {}
table.insert(tempArray, customFlagMatRed)
SkinnedMeshRFlag.materials = tempArray
else if cp == Team.Neutral then
local tempArray = {}
table.insert(tempArray, customFlagMatNeutral)
SkinnedMeshRFlag.materials = tempArray
end
end
end
print("Captured point " .. capturePoint.name)
end
end
function CustomFlag:SetFlagCurrent()
-- It's 2 because I don't want to impact performance, but also want the flag to be overwritten by the new mat so the user doesn't see the colored flag often
coroutine.yield(WaitForSeconds(2))
local sps = ActorManager.spawnPoints
if sps == nil then
print("<color=red>Flags not found</color>")
else
for i= 1, #sps, 1 do
local cp = sps[i].capturePoint.owner
local SkinnedMeshRFlag = sps[i].gameObject.GetComponentInChildren(SkinnedMeshRenderer)
if cp == Team.Blue then
local tempArray = {}
table.insert(tempArray, customFlagMatBlue)
SkinnedMeshRFlag.materials = tempArray
else if cp == Team.Red then
local tempArray = {}
table.insert(tempArray, customFlagMatRed)
SkinnedMeshRFlag.materials = tempArray
else if cp == Team.Neutral then
local tempArray = {}
table.insert(tempArray, customFlagMatNeutral)
SkinnedMeshRFlag.materials = tempArray
end
end
end
end
end
self.script.StartCoroutine("SetFlagCurrent")
end
function CustomFlag:Update()
end