Skip to content

Instantly share code, notes, and snippets.

@adamnejm
adamnejm / starfall_bodygroup_and_bone_manipulation.lua
Last active March 11, 2022 10:11
Starfall - Bodygroup and Bone Manipulation Example
--@name NPC bodygroup and bone manipulation example
--@author Name
--@shared
-- USAGE:
-- Place the chip on G-Man NPC (npc_gman)
local owner, client, chip, world = owner(), player(), chip(), entity(0)
if SERVER then
@adamnejm
adamnejm / starfall_basic_continous_chair_controller.lua
Last active March 11, 2022 10:11
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
@adamnejm
adamnejm / starfall_basic_event_chair_controller.lua
Last active March 11, 2022 10:11
Starfall - Basic Event Chair Controller Example
--@name Basic event 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
@adamnejm
adamnejm / starfall_find_closest_chair_in_area.lua
Last active March 11, 2022 10:10
Starfall - Find Closest Chair in Area Example
--@name Find Closest Chair in Area Example
--@author Name
--@server
local owner, client, chip, world = owner(), player(), chip(), entity(0)
local origin = chip:getPos() -- Origin of the search
local distance = 200^2 -- Maximum distance of the chair (still 200, but square it so it's faster to compare later on)
-- Find all chairs and disregard those that are not owned by us or are farther than the specified distance
@adamnejm
adamnejm / starfall_link_chair_via_wire.lua
Last active March 11, 2022 10:10
Starfall - Link Chair via Wire Example
@adamnejm
adamnejm / glua_remove_entity_on_floor_contact.lua
Last active March 14, 2022 22:23
GLua - Remove Entity on Floor Contact
if SERVER then
local function spawn_ent(pos)
local ent = ents.Create("prop_physics")
ent:SetModel("models/hunter/blocks/cube05x05x05.mdl")
ent:SetPos(pos)
ent:Spawn()
-- Make use of the `PhysicsCollide` callback to know when entity collides
ent:AddCallback("PhysicsCollide", function(self, data)
@adamnejm
adamnejm / glua_custom_spawnmenu_tab_example.lua
Last active March 17, 2022 01:36
GMod - Custom Spawnmenu Tab Example
if SERVER then return end
local entries = {
{ nice_name = "Pistol", spawn_name = "weapon_pistol" },
{ nice_name = "Pulse-Rifle", spawn_name = "weapon_ar2" },
}
spawnmenu.AddCreationTab("Example", function()
@adamnejm
adamnejm / awesomewm_slider_set_value_direct.lua
Last active April 27, 2022 02:37
AwesomeWM - slider.set_value_direct
-- Solution #1: Add `set_value_direct` only for the specified slider instance
local slider = wibox.widget.slider() -- ...or any other valid way to create the slider object
function slider:set_value_direct(value)
value = math.min(math.max(value, self:get_minimum()), self:get_maximum())
if value ~= self._private.value then
self._private.value = value
self:emit_signal("property::value", value, true) -- Pass an additional `true` value to the callback
self:emit_signal("widget::redraw_needed")
end
end
@adamnejm
adamnejm / starfall_pod_controller.lua
Created June 13, 2022 19:54
[Starfall] Pod Controller Library
--@name Generic
--@author Name
local track_seats = {}
local track_drivers = {}
local empty_func = function(...) end
-------------------------------------------
local Pod = class("Pod")
@adamnejm
adamnejm / focus_different_client.lua
Created July 9, 2022 11:34
AwesomeWM - Blocking mouse scroll bind
-- Focus different client
-- The input is passed to the client before switching focus *(just like in `unfocus_client.lua)*
client.connect_signal("request::default_mousebindings", function()
awful.mouse.append_client_mousebindings {
awful.button({ "Mod4" }, 4, function(c)
for _, other in ipairs(client.get()) do
if other ~= c then
client.focus = other
break
end