How can I make a SWEP that allows people who are holding it to walk through doors?
GM/ShouldCollide return false if one of the entities is player (which is holding that weapon) and the other one is door
Thanks
bump
you're calling all of that only one time: when the weapon initializes.
also according to the wiki,
This is only called if Entity:SetCustomCollisionCheck was used on one or both entities.
So what should I put it under instead of SWEP:Initialize
I don't think you understand basics, so take this spoon of cancer code
I tried adding that and a SetCustomCollisionCheck and it still collides with walls.
local SWEP={
Spawnable=true,
PrintName="door phaser"
Base="weapon_base",
Author="Revenant Moon AKA joeyjumper94",
Purpose="to walk through doors\nlike they aren't there",
Instructions="just take it out and\nwalk through the door",
DrawAmmo=false,
Slot=5,
DisableDuplicator=true,
}
function SWEP:Initialize()
self:SetHoldType("normal")
self.Owner:SetCustomCollisionCheck(true)
end
function SWEP:Deploy()
self.Owner:CollisionRulesChanged()
end
function SWEP:Holster()
self.Owner:CollisionRulesChanged()
end
local doors={
["func_door"]=true,
["prop_door_rotating"]=true,
["func_door_rotating"]=true,
}
local function IsDoor(ent)
if ent and ent:IsValid() and doors[ent:GetClass()] then
return true
end
return false
end
local function IsPlayer(ent)
if ent and ent:IsValid() and ent:GetClass()=="player" then
return true
end
return false
end
hook.Add("ShouldCollide","passs_through_doors_with_this_swep",function(ent1,ent2)
local ply
if IsDoor(ent1) and IsPlayer(ent2) then
ply=ent2
elseif IsPlayer(ent1) and IsDoor(ent2) then
ply=ent1
end
if ply and ply:GetActiveWeapon():IsValid() and ply:GetActiveWeapon():GetClass()=="door_phaser" then
return false
end
end)
weapons.Register(SWEP,"door_phaser")
put that into a lua file in
garrysmod\lua\autorun
Thanks, and I also understand it now.
Sorry, you need to Log In to post a reply to this thread.