Skip to content

Instantly share code, notes, and snippets.

@adamnejm
Last active March 11, 2022 10:11
Show Gist options
  • Save adamnejm/735a92f1a578d42d9024d7b0638f8554 to your computer and use it in GitHub Desktop.
Save adamnejm/735a92f1a578d42d9024d7b0638f8554 to your computer and use it in GitHub Desktop.
Starfall - Basic Continuous Chair Controller Example
--@name Basic continuous chair controller
--@author Name
--@server
-- USAGE:
-- Place chip on the ground, a chair will spawn, sit in it and press W or S
local owner, client, chip, world = owner(), player(), chip(), entity(0)
-- Create a frozen SENT chair 20 units above the chip
local chair = prop.createSent(chip:getPos() + chip:getUp() * 20, Angle(), "Seat_Jeep", true)
-- Create a basic hologram in front of the chair with a scale of 0.75
local holo = holograms.create(chair:getPos() + chair:getForward() * 40, Angle(), "models/props_phx/games/chess/white_rook.mdl", Vector(0.75))
-- A variable that will control velocity of the hologram
local velocity = 0
-- Use the `Tick` hook to create an update function, essentially runs continuously
hook.add("Tick", "Update", function()
-- Grab the player that's currently using the vehicle
local driver = chair:getDriver()
-- The function above will return a null entity if no driver has been found, so we need to check for a valid one
if driver:isValid() then
-- If the player is holding his FORWARD bind (W by default), set the velocity to 50
-- Otherwise if he's holding the BACK bind (S by default), set the velocity to -35
if driver:keyDown(IN_KEY.FORWARD) then
velocity = 50
elseif driver:keyDown(IN_KEY.BACK) then
velocity = -35
end
end
-- Create a new vector with Y axis based on the `velocity` and apply that to the hologram
-- Note that it's using hologram exclusive `setVel` instead of `setVelocity` which will actually set the velocity, not add it (GMod bug)
holo:setVel(Vector(0, velocity, 0))
-- Decrease the velocity, otherwise hologram will never stop
velocity = velocity * 0.9
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment