Skip to content

Commit

Permalink
superman: Initial fixes (#572)
Browse files Browse the repository at this point in the history
* Initial fixes for superman

* Update meta.xml

* Fix lint warnings.
  • Loading branch information
ds1-e authored Nov 5, 2024
1 parent fdded32 commit 2b3bc10
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 30 deletions.
36 changes: 18 additions & 18 deletions [gameplay]/superman/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,17 @@ end

function Superman.onJoin(player)
local self = Superman
local player = player or source
local playerElement = player or source

setPlayerFlying(player, false)
setPlayerFlying(playerElement, false)
end

function Superman.onQuit(reason, player)
local self = Superman
local player = player or source
local playerElement = player or source

if isPlayerFlying(player) then
self:restorePlayer(player)
if isPlayerFlying(playerElement) then
self:restorePlayer(playerElement)
end
end

Expand Down Expand Up @@ -271,7 +271,7 @@ function Superman.startFlight()
return
end

triggerServerEvent("superman:start", root)
triggerServerEvent("superman:start", localPlayer)
setPlayerFlying(localPlayer, true)
setElementVelocity(localPlayer, 0, 0, 0)
self.currentSpeed = 0
Expand All @@ -285,7 +285,7 @@ function Superman.processControls()
local self = Superman

if not isPlayerFlying(localPlayer) then
jump, oldJump = getPedControlState("jump"), jump
jump, oldJump = getPedControlState(localPlayer, "jump"), jump
if not oldJump and jump then
Superman.onJump()
end
Expand All @@ -295,15 +295,15 @@ function Superman.processControls()
-- Calculate the requested movement direction
local Direction = Vector3D:new(0, 0, 0)

if getPedControlState("forwards") then
if getPedControlState(localPlayer, "forwards") then
Direction.y = 1
elseif getPedControlState("backwards") then
elseif getPedControlState(localPlayer, "backwards") then
Direction.y = -1
end

if getPedControlState("left") then
if getPedControlState(localPlayer, "left") then
Direction.x = 1
elseif getPedControlState("right") then
elseif getPedControlState(localPlayer, "right") then
Direction.x = -1
end

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

if getPedControlState("look_behind") then
if getPedControlState(localPlayer, "look_behind") then
SightDirection = SightDirection:Mul(-1)
end

-- Calculate the current max speed and acceleration values
local maxSpeed = MAX_SPEED
local acceleration = ACCELERATION

if getPedControlState("sprint") then
if getPedControlState(localPlayer, "sprint") then
maxSpeed = MAX_SPEED * EXTRA_SPEED_FACTOR
acceleration = acceleration * EXTRA_ACCELERATION_FACTOR
elseif getPedControlState("walk") then
elseif getPedControlState(localPlayer, "walk") then
maxSpeed = MAX_SPEED * LOW_SPEED_FACTOR
acceleration = acceleration * LOW_ACCELERATION_FACTOR
end
Expand Down Expand Up @@ -449,7 +449,7 @@ function Superman.processFlight()
self:restorePlayer(player)
if player == localPlayer then
setGravity(serverGravity)
triggerServerEvent("superman:stop", root)
triggerServerEvent("superman:stop", localPlayer)
end
elseif distanceToGround and distanceToGround < LANDING_DISTANCE then
self:processLanding(player, Velocity, distanceToGround)
Expand All @@ -476,7 +476,7 @@ function Superman:processIdleFlight(player)
local Sight = Vector3D:new(lookX - cameraX, lookY - cameraY, lookZ - cameraZ)
Sight:Normalize()

if getPedControlState("look_behind") then
if getPedControlState(localPlayer, "look_behind") then
Sight = Sight:Mul(-1)
end

Expand Down Expand Up @@ -622,8 +622,8 @@ end
-- Vectors
--
Vector3D = {
new = function(self, _x, _y, _z)
local newVector = {x = _x or 0.0, y = _y or 0.0, z = _z or 0.0}
new = function(self, posX, posY, posZ)
local newVector = {x = posX or 0.0, y = posY or 0.0, z = posZ or 0.0}
return setmetatable(newVector, {__index = Vector3D})
end,

Expand Down
7 changes: 4 additions & 3 deletions [gameplay]/superman/meta.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<meta>
<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" />
<script src="server.lua" type="server" />
<script src="client.lua" type="client" />
<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"/>

<script src="client.lua" type="client" cache="false"/>
<script src="server.lua" type="server"/>
</meta>
14 changes: 5 additions & 9 deletions [gameplay]/superman/server.lua
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
local Superman = {}

-- Static global values
local thisResource = getThisResource()

-- Resource events
addEvent("superman:start", true)
addEvent("superman:stop", true)

--
-- Start/stop functions
--
function Superman.Start()
local self = Superman

addEvent("superman:start", true)
addEvent("superman:stop", true)

addEventHandler("superman:start", root, self.clientStart)
addEventHandler("superman:stop", root, self.clientStop)
addEventHandler("onPlayerJoin", root, Superman.setStateOff) --
addEventHandler("onPlayerJoin", root, Superman.setStateOff)
addEventHandler("onPlayerVehicleEnter", root, self.enterVehicle)
end
addEventHandler("onResourceStart", getResourceRootElement(thisResource), Superman.Start, false)
addEventHandler("onResourceStart", resourceRoot, Superman.Start, false)

function Superman.clientStart()
setElementData(client, "superman:flying", true)
Expand Down

0 comments on commit 2b3bc10

Please sign in to comment.