/* Utility script for reloading SENTs/SWEPs Commmands: swep_reload[_sv/_cl] - Reloads SWEP . sent_reload[_sv/_cl] - Reloads SENT . swep_give - Strip-gives SWEP. */ // Edit this function to your needs. local function HasPrivilege(ply) if !ply:IsSuperAdmin() then MsgN("Only SuperAdmins may use this command.") return false end return true end /* Autocomplete generation */ local function MatchFilter(full, filter) filter = string.sub(filter, 2) // The autocomplete function doesn't strip the leading space. if filter == "" then return true end return string.lower(string.Left(full, string.len(filter))) == string.lower(filter) end local function SENTList(cmd, filter) local t = {} for class, _ in pairs(scripted_ents.GetList()) do if MatchFilter(class, filter) then t[#t + 1] = cmd .. " " .. class end end table.sort(t) return t end local function SWEPList(cmd, filter) local t = {} for _, weap in pairs(weapons.GetList()) do if MatchFilter(weap.Classname, filter) then t[#t + 1] = cmd .. " " .. weap.Classname end end table.sort(t) return t end /* Reload functions */ local function FileExistsInLua(path) return #file.FindInLua(path) > 0 end local function ReloadSWEP(ply, class) if !HasPrivilege(ply) then return end if !class || class == "" then return end SWEP = {Primary = {}, Secondary = {}, Base = "weapon_base", Folder = "weapons/" .. class} // Include the right file for the right state. local found = false for filename, state in pairs{["init.lua"] = SERVER, ["cl_init.lua"] = CLIENT} do if state && FileExistsInLua("weapons/" .. class .. "/" .. filename) then MsgN("Reloading " .. filename .. "...") include("weapons/" .. class .. "/" .. filename) found = true end end // Only run shared.lua if we can't find the other files. if !found && FileExistsInLua("weapons/" .. class .. "/shared.lua") then include("weapons/" .. class .. "/shared.lua") MsgN("Reloading shared.lua...") found = true end if found then weapons.Register(SWEP, class, true) MsgN(class .. " loaded.") else MsgN(class .. " not found.") end SWEP = nil end local function ReloadSENT(ply, class) if !HasPrivilege(ply) then return end if !class || class == "" then return end ENT = {} local found = false if SERVER && FileExistsInLua("entities/" .. class .. "/init.lua") then MsgN("Reloading init.lua...") include("entities/" .. class .. "/init.lua") found = true end if CLIENT && FileExistsInLua("entities/" .. class .. "/cl_init.lua") then MsgN("Reloading cl_init.lua...") include("entities/" .. class .. "/cl_init.lua") found = true end if found then scripted_ents.Register(ENT, class, true) MsgN(class .. " loaded.") else MsgN(class .. " not found.") end ENT = nil end local function UpdateSENT(ply, class) if !HasPrivilege(ply) then return end if !class || class == "" then return end local ENT = scripted_ents.Get(class) if !ENT then MsgN(class .. " not found.") return end local updated = 0 for _, ent in pairs(ents.FindByClass(class)) do local t = table.Copy(ENT) ent:SetTable(t) ent.Entity = ent ent:Initialize() updated = updated + 1 end MsgN(updated .. " entities updated.") end /* Console commands */ if SERVER then concommand.Add("swep_reload_sv", function(p, _, a) ReloadSWEP(p, a[1]) end, SWEPList) concommand.Add("sent_reload_sv", function(p, _, a) ReloadSENT(p, a[1]) end, SENTList) concommand.Add("sent_update_sv", function(p, _, a) UpdateSENT(p, a[1]) end, SENTList) end if CLIENT then concommand.Add("swep_reload_cl", function(p, _, a) ReloadSWEP(p, a[1]) end, SWEPList) concommand.Add("sent_reload_cl", function(p, _, a) ReloadSENT(p, a[1]) end, SENTList) concommand.Add("sent_update_cl", function(p, _, a) UpdateSENT(p, a[1]) end, SENTList) end /* Shared commands */ local function ChooseFunction(ply, which, class) if !ply || !which || !class then return end if which == "ReloadSWEP" then ReloadSWEP(ply, class) end if which == "ReloadSENT" then ReloadSENT(ply, class) end if which == "UpdateSENT" then UpdateSENT(ply, class) end end if SERVER then local function SharedCommand(ply, which, class) if !HasPrivilege(ply) then return end if !which || !class || class == "" then return end ChooseFunction(ply, which, class) umsg.Start("quickReloadShared", ply) umsg.String(which) umsg.String(class) umsg.End() end concommand.Add("swep_reload", function(p, _, a) SharedCommand(p, "ReloadSWEP", a[1]) end, SWEPList) concommand.Add("sent_reload", function(p, _, a) SharedCommand(p, "ReloadSENT", a[1]) end, SENTList) concommand.Add("sent_update", function(p, _, a) SharedCommand(p, "UpdateSENT", a[1]) end, SENTList) end if CLIENT then local function SharedReload(msg) ChooseFunction(LocalPlayer(), msg:ReadString(), msg:ReadString()) end usermessage.Hook("quickReloadShared", SharedReload) end /* Useful commands */ if SERVER then local function GiveSWEP(ply, class) if !HasPrivilege(ply) then return end if !class || class == "" then return end ply:StripWeapon(class) ply:Give(class) timer.Simple(0, ply.SelectWeapon, ply, class) end concommand.Add("swep_give", function(p, _, a) GiveSWEP(p, a[1]) end, SWEPList) end