// ------------------------------------------------------------- // NPC Movers STOOL - v0.5 // Made By: Suicidal.Banana // This script is based of the standard gmod10 lamp.lua script // Helped by: SteveUK, aschmack // ------------------------------------------------------------- // combobox stuff npc_types = { Antlion = { name = 'Antlion', type = 'npc_antlion' }, Manhack = { name = 'Manhack', type = 'npc_manhack' }, } // tool settings TOOL.Category = "Transport" TOOL.Name = "#NPC Movers" TOOL.Command = nil TOOL.ConfigName = nil TOOL.ClientConVar['type'] = 'Antlion' TOOL.ClientConVar['ropelength'] = '128' // Add Default Language translation (saves adding it to the txt files) if ( CLIENT ) then language.Add( "npc_transport", "NPC Movers" ) language.Add( "Tool_npc_transport_name", "NPC Movers" ) language.Add( "Tool_npc_transport_desc", "Move objects using npc's" ) language.Add( "Tool_npc_transport_0", "Primary fire to create a roped npc, [Secondary to move it to where u aimed]-not yet" ) language.Add( "Undone_npc_transport", "Undone NPC Mover" ) end cleanup.Register( "npcs" ) function TOOL:LeftClick( trace, attach ) if trace.Entity && trace.Entity:IsPlayer() then return false end if (CLIENT) then return true end if (attach == nil) then attach = true end // If there's no physics object then we can't constraint it! if ( SERVER && attach && !util.IsValidPhysicsObject( trace.Entity, trace.PhysicsBone ) ) then return false end local ply = self:GetOwner() local pos, ang = trace.HitPos + trace.HitNormal * 10, trace.HitNormal:Angle() - Angle( 0, 0, 0 ) if ( !self:GetSWEP():CheckLimit( "npcs" ) ) then return false end local ntype = self:GetClientInfo('npc_transport_type') or 'Antlion' local ndata = npc_types[ntype] local r,g,b,a = trace.Entity:GetColor(); npc = MakeRopedNPC( ply, pos, ang, r, g, b, a) //?? if (!attach) then undo.Create("NPC") undo.AddEntity( npc ) undo.SetPlayer( self:GetOwner() ) undo.Finish() return true end local length = pl:GetClientNumber( "npc_transport_ropelength" ) local LPos1 = Vector( 0, 0, 0 ) local LPos2 = trace.Entity:WorldToLocal( trace.HitPos ) if (trace.Entity:IsValid()) then local phys = trace.Entity:GetPhysicsObjectNum( trace.PhysicsBone ) if (phys:IsValid()) then LPos2 = phys:WorldToLocal( trace.HitPos ) end end local constraint, rope = constraint.Rope( npc, trace.Entity, 0, trace.PhysicsBone, LPos1, LPos2, 0, length, 0, 1, material, nil ) undo.Create("Roped NPC") undo.AddEntity( npc ) undo.AddEntity( rope ) undo.AddEntity( constraint ) undo.SetPlayer( ply ) undo.Finish() return true end function TOOL:RightClick( trace ) //return self:LeftClick( trace, false ) end function SetRelationship( subject, target, relationship ) local relation = ents.Create( "ai_relationship" ) relation:SetKeyValue( "target", target ) relation:SetKeyValue( "subject", subject ) relation:SetKeyValue( "disposition", tostring( relationship ) ) relation:Spawn() relation:Fire( "ApplyRelationship", "", 0 ) // thanks to Devenger relation:Remove() // thanks Catdaemon for saying I should remove it afterwards. end function MakeRopedNPC( pl, Pos, Ang, r, g, b, a) if( RopeIncrement == nil ) then RopeIncrement = 0 end if ( !pl:CheckLimit( "npcs" ) ) then return false end // npc_clawscanner - npc_cscanner - npc_manhack - npc_antlion - npc_helicopter local npc = ents.Create( pl:GetClientInfo( "npc_transport_type" ) ) npc:SetPos( Pos ) npc:SetAngles( Ang ) npc:SetColor(r, g, b, a) -- npc:GetPhysicsObject():EnableCollisions( false ) npc:SetName( "npcmover_" .. tostring( RopeIncrement )) npc:AddRelationship("!player D_LI 99") -- like the spawner npc:AddRelationship("player D_FR 99") -- fear all others npc:Fire( "ApplyRelationship", "", 0 ) -- apply if( SinglePlayer() ) then SetRelationship ( "npcmover_" .. tostring( RopeIncrement ), "!player", 3) else SetRelationship ( "npcmover_" .. tostring( RopeIncrement ), "player", 3 ) end npc:Spawn() pl:AddCount( "npcs", npc ) pl:AddCleanup( "npcs", npc ) RopeIncrement = RopeIncrement + 1 return npc end duplicator.RegisterEntityClass( "npc_antlion", MakeRopedNPC, "Pos", "Ang", "r", "g", "b", "a") function TOOL.BuildCPanel( Panel ) Panel:AddControl( "Header", { Text = "#Tool_npc_transport_name", Description = "#Tool_npc_transport_desc" } ) local combo = {} combo.Label = 'NPC' combo.MenuButton = 0 combo.Folder = 'settings/menu/main/construct/npc_transport' combo.Options = {} for key,weapon in pairs(npc_types) do combo.Options[weapon.name] = { npc_type = key } end Panel:AddControl('ComboBox', combo) CPanel:AddControl( "Slider", { Label = "#Ropelength", Type = "Float", Min = 50, Max = 500, Command = "npc_transport_ropelength"} ) end