commit fa6a626116a465770f225725cd7b0025323797d9 Author: Winded Date: Fri Jun 28 21:53:04 2013 +0300 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..129a666 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +Physgun Undo +============ + +A Garry's Mod tool to put ragdolls on their model idle pose, which most likely is a stand pose. +Pull requests are welcome. \ No newline at end of file diff --git a/info.txt b/info.txt new file mode 100644 index 0000000..020cd8c --- /dev/null +++ b/info.txt @@ -0,0 +1,6 @@ +"AddonInfo" +{ + "name" "Standing Pose Tool" + "author_name" "author" + "info" "This small tool can pose a ragdoll to it's model pose, which usually is a standing pose for ragdolls. It does not work properly with all ragdolls, but for most of them it does." +} \ No newline at end of file diff --git a/lua/autorun/standpose.lua b/lua/autorun/standpose.lua new file mode 100644 index 0000000..314b1c1 --- /dev/null +++ b/lua/autorun/standpose.lua @@ -0,0 +1,55 @@ + +local propt = {} + +propt.MenuLabel = "Stand Pose" +propt.Order = 5000 + +propt.Filter = function( self, ent ) + if ( !IsValid( ent ) ) then return false end + if ( ent:GetClass() != "prop_ragdoll" ) then return false end + return true +end + +propt.Action = function( self, ent ) + self:MsgStart() + net.WriteEntity( ent ) + self:MsgEnd() +end + +propt.Receive = function( self, length, player ) + + local rag = net.ReadEntity() + + if ( !IsValid( rag ) ) then return end + if ( !IsValid( player ) ) then return end + if ( rag:GetClass() != "prop_ragdoll" ) then return end + + local tr = util.TraceLine({start = rag:GetPos(),endpos = rag:GetPos() - Vector(0,0,3000),filter = rag}) + + local ent = ents.Create("prop_dynamic") + ent:SetModel(rag:GetModel()) + ent:SetPos(tr.HitPos) + local angle = (tr.HitPos - player:GetPos()):Angle() + ent:SetAngles(Angle(0,angle.y-180,0)) + ent:Spawn() + for i=0,rag:GetPhysicsObjectCount()-1 do + local phys = rag:GetPhysicsObjectNum(i) + local b = rag:TranslatePhysBoneToBone(i) + local pos,ang = ent:GetBonePosition(b) + phys:EnableMotion(true) + phys:Wake() + phys:SetPos(pos) + phys:SetAngles(ang) + if string.sub(rag:GetBoneName(b),1,4) == "prp_" then + phys:EnableMotion(true) + phys:Wake() + else + phys:EnableMotion(false) + phys:Wake() + end + end + ent:Remove() + +end + +properties.Add("standpose",propt) \ No newline at end of file diff --git a/lua/weapons/gmod_tool/stools/ragdollstand.lua b/lua/weapons/gmod_tool/stools/ragdollstand.lua new file mode 100644 index 0000000..185e961 --- /dev/null +++ b/lua/weapons/gmod_tool/stools/ragdollstand.lua @@ -0,0 +1,73 @@ + +TOOL.Category = "Poser" +TOOL.Name = "Stand Pose" +TOOL.Command = nil +TOOL.ConfigName = nil + +function TOOL:LeftClick(tr) + if self:GetStage() == 0 then + + if !IsValid(tr.Entity) then return false end + if tr.Entity:GetClass() != "prop_ragdoll" then return false end + + if CLIENT then return true end + + self.SelectedEnt = tr.Entity + self:SetStage(1) + return true + + else + + local rag = self.SelectedEnt + if !IsValid(rag) then + self:SetStage(0) + return true + end + + if CLIENT then return true end + + local ent = ents.Create("prop_dynamic") + ent:SetModel(rag:GetModel()) + ent:SetPos(tr.HitPos) + local angle = (tr.HitPos - self:GetOwner():GetPos()):Angle() + ent:SetAngles(Angle(0,angle.y-180,0)) + ent:Spawn() + for i=0,rag:GetPhysicsObjectCount()-1 do + local phys = rag:GetPhysicsObjectNum(i) + local b = rag:TranslatePhysBoneToBone(i) + local pos,ang = ent:GetBonePosition(b) + phys:EnableMotion(true) + phys:Wake() + phys:SetPos(pos) + phys:SetAngles(ang) + if string.sub(rag:GetBoneName(b),1,4) == "prp_" then + phys:EnableMotion(true) + phys:Wake() + else + phys:EnableMotion(false) + phys:Wake() + end + end + ent:Remove() + self:SetStage(0) + return true + + end +end + +function TOOL:RightClick(tr) + if self:GetStage() == 1 then + self:SetStage(0) + return true + end + return false +end + +if CLIENT then + +language.Add("tool.ragdollstand.name","Stand Pose") +language.Add("tool.ragdollstand.desc","Position ragdolls in a standing pose.") +language.Add("tool.ragdollstand.0","Left Click to select a ragdoll.") +language.Add("tool.ragdollstand.1","Now click on a position where you want the ragdoll to stand or Right Click to cancel.") + +end \ No newline at end of file