Garry's Mod

Garry's Mod

Ragdoll Mover
kuma7 4 Jan, 2023 @ 4:03pm
Ragdoll Mover can't move static props when they're child entities
Currently, Ragdoll mover can move all bones of child entities, unless the child entity used is a static prop. SetLocalPos can be used in this case in order to move such a prop, as long as EF_BONEMERGE isn't used.

Example code:

if SERVER then util.AddNetworkString("setlocalpos_test") concommand.Add("setlocalpos_test", function(ply, cmd, args) if #args < 3 then return end --intended spawn pos local tr = ply:GetEyeTrace() if not tr.Hit then return end local spawn = tr.HitPos + tr.HitNormal * 24 --check whether the spawn pos is out of bounds local boundsTr = util.TraceLine({ start = tr.HitPos, endpos = spawn, mask = MASK_SOLID_BRUSHONLY }) if boundsTr.Hit then spawn = boundsTr.HitPos + boundsTr.HitNormal * (tr.HitPos:Distance(boundsTr.HitPos)/2) end --spawn motionless entities at spawn pos local parent = ents.Create("prop_dynamic") local child = ents.Create("prop_dynamic") if not IsValid(parent) or not IsValid(child) then return end parent:SetModel(args[1]) child:SetModel(args[2]) local phys for k, v in ipairs({parent, child}) do phys = v:GetPhysicsObject() if IsValid(phys) then phys:EnableMotion(false) end v:SetPos(spawn) v:Spawn() end child:SetParent(parent, 0) local num = tonumber(args[3]) if num and num != 0 then child:AddEffects(EF_BONEMERGE) end timer.Simple(1, function() if not IsValid(child) then return end net.Start("setlocalpos_test") net.WriteEntity(child) net.Broadcast() end) end) else net.Receive("setlocalpos_test", function() local ent = net.ReadEntity() if not IsValid(ent) then return end local menu = vgui.Create("DFrame") menu:SetSize(600, 200) menu:Center() menu:MakePopup() menu:DoModal() local slider = vgui.Create("DNumSlider", menu) slider:SetSize(400, 100) slider:Center() slider:SetText("Test") slider:SetMin(-100) slider:SetMax(100) slider:SetValue(0) slider:SetDefaultValue(0) slider.OnValueChanged = function(self, value) if IsValid(ent) then ent:SetLocalPos(Vector(value, 0, 0)) end end end) end

This code adds a new console command called "setlocalpos_test".

It can be used this way:
setlocalpos_test "models/alyx.mdl" "models/Combine_Helicopter/helicopter_bomb01.mdl" 0

This creates two props, Alyx and a Helicopter Bomb, then it sets Alyx as the parent and opens a menu where the local player can move the X coordinate of LocalPos. When the third argument of the command is 0, EF_BONEMERGE isn't used and SetLocalPos works, otherwise it doesn't.
Last edited by kuma7; 4 Jan, 2023 @ 4:39pm
< >
Showing 1-1 of 1 comments
PenolAkushari  [developer] 5 Jan, 2023 @ 5:18am 
yeah, i just happened to take a look, props without bones can't be moved whereas stuff with bones does, as manipulatebone stuff does indeed work on bones. gonna look into this some time in the future, as i was mostly going to work on smh first and probably would add more stuff to ragdoll mover after i'd be done with save menu additions.

also thanks for using DoModal as i kind of missed it in the gmod wiki and i couldn't figure out how to make those popups that don't allow to use any other windows as long as they are up
< >
Showing 1-1 of 1 comments
Per page: 1530 50