• Test whether there is a free space before spawning entity
    3 replies, posted
This is my code for a building weapon. It spawns a models/hunter/blocks/cube075x075x075.mdl a bit above where you are looking. How do i get this to test if the WHOLE area it's going to spawn in is empty and only then spawn an entity. Right now you are able to spawn stuff inside walls and in blocks so i'd like to fix this thx. SWEP.PrintName = "Builder" SWEP.Author = "olismith1" SWEP.Instructions = "Builds shit" SWEP.Spawnable = true SWEP.AdminOnly = true SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" SWEP.Weight = 5 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false SWEP.Slot = 1 SWEP.SlotPos = 2 SWEP.DrawAmmo = false SWEP.DrawCrosshair = true SWEP.ViewModel = "models/weapons/v_pistol.mdl" SWEP.WorldModel = "models/weapons/w_pistol.mdl" local ShootSound = Sound( "Metal.SawbladeStick" ) function SWEP:PrimaryAttack() self:Build() self:EmitSound( ShootSound ) end function SWEP:SecondaryAttack() --pass end function SWEP:Build() local ent = ents.Create( "wooden_block" ) if ( !IsValid( ent ) ) then return end ent:SetPos(Vector(self.Owner:GetEyeTrace().HitPos.x, self.Owner:GetEyeTrace().HitPos.y, self.Owner:GetEyeTrace().HitPos.z + 37.5)); ent:Spawn() end
Sandbox Tools uses this functions to place something. It uses trace. You can store it in the variable instead of calling 3 times. local min = ent:OBBMins() ent:SetPos( trace.HitPos - trace.HitNormal * min.z )
util.TraceHull might be what you're looking for
I've done something like this before, heres the code: hastebin Place this somewhere in lua\autorun Also why is the syntax highlighting so broken here
Sorry, you need to Log In to post a reply to this thread.