Added localization resource and notifications to prop ragdoll tool, removed some checks from ragdoll mover as a test whether gmod crashes now without them

This commit is contained in:
penolakushari 2023-08-19 21:02:48 +03:00
parent 630d23955d
commit a19d103949
3 changed files with 89 additions and 15 deletions

View File

@ -1245,18 +1245,18 @@ if SERVER then
local boneid = not pl.rgm.PropRagdoll and i or 0
local obj = ent:GetPhysicsObjectNum(boneid)
local poslen = postable[i].pos:Length()
local anglen = Vector(postable[i].ang.p,postable[i].ang.y,postable[i].ang.r):Length()
-- local poslen = postable[i].pos:Length()
-- local anglen = Vector(postable[i].ang.p,postable[i].ang.y,postable[i].ang.r):Length()
--Temporary solution for INF and NaN decimals crashing the game (Even rounding doesnt fix it)
if poslen > 2 and anglen > 2 then
-- if poslen > 2 and anglen > 2 then
obj:EnableMotion(true)
obj:Wake()
obj:SetPos(postable[i].pos)
obj:SetAngles(postable[i].ang)
obj:EnableMotion(false)
obj:Wake()
end
-- end
end
if postable[i] and postable[i].locked and ConstrainedAllowed:GetBool() then
@ -1264,18 +1264,18 @@ if SERVER then
for j=0,lockent:GetPhysicsObjectCount()-1 do
if bones[j] then
local obj = lockent:GetPhysicsObjectNum(j)
local poslen = bones[j].pos:Length()
local anglen = Vector(bones[j].ang.p,bones[j].ang.y,bones[j].ang.r):Length()
-- local poslen = bones[j].pos:Length()
-- local anglen = Vector(bones[j].ang.p,bones[j].ang.y,bones[j].ang.r):Length()
--Temporary solution for INF and NaN decimals crashing the game (Even rounding doesnt fix it)
if poslen > 2 and anglen > 2 then
-- if poslen > 2 and anglen > 2 then
obj:EnableMotion(true)
obj:Wake()
obj:SetPos(bones[j].pos)
obj:SetAngles(bones[j].ang)
obj:EnableMotion(false)
obj:Wake()
end
-- end
end
end

View File

