Skip to content

Instantly share code, notes, and snippets.

@x4fx77x4f
x4fx77x4f / digidumper.lua
Last active October 6, 2020 20:56
clientside Lua script to save Wired Digital Screens to PGM/PPM files
local mem = LocalPlayer():GetEyeTrace().Entity
if mem then
mem = mem.Memory1
end
if not mem then
print("either there is no entity or the entity has no memory")
return
end
local width = mem[1048573] or 0
local height = mem[1048572] or 0
@x4fx77x4f
x4fx77x4f / stringmethodtest.lua
Created October 2, 2020 19:28
Script for checking if string methods behave the same as regular Lua
--@shared
local setfenv = setfenv or debug.setfenv
assert(setfenv, "incompatible version of lua")
local prefix = BRANCH and (SERVER and "GLUA SERVER" or CLIENT and "GLUA CLIENT") or (SERVER and "SF SERVER" or CLIENT and "SF CLIENT") or "LUA"
prefix = prefix..": "
local i = 0
local j = 0
local k = 7
local function test(cond, msg)
j = j+1
@x4fx77x4f
x4fx77x4f / quakelmp.lua
Last active October 22, 2020 02:03
Render .lmp texture files from Quake 1 in StarfallEx
--@name Quake LMP renderer
--@client
local p = file.read("quakefall/gfx/palette.lmp")
local d = file.read("quakefall/gfx/mainmenu.lmp")
d = bit.stringstream(d)
local threshold = quotaMax()*0.7
local function yield(rt)
if math.max(quotaUsed(), quotaAverage()) >= threshold then
coroutine.yield()
if rt then
@x4fx77x4f
x4fx77x4f / consoledemo.lua
Created October 4, 2020 01:16
A simple demo using a Wired Console Screen in StarfallEx
--@server
wire.adjustInputs({"Console"}, {"Wirelink"})
local con = wire.ports.Console
con[2041] = 0
local function writeString(str, i)
for j=1, #str do
local k = (i+j-1)*2
con[k] = str:sub(j, j):byte()
con[k+1] = 0000999
end
@x4fx77x4f
x4fx77x4f / permdemo.lua
Created October 9, 2020 01:59
My preferred way of dealing with permissions in StarfallEx.
--@client
local function init()
-- Your code here (placeholder code follows)
hook.add("render", "render", function()
local w, h = render.getResolution()
render.setFont("DermaLarge")
render.drawSimpleText(w/2, h/2, "Success!", 1, 1)
end)
-- Your code here (placeholder code precedes)
end
@x4fx77x4f
x4fx77x4f / 360ify.lua
Created October 18, 2020 04:03
A crude attempt to make Source Engine games look like they're running on the Xbox 360 when they're not
#!/usr/bin/env luajit
local files = {
"ChatScheme.res",
"ClientScheme.res",
"GameMenu.res",
"LoadingDialogNoBanner.res",
"LoadingDialogNoBannerSingle.res",
"LoadingDialogVAC.res",
"mdlpicker.res",
"mdlpickerrender.res",
@x4fx77x4f
x4fx77x4f / minesweeper.lua
Created October 20, 2020 07:49
Minesweeper in StarfallEx. State is not kept in sync across clients.
--@name Minesweeper
--@author x4fx77x4f
--@client
local hook_add = hook.add
local hook_remove = hook.remove
local IN_KEY_USE = IN_KEY.USE
local IN_KEY_ATTACK = IN_KEY.ATTACK
local IN_KEY_ATTACK2 = IN_KEY.ATTACK2
local material_create = material.create
local math_floor = math.floor
@x4fx77x4f
x4fx77x4f / gwars.lua
Last active October 20, 2020 23:20
Realtime mesh demo in StarfallEx
--@client
--@include libs/fh_lube.lua
require("libs/fh_lube.lua")(function()
local math_cos = math.cos
local math_sin = math.sin
local mesh_advanceVertex = mesh.advanceVertex
local mesh_generate = mesh.generate
local mesh_writeColor = mesh.writeColor
local mesh_writePosition = mesh.writePosition
local mesh_writeUV = mesh.writeUV
@x4fx77x4f
x4fx77x4f / cfgpp.lua
Last active November 20, 2020 19:08
Preprocessor and minifier for Quake/Source Engine .cfg files
#!/usr/bin/env luajit
local input = arg[1] and io.open(arg[1], 'r') or io.stdin
local output = arg[2] and io.open(arg[2], 'w+') or io.stdout
local inbrace = false
local firstbrace = false
for line in input:lines() do
if line:find('^[ \t]*//') or line == '' then
-- skip
elseif inbrace then
local o = line:find('}')
@x4fx77x4f
x4fx77x4f / invaders.cfg
Last active October 27, 2023 10:32
Space Invaders as a Source .cfg
// CFGINVADERS
// HOW TO PLAY:
// Preprocess this file with cfgpp.lua (in another gist, or use the already prepreprocessed one below)
// Run 'map cs_assault' (or any other map)
// Run 'exec invaders2' (or wherever you put the processed file)
// Unpause the game and look in the top-left corner
// Numpad 4 and 6 to move, numpad 8 to shoot
// aliens state
alias a_1_1 a_t