Skip to content

Commit 2b3bc10

Browse files
authored
superman: Initial fixes (#572)
* Initial fixes for superman * Update meta.xml * Fix lint warnings.
1 parent fdded32 commit 2b3bc10

File tree

3 files changed

+27
-30
lines changed

3 files changed

+27
-30
lines changed

[gameplay]/superman/client.lua

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,17 @@ end
170170

171171
function Superman.onJoin(player)
172172
local self = Superman
173-
local player = player or source
173+
local playerElement = player or source
174174

175-
setPlayerFlying(player, false)
175+
setPlayerFlying(playerElement, false)
176176
end
177177

178178
function Superman.onQuit(reason, player)
179179
local self = Superman
180-
local player = player or source
180+
local playerElement = player or source
181181

182-
if isPlayerFlying(player) then
183-
self:restorePlayer(player)
182+
if isPlayerFlying(playerElement) then
183+
self:restorePlayer(playerElement)
184184
end
185185
end
186186

@@ -271,7 +271,7 @@ function Superman.startFlight()
271271
return
272272
end
273273

274-
triggerServerEvent("superman:start", root)
274+
triggerServerEvent("superman:start", localPlayer)
275275
setPlayerFlying(localPlayer, true)
276276
setElementVelocity(localPlayer, 0, 0, 0)
277277
self.currentSpeed = 0
@@ -285,7 +285,7 @@ function Superman.processControls()
285285
local self = Superman
286286

287287
if not isPlayerFlying(localPlayer) then
288-
jump, oldJump = getPedControlState("jump"), jump
288+
jump, oldJump = getPedControlState(localPlayer, "jump"), jump
289289
if not oldJump and jump then
290290
Superman.onJump()
291291
end
@@ -295,15 +295,15 @@ function Superman.processControls()
295295
-- Calculate the requested movement direction
296296
local Direction = Vector3D:new(0, 0, 0)
297297

298-
if getPedControlState("forwards") then
298+
if getPedControlState(localPlayer, "forwards") then
299299
Direction.y = 1
300-
elseif getPedControlState("backwards") then
300+
elseif getPedControlState(localPlayer, "backwards") then
301301
Direction.y = -1
302302
end
303303

304-
if getPedControlState("left") then
304+
if getPedControlState(localPlayer, "left") then
305305
Direction.x = 1
306-
elseif getPedControlState("right") then
306+
elseif getPedControlState(localPlayer, "right") then
307307
Direction.x = -1
308308
end
309309

@@ -314,18 +314,18 @@ function Superman.processControls()
314314
local SightDirection = Vector3D:new((lookX - cameraX), (lookY - cameraY), (lookZ - cameraZ))
315315
SightDirection:Normalize()
316316

317-
if getPedControlState("look_behind") then
317+
if getPedControlState(localPlayer, "look_behind") then
318318
SightDirection = SightDirection:Mul(-1)
319319
end
320320

321321
-- Calculate the current max speed and acceleration values
322322
local maxSpeed = MAX_SPEED
323323
local acceleration = ACCELERATION
324324

325-
if getPedControlState("sprint") then
325+
if getPedControlState(localPlayer, "sprint") then
326326
maxSpeed = MAX_SPEED * EXTRA_SPEED_FACTOR
327327
acceleration = acceleration * EXTRA_ACCELERATION_FACTOR
328-
elseif getPedControlState("walk") then
328+
elseif getPedControlState(localPlayer, "walk") then
329329
maxSpeed = MAX_SPEED * LOW_SPEED_FACTOR
330330
acceleration = acceleration * LOW_ACCELERATION_FACTOR
331331
end
@@ -449,7 +449,7 @@ function Superman.processFlight()
449449
self:restorePlayer(player)
450450
if player == localPlayer then
451451
setGravity(serverGravity)
452-
triggerServerEvent("superman:stop", root)
452+
triggerServerEvent("superman:stop", localPlayer)
453453
end
454454
elseif distanceToGround and distanceToGround < LANDING_DISTANCE then
455455
self:processLanding(player, Velocity, distanceToGround)
@@ -476,7 +476,7 @@ function Superman:processIdleFlight(player)
476476
local Sight = Vector3D:new(lookX - cameraX, lookY - cameraY, lookZ - cameraZ)
477477
Sight:Normalize()
478478

479-
if getPedControlState("look_behind") then
479+
if getPedControlState(localPlayer, "look_behind") then
480480
Sight = Sight:Mul(-1)
481481
end
482482

@@ -622,8 +622,8 @@ end
622622
-- Vectors
623623
--
624624
Vector3D = {
625-
new = function(self, _x, _y, _z)
626-
local newVector = {x = _x or 0.0, y = _y or 0.0, z = _z or 0.0}
625+
new = function(self, posX, posY, posZ)
626+
local newVector = {x = posX or 0.0, y = posY or 0.0, z = posZ or 0.0}
627627
return setmetatable(newVector, {__index = Vector3D})
628628
end,
629629

[gameplay]/superman/meta.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<meta>
2-
<info author="MTA contributors (github.com/multitheftauto/mtasa-resources)" version="3.0" name="Superman" description="Allows players to fly around the map by pressing the jump button twice" type="script" />
3-
<script src="server.lua" type="server" />
4-
<script src="client.lua" type="client" />
2+
<info author="MTA contributors (github.com/multitheftauto/mtasa-resources)" version="3.0" name="Superman" description="Allows players to fly around the map by pressing the jump button twice" type="script"/>
3+
4+
<script src="client.lua" type="client" cache="false"/>
5+
<script src="server.lua" type="server"/>
56
</meta>

[gameplay]/superman/server.lua

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
local Superman = {}
22

3-
-- Static global values
4-
local thisResource = getThisResource()
5-
6-
-- Resource events
7-
addEvent("superman:start", true)
8-
addEvent("superman:stop", true)
9-
103
--
114
-- Start/stop functions
125
--
136
function Superman.Start()
147
local self = Superman
158

9+
addEvent("superman:start", true)
10+
addEvent("superman:stop", true)
11+
1612
addEventHandler("superman:start", root, self.clientStart)
1713
addEventHandler("superman:stop", root, self.clientStop)
18-
addEventHandler("onPlayerJoin", root, Superman.setStateOff) --
14+
addEventHandler("onPlayerJoin", root, Superman.setStateOff)
1915
addEventHandler("onPlayerVehicleEnter", root, self.enterVehicle)
2016
end
21-
addEventHandler("onResourceStart", getResourceRootElement(thisResource), Superman.Start, false)
17+
addEventHandler("onResourceStart", resourceRoot, Superman.Start, false)
2218

2319
function Superman.clientStart()
2420
setElementData(client, "superman:flying", true)

0 commit comments

Comments
 (0)