@ -5,6 +5,15 @@ TOOL.ConfigName = ""
CVMaxPRBones = CreateConVar("sv_ragdollmover_max_prop_ragdoll_bones", 32, FCVAR_ARCHIVE + FCVAR_NOTIFY, "Maximum amount of bones that can be used in single Prop Ragdoll", 0, 4096)
local RGM_NOTIFY = {
ENT_SELECTED = {id = 0, iserror = false},
ENT_CLEARED = {id = 1, iserror = false},
APPLIED = {id = 2, iserror = false},
APPLY_FAILED = {id = 3, iserror = true},
APPLY_FAILED_LIMIT = {id = 4, iserror = true},
PROPRAGDOLL_CLEARED = {id = 5, iserror = false}
}
local function ClearPropRagdoll(ent)
ent.rgmPRidtoent = nil
ent.rgmPRenttoid = nil
@ -12,10 +21,17 @@ local function ClearPropRagdoll(ent)
duplicator.ClearEntityModifier(ent, "Ragdoll Mover Prop Ragdoll")
end
local function SendNotification(pl, id)
net.Start("rgmprDoNotify")
net.WriteUInt(id, 3)
net.Send(pl)
end
if SERVER then
util.AddNetworkString("rgmprSendConEnts")
util.AddNetworkString("rgmprApplySkeleton")
util.AddNetworkString("rgmprDoNotify")
duplicator.RegisterEntityModifier("Ragdoll Mover Prop Ragdoll", function(pl, ent, data)
@ -88,7 +104,14 @@ if SERVER then
end
end
if fail or count > CVMaxPRBones:GetInt() then return end
if fail or count > CVMaxPRBones:GetInt() then
if fail then
SendNotification(pl, RGM_NOTIFY.APPLY_FAILED.id)
else
SendNotification(pl, RGM_NOTIFY.APPLY_FAILED_LIMIT.id)
end
return
end
for id, data in pairs(ents) do
local ent = data.ent
@ -117,6 +140,7 @@ if SERVER then
duplicator.StoreEntityModifier(ent, "Ragdoll Mover Prop Ragdoll", data)
end
SendNotification(pl, RGM_NOTIFY.APPLIED.id)
end)
end
@ -169,6 +193,7 @@ function TOOL:Reload(tr)
for id, ent in pairs(ent.rgmPRidtoent) do
ClearPropRagdoll(ent)
end
SendNotification(self:GetOwner(), RGM_NOTIFY.PROPRAGDOLL_CLEARED.id)
end
return true
@ -176,6 +201,11 @@ end
if CLIENT then
TOOL.Information = {
{name = "right"},
{name = "reload"}
}
local PRUI
local HoveredEnt
@ -194,8 +224,29 @@ local function RGMCallApplySkeleton()
net.SendToServer()
end
local function rgmDoNotification(message)
local MessageTable = {}
for key, data in pairs(RGM_NOTIFY) do
if not data.iserror then
MessageTable[data.id] = function()
notification.AddLegacy("#tool.ragmover_propragdoll.message" .. data.id, NOTIFY_GENERIC, 5)
surface.PlaySound("buttons/button14.wav")
end
else
MessageTable[data.id] = function()
notification.AddLegacy("#tool.ragmover_propragdoll.message" .. data.id, NOTIFY_ERROR, 5)
surface.PlaySound("buttons/button10.wav")
end
end
end
MessageTable[message]()
end
local function DeleteNodeRecursive(node)
if IsValid(node) then
PRUI.PRTree.Nodes[node.id] = nil
node:SetParent(nil)
node:Remove()
for _, child in ipairs(node:GetChildNodes()) do
@ -490,17 +541,17 @@ local function PropRagdollCreator(cpanel)
helptext:SetWrap(true)
helptext:SetAutoStretchVertical(true)
helptext:SetDark(true)
helptext:SetText("Drag nodes from Constrained Entities tab into Prop Ragdoll tab to create skeleton for your prop ragdoll and then apply it. This tool can not read Prop Ragdoll skeleton data from existing Prop Ragdolls")
helptext:SetText("#tool.ragmover_propragdoll.treeinfo")
cpanel:AddItem(helptext)
local PropRagdollUI = {}
local constrainedents = CCol(cpanel, "Constrained Entities")
local constrainedents = CCol(cpanel, "#tool.ragmover_propragdoll.conents")
PropRagdollUI.EntTree = vgui.Create("DTree", constrainedents)
PropRagdollUI.EntTree:SetTall(300)
constrainedents:AddItem(PropRagdollUI.EntTree)
local creatorpanel = CCol(cpanel, "Prop Ragdoll")
local creatorpanel = CCol(cpanel, "#tool.ragmover_propragdoll.propragdoll")
PropRagdollUI.PRTree = vgui.Create("DTree", creatorpanel)
PropRagdollUI.PRTree:SetTall(300)
@ -538,7 +589,7 @@ local function PropRagdollCreator(cpanel)
creatorpanel:AddItem(PropRagdollUI.PRTree.HBar)
local applybutt = vgui.Create("DButton", creatorpanel)
applybutt:SetText("Apply Skeleton")
applybutt:SetText("#tool.ragmover_propragdoll.apply")
applybutt.DoClick = RGMCallApplySkeleton
@ -562,7 +613,7 @@ local function UpdateConstrainedEnts(ents)
PRUI.PRTree.Bones = 0
PRUI.PRTree.Nodes = {}
if not next(ents) then return end
if not next(ents) then rgmDoNotification(1) return end
for _, ent in ipairs(ents) do
local text = GetModelName(ent)
PRUI.EntNodes[ent] = PRUI.EntTree:AddNode(text, "icon16/brick.png")
@ -580,6 +631,7 @@ local function UpdateConstrainedEnts(ents)
HoveredEnt = nil
end
end
rgmDoNotification(0)
end
function TOOL.BuildCPanel(CPanel)
@ -595,6 +647,7 @@ function TOOL:DrawHUD()
if PRUI and PRUI.PRTree and PRUI.PRTree.Nodes then
for id, node in pairs(PRUI.PRTree.Nodes) do
local ent = node.ent
if not IsValid(ent) then break end
local pos = ent:GetPos():ToScreen()
local textpos = { x = pos.x+5, y = pos.y-5 }
surface.DrawCircle(pos.x, pos.y, 3.5, COLOR_RGMGREEN)
@ -614,7 +667,7 @@ function TOOL:DrawHUD()
end
net.Receive("rgmprSendConEnts", function(len, pl)
net.Receive("rgmprSendConEnts", function(len)
local validents = net.ReadBool()
local ents = {}
@ -629,4 +682,9 @@ net.Receive("rgmprSendConEnts", function(len, pl)
UpdateConstrainedEnts(ents)
end)
net.Receive("rgmprDoNotify", function(len)
local msgid = net.ReadUInt(3)
rgmDoNotification(msgid)
end)
end

View File

@ -152,3 +152,19 @@ tool.ragmover_ikchains.elbow=Elbow
tool.ragmover_propragdoll.name=Ragdoll Mover - Prop Ragdoll
tool.ragmover_propragdoll.name2=Rag Mover - Prop Ragdoll
tool.ragmover_propragdoll.desc=Create a "Ragdoll" out of props for Ragdoll Mover to work with
tool.ragmover_propragdoll.right=Select physics props and their constrained props
tool.ragmover_propragdoll.reload=Remove Prop Ragdoll Data
tool.ragmover_propragdoll.treeinfo=Drag nodes from Constrained Entities tab into Prop Ragdoll tab to create skeleton for your prop ragdoll and then apply it. This tool can not read Prop Ragdoll skeleton data from existing Prop Ragdolls
tool.ragmover_propragdoll.conents=Constrained Entities
tool.ragmover_propragdoll.propragdoll=Prop Ragdoll
tool.ragmover_propragdoll.apply=Apply Skeleton
tool.ragmover_propragdoll.message0=Entities selected!
tool.ragmover_propragdoll.message1=Selection cleared!
tool.ragmover_propragdoll.message2=Prop Ragdoll skeleton created!
tool.ragmover_propragdoll.message3=Couldn't apply Prop Ragdoll skeleton. Something must be wrong with the props.
tool.ragmover_propragdoll.message4=Too many bones in a skeleton!
tool.ragmover_propragdoll.message5=Prop Ragdoll skeleton data cleared!