1. Post #1
    StopMotion20's Avatar
    April 2008
    130 Posts
    I need help with the prop resizing tool.
    Ive done some programming some years ago ,but i need help.
    Im trying to remove lines of the LUA code.
    I dont want the hitbox to be resized along with the prop.
    I know about the No collide right click ,but im going to put ragdolls on the
    prop and the gravity gun cannot select anything except the resized prop ,because its so fekkin huge...
    There has to be a command that tells the prop to resize its hitbox.
    Wich line do i remove?
    Please...

    LUA Code / Resizing props Tool
    Code:
    TOOL.Category        = "Render"
    TOOL.Name            = "#Prop Resizer"
    TOOL.Command        = nil
    TOOL.ConfigName        = ""
    
    TOOL.ClientConVar[ "scalex" ]    = "1"
    TOOL.ClientConVar[ "scaley" ]    = "1"
    TOOL.ClientConVar[ "scalez" ]    = "1"
    TOOL.ClientConVar[ "anglex" ]    = "0"
    TOOL.ClientConVar[ "angley" ]    = "0"
    TOOL.ClientConVar[ "anglez" ]    = "0"
    TOOL.ClientConVar[ "frozen" ]    = "0"
    TOOL.ClientConVar[ "useinp" ]    = "1"
    TOOL.ClientConVar[ "shrink" ]    = "1"
    
    if SERVER then
        if server_settings.Int("sbox_maxresizedprops", -1) == -1 then
            CreateConVar("sbox_maxresizedprops",3)
        end
    end
    
    cleanup.Register( "resizedprops" )
    
    if ( CLIENT ) then
    
        language.Add( "Tool_prop_resizer_name", "Prop Resizer" )
        language.Add( "Tool_prop_resizer_desc", "Change the size that props are rendered and collided at." )
        language.Add( "Tool_prop_resizer_0", "Set the scales and click. Right click to reset to defaults. Reload to copy angles." )
    
        language.Add( "SBoxLimit_resizedprops", "You've hit the resized props limit!" )
        language.Add( "Undone_Resized Prop", "Undone Resized Prop" )
        language.Add( "Cleanup_resizedprops", "Resized Props" )
        language.Add( "Cleaned_resizedprops", "Cleaned up all Resized Props" )
    
    end
    
    function TOOL:LeftClick( trace, attach )
        local ent = trace.Entity
        if (CLIENT) then return true end
        if SERVER && !util.IsValidPhysicsObject( ent, trace.PhysicsBone ) then return false end
        
        if ent && ent:GetClass() == "gmod_resized_prop" then
            local pl            = self:GetOwner()
            local scale_x        = tonumber( self:GetClientInfo( "scalex" ) ) or 1
            local scale_y         = tonumber( self:GetClientInfo( "scaley" ) ) or 1
            local scale_z         = tonumber( self:GetClientInfo( "scalez" ) ) or 1
            local scalevec         = Vector(scale_x, scale_y, scale_z)
            local angle_x        = tonumber( self:GetClientInfo( "anglex" ) ) or ent:GetAngles().p
            local angle_y         = tonumber( self:GetClientInfo( "angley" ) ) or ent:GetAngles().y
            local angle_z         = tonumber( self:GetClientInfo( "anglez" ) ) or ent:GetAngles().r
            local inpangles     = Angle(angle_x, angle_y, angle_z)
            local frozen         = tonumber( self:GetClientInfo( "frozen" ) ) or 0
            local useinp         = tonumber( self:GetClientInfo( "useinp" ) ) or 1
            local model         = trace.Entity:GetModel()
            local pos = ent:GetPos()
        
            local prop = MakeResizedProp( pl, pos, inpangles, scalevec, model, frozen, useinp )
            if !prop:IsValid() then return end
    
            //!!TODO!! copy existing constraints to the replacement prop
            ent:Remove()
    
            undo.Create("Resized Prop")
            undo.AddEntity( prop )
            undo.SetPlayer( pl )
            undo.Finish()
    
            pl:AddCleanup( "resizedprops", spawner )
            
            return true
        end
    
        if ent && ent:GetClass() != "prop_physics" then return false end
    
        local pl            = self:GetOwner()
        local scale_x        = tonumber( self:GetClientInfo( "scalex" ) ) or 1
        local scale_y         = tonumber( self:GetClientInfo( "scaley" ) ) or 1
        local scale_z         = tonumber( self:GetClientInfo( "scalez" ) ) or 1
        local scalevec         = Vector(scale_x, scale_y, scale_z)
        local angle_x        = tonumber( self:GetClientInfo( "anglex" ) ) or ent:GetAngles().p
        local angle_y         = tonumber( self:GetClientInfo( "angley" ) ) or ent:GetAngles().y
        local angle_z         = tonumber( self:GetClientInfo( "anglez" ) ) or ent:GetAngles().r
        local inpangles     = Angle(angle_x, angle_y, angle_z)
        local frozen         = tonumber( self:GetClientInfo( "frozen" ) ) or 0
        local useinp         = tonumber( self:GetClientInfo( "useinp" ) ) or 1
        local model         = trace.Entity:GetModel()
        local pos = ent:GetPos()
    
        if ( !self:GetSWEP():CheckLimit( "resizedprops" ) ) then return false end
    
        local prop = MakeResizedProp( pl, pos, inpangles, scalevec, model, frozen, useinp )
        if !prop:IsValid() then return end
    
        //!!TODO!! copy existing constraints to the replacement prop
        ent:Remove()
    
        undo.Create("Resized Prop")
        undo.AddEntity( prop )
        undo.SetPlayer( pl )
        undo.Finish()
    
        pl:AddCleanup( "resizedprops", spawner )
    
        return true
    
    end
    
    function TOOL:RightClick( trace, attach )
        if (CLIENT) then return true end
        
        self:GetOwner():ConCommand("prop_resizer_scalex 1")
        self:GetOwner():ConCommand("prop_resizer_scaley 1")
        self:GetOwner():ConCommand("prop_resizer_scalez 1")
        self:GetOwner():ConCommand("prop_resizer_anglex 0")
        self:GetOwner():ConCommand("prop_resizer_angley 0")
        self:GetOwner():ConCommand("prop_resizer_anglez 0")
        self:GetOwner():ConCommand("prop_resizer_frozen 0")
        self:GetOwner():ConCommand("prop_resizer_useinp 1")
        
        return true
    end
    
    function TOOL:Reload( trace, attach )
        if (CLIENT) then return true end
        
        local ent = trace.Entity;
        if ent && ent:IsValid() then
            self:GetOwner():ConCommand("prop_resizer_anglex "..ent:GetAngles().p)
            self:GetOwner():ConCommand("prop_resizer_angley "..ent:GetAngles().y)
            self:GetOwner():ConCommand("prop_resizer_anglez "..ent:GetAngles().r)
            return true
        end
    end
    
    function MakeResizedProp( pl, pos, inpangles, scalevec, model, frozen, useinp )
    
        if ( !pl:CheckLimit( "resizedprops" ) ) then return nil end
    
        local prop = ents.Create( "gmod_resized_prop" )
        local position = pos + Vector(0,0,(10*scalevec.z*2))
        if (!prop:IsValid()) then return end
            prop:SetPos( position )
            prop:SetAngles( inpangles )
            prop:SetModel( model )
            prop:SetUseInp(useinp)
            prop:SetScaleXYZ(scalevec)
            prop:SetInpAngles(inpangles)
        prop:Spawn()
    
        if prop:GetPhysicsObject():IsValid() then
            phys = prop:GetPhysicsObject()
            if frozen == 1 then
                phys:EnableMotion( false )
            else
                phys:Wake()
            end
        end
    
        local tbl = { Player = pl }
    
        table.Merge(prop:GetTable(), tbl )
    
        pl:AddCount( "resizedprops", prop )
    
        return prop
    
    end
    
    duplicator.RegisterEntityClass( "gmod_resized_prop", MakeResizedProp, "Pos", "Ang", "increase", "decrease", "size", "model", "Vel", "aVel", "frozen" )
    
    function TOOL.BuildCPanel( CPanel )
    
        CPanel:AddControl( "Header", {    Text = "#Tool_prop_resizer_name", Description    = "#Tool_prop_resizer_desc" }  )
        CPanel:AddControl( "Checkbox", { Label = "Frozen", Command = "prop_resizer_frozen" } )
        
        CPanel:AddControl( "Slider",  { Label    = "X Scale",
                        Type    = "Float",
                        Min        = 0,
                        Max        = 10,
                        Command = "prop_resizer_scalex"} )
    
        CPanel:AddControl( "Slider",  { Label    = "Y Scale",
                        Type    = "Float",
                        Min        = 0,
                        Max        = 10,
                        Command = "prop_resizer_scaley"} )
    
        CPanel:AddControl( "Slider",  { Label    = "Z Scale",
                        Type    = "Float",
                        Min        = 0,
                        Max        = 10,
                        Command = "prop_resizer_scalez"} )
                        
        CPanel:AddControl( "Checkbox", { Label = "Restrict Angles", Command = "prop_resizer_useinp" } )                
                        
        CPanel:AddControl( "Slider",  { Label    = "X Angle",
                        Type    = "Float",
                        Min        = -360,
                        Max        = 360,
                        Command = "prop_resizer_anglex"} )
    
        CPanel:AddControl( "Slider",  { Label    = "Y Angle",
                        Type    = "Float",
                        Min        = -360,
                        Max        = 360,
                        Command = "prop_resizer_angley"} )
    
        CPanel:AddControl( "Slider",  { Label    = "Z Angle",
                        Type    = "Float",
                        Min        = -360,
                        Max        = 360,
                        Command = "prop_resizer_anglez"} )
    end

  2. Post #2
    Gold Member
    BackwardSpy's Avatar
    May 2008
    6,562 Posts
    From just looking over that code, looks more likely you'd have to add code in to make it keep the same sized hitbox, not take something out.

  3. Post #3
    StopMotion20's Avatar
    April 2008
    130 Posts
    so what do i add? Any clues? I have no idea how to LUA code anymore :P