Skip to content

Commit

Permalink
Merge branch 'master' into fix-map-LOD-table
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-A-Rocha authored Nov 13, 2024
2 parents 2d9a5c1 + eb94ca3 commit 04869a2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 32 deletions.
24 changes: 22 additions & 2 deletions [gameplay]/freeroam/fr_client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2123,7 +2123,9 @@ function onExitVehicle(vehicle,seat)
hideControls(wndMain, 'repair', 'flip', 'upgrades', 'color', 'paintjob', 'lightson', 'lightsoff')
closeWindow(wndUpgrades)
closeWindow(wndColor)
elseif vehicle and seat == 0 then
end

if vehicle and seat == 0 then
if source and g_PlayerData[source] then
setVehicleGhost(vehicle,hasDriverGhost(vehicle))
end
Expand Down Expand Up @@ -2243,11 +2245,21 @@ addEventHandler('onClientResourceStart', resourceRoot,
createWindow(wndMain)
hideAllWindows()
bindKey('f1', 'down', toggleFRWindow)
bindKey('f2', 'down', toggleMap)
guiCheckBoxSetSelected(getControl(wndMain, 'jetpack'), isPedWearingJetpack(localPlayer))
guiCheckBoxSetSelected(getControl(wndMain, 'falloff'), canPedBeKnockedOffBike(localPlayer))
end
)

addEventHandler('onClientResourceStart', root,
function(startedResource)
local editorResource, raceResource = getResourceFromName('editor'), getResourceFromName('race')
if (editorResource and raceResource and startedResource == raceResource) then
unbindKey('f2', 'down', toggleMap)
end
end
)

function showWelcomeMap()
createWindow(wndSpawnMap)
showCursor(true)
Expand All @@ -2267,7 +2279,6 @@ function toggleMap()
showCursor(true)
end
end
bindKey("f2", "down", toggleMap)

function toggleFRWindow()
if isWindowOpen(wndMain) then
Expand Down Expand Up @@ -2355,6 +2366,15 @@ addEventHandler('onClientResourceStop', resourceRoot,
end
)

addEventHandler('onClientResourceStop', root,
function(stoppingResource)
local editorResource, raceResource = getResourceFromName('editor'), getResourceFromName('race')
if (editorResource and raceResource and stoppingResource == raceResource) then
bindKey('f2', 'down', toggleMap)
end
end
)

function setVehicleGhost(sourceVehicle,value)

local vehicles = getElementsByType("vehicle")
Expand Down
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 04869a2

Please sign in to comment.