Shared Utilities
Utility functions available on both client and server.
cLib.GetStringTotalWords
Count words in a string.
local count = cLib.GetStringTotalWords(str)local words = cLib.GetStringTotalWords("Hello world, this is a test")
-- Result: 6Engine Entity Detection
cLib.IsEngineWeapon
Check if weapon class is a default GMod weapon.
local isEngine = cLib.IsEngineWeapon(weaponClass)cLib.IsEngineWeapon("weapon_pistol") -- true
cLib.IsEngineWeapon("weapon_crowbar") -- true
cLib.IsEngineWeapon("m9k_ak47") -- falsecLib.IsEngineEntity
Check if entity class is a default GMod entity.
local isEngine = cLib.IsEngineEntity(entityClass)cLib.IsEngineEntity("item_healthkit") -- true
cLib.IsEngineEntity("item_battery") -- true
cLib.IsEngineEntity("custom_entity") -- falsecLib.GetEngineEntityModel
Get the world model for engine entities/weapons.
local model = cLib.GetEngineEntityModel(class)local model = cLib.GetEngineEntityModel("weapon_pistol")
-- "models/weapons/w_pistol.mdl"
local model = cLib.GetEngineEntityModel("item_healthkit")
-- "models/items/healthkit.mdl"Engine Lookup Tables
-- Available weapons
cLib.EngineWeapons = {
["weapon_357"] = "models/weapons/w_357.mdl",
["weapon_ar2"] = "models/weapons/w_irifle.mdl",
["weapon_pistol"] = "models/weapons/w_pistol.mdl",
-- ... etc
}
-- Available entities
cLib.EngineEntities = {
["item_healthkit"] = "models/items/healthkit.mdl",
["item_battery"] = "models/items/battery.mdl",
["item_ammo_pistol"] = "models/items/boxsrounds.mdl",
-- ... etc
}Practical Example
-- Get proper model for any item
function GetItemModel(class)
-- Check if it's an engine item
local model = cLib.GetEngineEntityModel(class)
if model then return model end
-- Try to get from entity/weapon
local ent = weapons.Get(class)
if ent and ent.WorldModel then
return ent.WorldModel
end
local entTable = scripted_ents.Get(class)
if entTable and entTable.Model then
return entTable.Model
end
return "models/error.mdl"
end