Skip to content

Commit

Permalink
Fix realm mismatches in Vector:toScreen() and Vehicle:getDriver() (th…
Browse files Browse the repository at this point in the history
…egrb93#1581)

* Vector:toScreen() is client-only

* :getDriver() and :getPassenger() are shared

* Fix trailing whitespace
  • Loading branch information
legokidlogan authored Dec 21, 2023
1 parent 97d9b7f commit cabb368
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
13 changes: 7 additions & 6 deletions lua/starfall/libs_sh/vectors.lua
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,6 @@ function vec_methods:set(v)
self[3] = v[3]
end

--- Translates the vectors position into 2D user screen coordinates.
-- @return table A table {x=screenx,y=screeny,visible=visible}
function vec_methods:toScreen()
return unwrap(self):ToScreen()
end

--- Converts vector to color
-- @return Color New color object
function vec_methods:getColor()
Expand All @@ -501,6 +495,13 @@ if SERVER then
function vec_methods:isInWorld()
return util.IsInWorld(unwrap(self))
end
else
--- Translates the vectors position into 2D user screen coordinates.
-- @client
-- @return table A table {x=screenx,y=screeny,visible=visible}
function vec_methods:toScreen()
return unwrap(self):ToScreen()
end
end

end
32 changes: 15 additions & 17 deletions lua/starfall/libs_sh/vehicles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,21 @@ function vehicle_meta:__tostring()
else return tostring(ent) end
end

if SERVER then
--- Returns the driver of the vehicle
-- @server
-- @return Player Driver of vehicle
function vehicle_methods:getDriver()
return pwrap(getveh(self):GetDriver())
end
--- Returns the driver of the vehicle
-- @return Player Driver of vehicle
function vehicle_methods:getDriver()
return pwrap(getveh(self):GetDriver())
end

--- Returns a passenger of a vehicle
-- @param number n The index of the passenger to get
-- @return Player The passenger or NULL if empty
function vehicle_methods:getPassenger(n)
checkluatype(n, TYPE_NUMBER)
return pwrap(getveh(self):GetPassenger(n))
end

if SERVER then
--- Ejects the driver of the vehicle
-- @server
function vehicle_methods:ejectDriver()
Expand All @@ -58,15 +65,6 @@ if SERVER then
end
end

--- Returns a passenger of a vehicle
-- @server
-- @param number n The index of the passenger to get
-- @return Player The passenger or NULL if empty
function vehicle_methods:getPassenger(n)
checkluatype(n, TYPE_NUMBER)
return pwrap(getveh(self):GetPassenger(n))
end

--- Kills the driver of the vehicle
-- @server
function vehicle_methods:killDriver()
Expand Down Expand Up @@ -102,7 +100,7 @@ if SERVER then
checkpermission(instance, ent, "vehicle.lock")
local n = "SF_CanExitVehicle"..ent:EntIndex()
hook.Add("CanExitVehicle", n, function(v) if v==ent then return false end end)
ent:CallOnRemove(n, function() hook.Remove("CanExitVehicle", n) end)
ent:CallOnRemove(n, function() hook.Remove("CanExitVehicle", n) end)
ent:Fire("Lock")
end

Expand Down

0 comments on commit cabb368

Please sign in to comment.