Skip to content

Instantly share code, notes, and snippets.

View CaptainPRICE's full-sized avatar
💭
🥚

CaptainPRICE

💭
🥚
View GitHub Profile
@CaptainPRICE
CaptainPRICE / createmove-setbuttons-issue.lua
Last active May 11, 2017 00:27
Garry's Mod: CreateMove SetButtons issue...
--- Here is the simple task: Make local player go forward with CreateMove hook (CUserCmd).
--- And here is the problem: It just does NOT work!
-- Running on Development branch, WITHOUT ANY ADDONS (launched with these command-line options: -noaddons -noworkshop). Playing on Sandbox gamemode with gm_flatgrass map.
-- I have tried this in both, singleplayer and multiplayer, but this shit still doesn't want to work.
-- I have verified integrity of game files, also restored default game options, but despite all the work, it still doesn't work!!! What the actual fuck is wrong here, Garry?!
-- In short: I have literally tried it in every single way possible, it just doesn't work. Also, this has been confirmed as "bug" by a few friends of mine.
print( _VERSION, VERSION, BRANCH, GAMEMODE.Name, game.GetMap() ) -- Lua 5.1 170509 dev Sandbox gm_flatgrass
@name Namer-Test-Code
@persist ENTITY:entity [BigString1 BigString2]:string
if (first())
{
ENTITY = entity()
print("Test: entity:setName(string)")
print(setName("Namer-Test-Code") == 0) # Pass [initially, the names are the same so it is expected to fail]
print(setName("Another E2 Name") == 1) # Pass [name is successfully changed]
@CaptainPRICE
CaptainPRICE / color-pack-unpack.lua
Created April 9, 2017 23:46
Garry's Mod: Pack/Unpack a Color/number/string structure to/from "uint32" and string. Works as expected, only 32-bit supported. Output: https://i.imgur.com/U8y7ejv.png
local assert, Color, IsColor, isnumber, isstring, tonumber = assert, Color, IsColor, isnumber, isstring, tonumber
local bit = bit
local bit_band, bit_bor, bit_lshift, bit_rshift = bit.band, bit.bor, bit.lshift, bit.rshift
local string = string
local string_byte, string_char, string_format, string_len = string.byte, string.char, string.format, string.len
local BYTE_MAX, UINT32_MAX = 0xFF, 0xFFFFFFFF -- Max value of unsigned byte. Max value of 32-bit unsigned integer.
--local UINT64_MAX = 0xFFFFFFFFFFFFFFFF -- Max value of 64-bit unsigned integer.
--- Packs a [Color] structure into a 32-bit unsigned integer.
@CaptainPRICE
CaptainPRICE / cactus.mtl
Last active January 8, 2017 18:41
Small collection of Wavefront objects I have generated via Unity 5 ;-)
newmtl M_0077_DarkGreen
Kd 0.509804 0.6666667 0.3490196
illum 2
@CaptainPRICE
CaptainPRICE / holograms-are-fun.txt
Created December 30, 2016 19:26
Holograms Are Fun v1.
### <copyright>Copyright (c) 2016 https://github.com/CaptainPRICE. All rights reserved.</copyright>
### <license>MIT license (see "LICENSE.md" file).</license>
### <dependency>holo</dependency>
### <contributors>github.com/CaptainPRICE (https://steamcommunity.com/profiles/76561198092225548/)</contributors>
@name Hologram Are Fun v1
#ifdef holoCreate(number)
@persist Holograms:array IsDone LastHoloID MaxAmount StartedTime SpawnedCount NAME:string
@trigger none
@model models/led.mdl
@CaptainPRICE
CaptainPRICE / entsByPlayer.txt
Last active November 3, 2016 00:53
Functions to be added to Expression 2.
# A single function to rule everything about entity searching.
# (1) array/entity: Player(s) to search the entities of.
# (2) array/string: Parameter to be used with search.
# (3) number: Type of search to be executed (valid values: _FIND_BY_CLASS, _FIND_BY_MODEL, _FIND_BY_NAME).
# Examples:
entsByPlayer(owner(), "*", _FIND_BY_CLASS) # Gets all entities owned by you.
entsByPlayer(playersAdmins(), "*", _FIND_BY_CLASS) # Gets all entities that are owned by all admins.
entsByPlayer(owner(), array("prop_*", "gmod_wire_expression2"), _FIND_BY_CLASS) # Gets all entities that you own, and whose class name matches any of the strings (specified by 2nd argument).
@CaptainPRICE
CaptainPRICE / switch-case_statement.lua
Last active September 30, 2016 17:08
Simple implementation of "Switch-Case" and "Try-Catch" statements for Lua. For usage, see screenshot: https://i.imgur.com/SFC4wGj.png
local setmetatable = setmetatable
Default, Nil = {}, function() end
switch = function(i)
return setmetatable({ i }, {
__call = function(t, cases)
local item = #t < 1 and Nil or t[1]
return (cases[item] or cases[Default] or Nil)(item)
end
})
@CaptainPRICE
CaptainPRICE / print-tree-structure.lua
Last active September 30, 2016 12:54
Challenge: Code a better version of "printTable(table)" E2 function. Below is a sample in Lua.
local NODES = {
Branch_1 = {
Sibling_1 = {
item_1 = "a string value",
item_2 = 2,
item_3 = "another string value"
},
Sibling_2 = {
grandchild_1 = {
item_1 = 123.456789
@CaptainPRICE
CaptainPRICE / average_vector.txt
Last active September 29, 2016 14:35
E2: average function with support for vectors.
function vector average(Vector1:vector, Vector2:vector)
{
return (Vector1 + Vector2) * 0.5
}
function vector average(Vector1:vector, Vector2:vector, Vector3:vector)
{
return (Vector1 + Vector2 + Vector3) / 3
}
@CaptainPRICE
CaptainPRICE / int32.lua
Last active December 18, 2019 08:49
struct int32 for Lua.
local math = math
local math_floor = math.floor
local error, setmetatable, rawget, tostring, type = error, setmetatable, rawget, tostring, type
int = {}
do
local INT32, INT32_NAME, INT32_SIZE, INT32_DEFAULT, INT32_MAX, INT32_MIN = 3, "int32", 32, 0, 2147483648, -2147483648
local int32 = {
__metatable = false,