Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ __pycache__
/test_release/
__test*
*.bak
check_lua_versions.sh
16 changes: 10 additions & 6 deletions scripts/vscripts/alyxlib/class.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--[[
v2.3.0
v2.3.1
https://github.com/FrostSource/alyxlib

If not using `vscripts/alyxlib/core.lua`, load this file at game start using the following line:
Expand Down Expand Up @@ -74,7 +74,7 @@
end
```
]]
local version = "v2.3.0"
local version = "v2.3.1"

require "alyxlib.storage"
require "alyxlib.globals"
Expand Down Expand Up @@ -469,15 +469,19 @@ end
---Resume the entity think function.
---@luadoc-ignore
function EntityClass:ResumeThink()
self:SetContextThink("__EntityThink", function() return self:Think() end, 0)
self.IsThinking = true
if not self:IsNull() then
self:SetContextThink("__EntityThink", function() return self:Think() end, 0)
self.IsThinking = true
end
end

---Pause the entity think function.
---@luadoc-ignore
function EntityClass:PauseThink()
self:SetContextThink("__EntityThink", nil, 0)
self.IsThinking = false
if not self:IsNull() then
self:SetContextThink("__EntityThink", nil, 0)
self.IsThinking = false
end
end

---Define a function to redirected to `output` on spawn.
Expand Down
9 changes: 7 additions & 2 deletions scripts/vscripts/alyxlib/controls/haptics.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--[[
v1.0.1
v1.0.2
https://github.com/FrostSource/alyxlib

Haptic sequences allow for more complex vibrations than the one-shot pulses that the base API provides.
Expand Down Expand Up @@ -28,7 +28,7 @@ local HapticSequenceClass = {
pulseWidth_us = 0,
}
HapticSequenceClass.__index = HapticSequenceClass
HapticSequenceClass.version = "v1.0.1"
HapticSequenceClass.version = "v1.0.2"

---
---Start the haptic sequence on a given hand.
Expand All @@ -39,6 +39,11 @@ function HapticSequenceClass:Fire(hand)
hand = Entities:GetLocalPlayer():GetHMDAvatar():GetVRHand(hand)
end

if not IsValidEntity(hand) then
warn("Invalid hand entity for haptic sequence!")
return
end

local ref = {
increment = 0,
prevTime = Time(),
Expand Down
8 changes: 4 additions & 4 deletions scripts/vscripts/alyxlib/controls/input.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--[[
v4.0.1
v4.0.2
https://github.com/FrostSource/alyxlib

Simplifies the tracking of digital action presses/releases and analog values.
Expand All @@ -15,7 +15,7 @@
---@class Input
Input = {}
Input.__index = Input
Input.version = "v4.0.1"
Input.version = "v4.0.2"

---
---If the input system should start automatically on player spawn.
Expand Down Expand Up @@ -305,8 +305,8 @@ function Input:ListenToButton(kind, hand, button, presses, callback, context)
kind = kind,

multiple_press_count = 0,
press_time = -1,
release_time = 0,
press_time = vlua.select(kind == "press", 0, -1),
release_time = vlua.select(kind == "release", 0, -1),
prev_press_time = 0,
}

Expand Down
14 changes: 7 additions & 7 deletions scripts/vscripts/alyxlib/debug/commands.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
--[[
v1.1.0
v1.1.1
https://github.com/FrostSource/alyxlib

If not using `vscripts/alyxlib/init.lua`, load this file at game start using the following line:

require "alyxlib.debug.commands"
]]

local version = "v1.1.0"
local version = "v1.1.1"

local alyxlibCommands = {}

Expand Down Expand Up @@ -455,11 +455,11 @@ RegisterAlyxLibCommand("ent_find_by_address", function (_, tblpart, colon, hash)
local foundEnt = Debug.FindEntityByHandleString(tblpart, colon, hash)

if foundEnt then
Msg("Info for " .. tostring(foundEnt).."\n")
Msg("\tClassname" .. foundEnt:GetClassname().."\n")
Msg("\tName" .. foundEnt:GetName().."\n")
Msg("\tParent" .. foundEnt:GetMoveParent().."\n")
Msg("\tModel" .. foundEnt:GetModelName())
Msg("Info for " .. tostring(foundEnt) .."\n")
Msg("\tClassname: " .. foundEnt:GetClassname() .."\n")
Msg("\tName: " .. foundEnt:GetName().."\n")
Msg("\tParent: " .. (tostring(foundEnt:GetMoveParent() or "[none]")) .."\n")
Msg("\tModel: " .. foundEnt:GetModelName())
else
Msg("Could not find any entity matching '" .. hash .. "'")
end
Expand Down
24 changes: 22 additions & 2 deletions scripts/vscripts/alyxlib/debug/common.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--[[
v2.1.0
v2.2.0
https://github.com/FrostSource/alyxlib

Debug utility functions.
Expand All @@ -13,7 +13,7 @@ require "alyxlib.extensions.entity"
require "alyxlib.math.common"

Debug = {}
Debug.version = "v2.1.0"
Debug.version = "v2.2.0"

---
---Finds the first entity whose name, class or model matches `pattern`.
Expand Down Expand Up @@ -792,9 +792,20 @@ end
---@param ent EntityHandle
---@return string
function Debug.EntStr(ent)
if ent == nil then
return "[nil, nil]"
end

if ent:IsNull() then
return "[invalid, invalid]"
end

return "[" .. ent:GetClassname() .. ", " .. ent:GetName() .. "]"
end

---@diagnostic disable-next-line: lowercase-global
entstr = Debug.EntStr

---
---Dumps a list of convars and their values to the console.
---
Expand Down Expand Up @@ -891,4 +902,13 @@ function Debug.ToOrdinalString(n)
return n .. (suffixes[lastDigit] or "th")
end

---
---Get the script name and line number of a function or traceback level.
---
---@param f integer|function # Level or function
---@return string
function Debug.GetSourceLine(f)
return debug.getinfo(f, "S").short_src..":"..tostring(debug.getinfo(f, "l").currentline)
end

return Debug.version
5 changes: 3 additions & 2 deletions scripts/vscripts/alyxlib/debug/controller.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--[[
v1.0.1
v1.0.2
https://github.com/FrostSource/alyxlib

Allows quick debugging of VR controllers.
Expand All @@ -11,7 +11,7 @@
-- Used for button descriptions
require "alyxlib.controls.input"

local version = "v1.0.1"
local version = "v1.0.2"


Convars:RegisterCommand("alyxlib_start_print_controller_button_presses", function (_)
Expand Down Expand Up @@ -46,6 +46,7 @@ Convars:RegisterCommand("alyxlib_start_print_controller_button_presses", functio
if buttonsPressed[h][i] ~= nil then
buttonsPressed[h][i] = nil
Msg(desc .. " controller: [".. i .."] " .. Input:GetButtonDescription(i) .. " Released\n")
msgPrinted = true
end
end
end
Expand Down
59 changes: 57 additions & 2 deletions scripts/vscripts/alyxlib/extensions/entity.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--[[
v2.6.1
v2.7.0
https://github.com/FrostSource/alyxlib

Provides base entity extension methods.
Expand All @@ -9,7 +9,7 @@
require "alyxlib.extensions.entity"
]]

local version = "v2.6.1"
local version = "v2.7.0"

---
---Get the entities parented to this entity. Including children of children.
Expand Down Expand Up @@ -45,6 +45,52 @@ function CBaseEntity:GetTopChildren()
return children
end

---
---Get the first child in the hierarchy that has targetname or classname.
---
---@param name string # The name or classname to look for, supports wildcard '*'
---@return EntityHandle?
function CBaseEntity:GetChild(name)
local usePattern = name:find("%*") ~= nil
local pattern

---@TODO Consider moving wildcard logic to a utility function
if usePattern then
-- Escape pattern special characters, then replace '*' with '.*'
pattern = "^" .. name
:gsub("([%^%$%(%)%%%.%[%]%+%-%?])", "%%%1")
:gsub("%*", ".*") .. "$"
end

local child = self:FirstMoveChild()
while IsValidEntity(child) do
local childName = child:GetName()
local className = child:GetClassname()

local match = false
if usePattern then
match = childName:match(pattern) or className:match(pattern)
else
match = childName == name or className == name
end

if match then
return child
end

-- Check children recursively
local result = child:GetChild(name)
if result then
return result
end

child = child:NextMovePeer()
end

return nil
end


---
---Send an input to this entity.
---
Expand Down Expand Up @@ -443,4 +489,13 @@ function CBaseAnimating:GetAttachmentNameAngles(name)
return self:GetAttachmentAngles(self:ScriptLookupAttachment(name))
end

---
---Gets the forward vector of a named attachment.
---
---@param name string
---@return Vector
function CBaseAnimating:GetAttachmentNameForward(name)
return self:GetAttachmentForward(self:ScriptLookupAttachment(name))
end

return version
12 changes: 10 additions & 2 deletions scripts/vscripts/alyxlib/globals.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--[[
v2.6.0
v2.7.0
https://github.com/FrostSource/alyxlib

Provides common global functions used throughout extravaganza libraries.
Expand All @@ -14,7 +14,7 @@
-- These are expected by globals
require 'alyxlib.utils.common'

local _version = "v2.6.0"
local _version = "v2.7.0"

---
---A registered AlyxLib addon.
Expand Down Expand Up @@ -261,6 +261,14 @@ function IsVREnabled()
return GlobalSys:CommandLineCheck('-vr')
end

---
---Gets if the game was started with `+vr_enable_fake_vr 1`.
---
---@return boolean
function IsFakeVREnabled()
return GlobalSys:CommandLineInt("+vr_enable_fake_vr", 0) == 1
end

---
---Prints all arguments with spaces between instead of tabs.
---
Expand Down
19 changes: 12 additions & 7 deletions scripts/vscripts/alyxlib/player/core.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--[[
v4.2.0
v4.2.1
https://github.com/FrostSource/alyxlib

Player script allows for more advanced player manipulation and easier
Expand Down Expand Up @@ -100,7 +100,7 @@ require "alyxlib.globals"
require "alyxlib.extensions.entity"
require "alyxlib.storage"

local version = "v4.2.0"
local version = "v4.2.1"

-----------------------------
-- Class extension members --
Expand Down Expand Up @@ -957,11 +957,16 @@ function CBasePlayer:UpdateWeaponsExistence()
end
end

for i = #weapons.genericpistols, 1, -1 do
local generic = weapons.genericpistols[i]
local swt = Entities:FindByName(nil, "wpnswitch_" .. generic:GetName())
if not swt then
table.remove(weapons.genericpistols, i)
if #weapons.genericpistols > 0 then
for i = #weapons.genericpistols, 1, -1 do
local generic = weapons.genericpistols[i]
-- Server change seems to destroy weapons before this is run
if IsValidEntity(generic) then
local swt = Entities:FindByName(nil, "wpnswitch_" .. generic:GetName())
if not swt then
table.remove(weapons.genericpistols, i)
end
end
end
end
end
Expand Down
Loading
Loading