-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpickups_c.lua
More file actions
310 lines (263 loc) · 7.64 KB
/
pickups_c.lua
File metadata and controls
310 lines (263 loc) · 7.64 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
local currentPickup = nil
local pickupCountdown = 0
local screenWidth,screenHeight = guiGetScreenSize()
addEventHandler("onClientResourceStart", resourceRoot,
function()
outputDebugString("Race powerups by Rhytz loaded")
end
)
function pickupInvincibility()
local theVehicle = getPedOccupiedVehicle (localPlayer)
if theVehicle then
local weightSound = playSound("assets/sounds/invinc.mp3")
setVehicleDamageProof(theVehicle, true)
triggerServerEvent("invincibilityAlpha", resourceRoot, theVehicle)
end
end
function stopInvincibility()
local theVehicle = getPedOccupiedVehicle (localPlayer)
if theVehicle then
setVehicleDamageProof(theVehicle, false)
triggerServerEvent("invincibilityAlphaOff", resourceRoot, theVehicle)
local offSound = playSound("assets/sounds/off.mp3")
end
end
function pickupMaxWeight()
local theVehicle = getPedOccupiedVehicle (localPlayer)
if theVehicle then
local weightSound = playSound("assets/sounds/weight.mp3")
triggerServerEvent("maxWeight", resourceRoot, theVehicle)
end
end
function stopMaxWeight()
local offSound = playSound("assets/sounds/off.mp3")
end
function pickupBoost()
local theVehicle = getPedOccupiedVehicle (localPlayer)
if theVehicle then
triggerServerEvent("boostPickup", resourceRoot, theVehicle)
local boostsound = playSound("assets/sounds/boost.mp3")
speed = 1.4
_,_, rotz = getElementRotation(theVehicle)
rotz = math.rad(rotz)
vel_x = speed * math.sin(rotz) * -1
vel_y = speed * math.cos(rotz)
setElementVelocity(theVehicle, vel_x, vel_y, 0)
end
end
function pickupBarrels()
local theVehicle = getPedOccupiedVehicle(localPlayer)
if theVehicle then
triggerServerEvent("createBarrel", resourceRoot, theVehicle)
local barrelSound = playSound("assets/sounds/barreldrop.mp3")
end
end
function pickupRamps()
local theVehicle = getPedOccupiedVehicle(localPlayer)
if theVehicle then
triggerServerEvent("createRamp", resourceRoot, theVehicle)
local rampSound = playSound("assets/sounds/thud.mp3")
end
end
function pickupRockets()
local theVehicle = getPedOccupiedVehicle(localPlayer)
local x,y,z = getElementPosition(theVehicle)
local rX,rY,rZ = getVehicleRotation(theVehicle)
local x = x+4*math.cos(math.rad(rZ+90))
local y = y+4*math.sin(math.rad(rZ+90))
createProjectile(theVehicle, 19, x, y, z, 1.0, nil)
end
function pickupMines()
local theVehicle = getPedOccupiedVehicle(localPlayer)
if theVehicle then
triggerServerEvent("createMine", resourceRoot, theVehicle)
local mineSound = playSound("assets/sounds/mine.mp3")
end
end
local randomPickups = {
{
name = "Invincibility",
amount = 1, --How many times the pickup can be activated
description = "for 10 seconds of invincibility",
seconds = 10,
callback = pickupInvincibility,
endfunc = stopInvincibility,
icon = "invincibility.png"
},
{
name = "Max weight",
amount = 1,
description = "to get maximum car weight for 10 seconds",
seconds = 10,
callback = pickupMaxWeight,
endfunc = stopMaxWeight,
icon = "maxweight.png"
},
{
name = "Boost",
amount = 1,
description = "for a quick boost with max weight",
seconds = nil,
callback = pickupBoost,
icon = "boost.png"
},
{
name = "Barrels",
amount = 3,
description = "to drop barrels",
seconds = nil,
callback = pickupBarrels,
icon = "barrels.png"
},
{
name = "Ramps",
amount = 3,
description = "to spawn ramps",
seconds = nil,
callback = pickupRamps,
icon = "ramps.png"
},
{
name = "Rockets",
amount = 3,
description = "to shoot rockets",
seconds = nil,
callback = pickupRockets,
icon = "rockets.png"
},
{
name = "Mines",
amount = 3,
description = "to drop mines",
seconds = nil,
callback = pickupMines,
icon = "mines.png"
}
}
--[[
may be buggy
,
{
name = "Ghostmode",
amount = 1,
description = "for 20 seconds of ghostmode",
seconds = 20,
callback = pickupGhostmode,
endfunc = stopGhostmode,
icon = "ghostmode.png"
}
]]--
function updatePickupStatus()
if(pickupCountdown <= 0) then
unbindKey("lshift", "down", activatePickup)
unbindKey("rshift", "down", activatePickup)
unbindKey("z", "down", discardPickup)
triggerServerEvent("noLongerHasPickup", resourceRoot, localPlayer)
currentPickup = nil
end
end
function activatePickup(key, keyState)
currentPickup.callback();
if currentPickup.seconds then
unbindKey("lshift", "down", activatePickup)
unbindKey("rshift", "down", activatePickup)
unbindKey("z", "down", discardPickup)
setTimer(
function()
pickupCountdown = pickupCountdown - 1
if(pickupCountdown <= 0) then
currentPickup.endfunc()
updatePickupStatus()
end
end,
1000,
currentPickup.seconds
)
else
pickupCountdown = pickupCountdown - 1
end
updatePickupStatus()
end
function discardPickup(key, keyState)
pickupCountdown = 0
updatePickupStatus()
end
local shufflingPickup = nil
local lastTick = 0
function showPickupData()
if shufflingPickup then
if(getTickCount() - lastTick > 50) then
randomIcon = randomPickups[math.random(#randomPickups)].icon
lastTick = getTickCount()
end
dxDrawImage(screenWidth-155, screenHeight-185, 150, 150, "assets/images/" .. randomIcon)
end
if currentPickup then
dxDrawImage(screenWidth-155, screenHeight-190, 150, 150, "assets/images/" .. currentPickup.icon)
dxDrawRectangle(screenWidth-210, screenHeight-170, 55, 120, tocolor(245,149,28))
dxDrawImage(screenWidth-205, screenHeight-165, 45, 32, "assets/images/keyboard_key_shift.png")
dxDrawImage(screenWidth-199, screenHeight-87, 32, 32, "assets/images/keyboard_key_z.png")
dxDrawText(pickupCountdown, screenWidth-210, screenHeight-130, screenWidth-155, nil, nil, 1.3, "pricedown", "center")
end
end
addEventHandler("onClientRender", root, showPickupData)
addEvent("pickedUpPowerup", true)
addEventHandler("pickedUpPowerup", localPlayer,
function()
if(not currentPickup and getElementData(localPlayer,"state") == "alive") then
local shufflesound = playSound("assets/sounds/shuffle.mp3")
local x,y,z = getElementPosition(source)
createExplosion(x, y, z, 5, nil, nil, false)
shufflingPickup = true
setTimer(
function()
shufflingPickup = nil
if not isPedDead(localPlayer) then
currentPickup = randomPickups[math.random(#randomPickups)]
if(currentPickup.seconds) then
pickupCountdown = currentPickup.seconds
else
pickupCountdown = currentPickup.amount
end
outputChatBox("You picked up #FFFFFF" .. currentPickup.name .. "#696969. Press #00FF00Shift#696969 ".. currentPickup.description .. ". #FF0000Z#696969 to discard", 105, 105, 105, true);
bindKey("lshift", "down", activatePickup)
bindKey("rshift", "down", activatePickup)
bindKey("z", "down", discardPickup)
end
end,
1850,
1
)
end
end
)
addEvent("createBoostExplosion", true)
addEventHandler("createBoostExplosion", resourceRoot,
function(theVehicle)
if theVehicle then
local x,y,z = getElementPosition(theVehicle)
createExplosion(x,y,z, 5, nil, nil, false)
end
end
)
addEventHandler("onClientPlayerWasted", localPlayer,
function()
if(source == localPlayer) then
currentPickup = nil
end
end
)
local triggeredObject = {}
addEventHandler("onClientVehicleCollision", root,
function(object, force, bodyPart, x, y, z, nx, ny, nz, force, model)
local theVehicle = getPedOccupiedVehicle(localPlayer)
if(object and source == theVehicle and not triggeredObject[object]) then
if(model == 1218) then
triggerServerEvent("barrelHit", resourceRoot, object)
elseif(model == 2918) then
setElementVelocity(source, math.random() + math.random(-1, 0), math.random() + math.random(-1, 0), math.random())
end
triggeredObject[object] = true
end
end
)