Trying to make the gms_buildsite entity from Garry's Mod Stranded no collide with players but not the world.
I found this:
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index8483.html[/url]
Can someone elaborate a bit more one what I need to do to set this up?
I've never actually tried creating my own code, only edited what was already there.
ent1 = ent to nocollide
ent2 = with this
[QUOTE=tyguy;40790854]ent1 = ent to nocollide
ent2 = with this[/QUOTE]
Put
[code]local function ShouldCollideTestHook( gms_buildsite, ent2 )
if ( ent1:IsPlayer() and ent2:IsPlayer() ) then
return false //Returning false stops the entities from colliding
end
-- DO NOT RETURN FALSE HERE OR YOU WILL FORCE EVERY OTHER ENTITY NOT TO COLLIDE
end
hook.Add( "ShouldCollide", "ShouldCollideTestHook", ShouldCollideTestHook )[/code]
In both the gms_buildsite lua and shared.lua. Still didn't work.
Edit: I have to go to work for the next 9 hours, I'll check back then.
is gms_buildsite the class of the entity? then make ent1 and ent2 the arguments and use ent1:GetClass()
Here's gms_buildsite.lua
[code]
AddCSLuaFile()
ENT.Type = "anim"
ENT.Base = "gms_base_entity"
ENT.PrintName = "Buildsite"
ENT.Purpose = "To build."
ENT.Instructions = "Press use to add resources."
ENT.Model = ""
ENT.Color = Color( 90, 167, 243, 255 )
if ( CLIENT ) then return end
function ENT:OnInitialize()
self:DropToFloor()
self:SetMoveType( MOVETYPE_NONE )
self:SetMaterial( "models/wireframe" )
self.LastUsed = CurTime()
end
function ENT:AddResource( res, int )
self.Costs[ res ] = self.Costs[ res ] - int
if (self.Costs[ res ] <= 0) then self.Costs[ res ] = nil end
local str = ":"
for k, v in pairs( self.Costs ) do
str = str .. " " .. string.Replace( k, "_", " " ) .. " ( " .. v .. "x )"
end
self:SetNetworkedString( "Resources", str )
end
function ENT:Setup( model, class )
self:SetModel( model )
self.ResultClass = class
self:PhysicsInit( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
local phys = self:GetPhysicsObject()
if ( phys != NULL && phys ) then phys:EnableMotion( false ) end
end
function ENT:Finish()
if ( self.ResultClass ) then
local ent = ents.Create( self.ResultClass )
if ( self.NormalProp == true ) then ent.NormalProp = true end
ent:SetPos( self:GetPos() )
ent:SetAngles( self:GetAngles() )
ent:SetModel( self:GetModel() )
ent.Player = self.Player
ent:SetNWString( "Name", self.Name )
ent:Spawn()
local owner = ent.Player
if ( !IsValid( owner ) ) then owner = ent.Table end
SPropProtection.PlayerMakePropOwner( owner, ent )
ent:Fadein()
end
if ( IsValid( self ) ) then
if ( IsValid( self.Player ) ) then self.Player.HasBuildingSite = false end
self:Remove()
end
end
function ENT:OnUse( ply )
if ( CurTime() - self.LastUsed < 0.5 ) then return end
self.LastUsed = CurTime()
if ( self.Costs ) then
for k, v in pairs( self.Costs ) do
if ( ply:GetResource( k ) >= 0 ) then
if ( ply:GetResource( k ) < v ) then
self:AddResource( k, ply:GetResource( k ) )
ply:DecResource( k, ply:GetResource( k ) )
else
self:AddResource( k, v )
ply:DecResource( k, v )
end
end
end
if ( table.Count( self.Costs ) > 0 ) then
local str = "You need:"
for k, v in pairs( self.Costs ) do
str = str .. " " .. string.Replace( k, "_", " " ) .. " ( " .. v .. "x )"
end
str = str .. " to finish."
ply:SendMessage( str, 5, Color( 255, 255, 255, 255 ) )
else
self:Finish()
ply:SendMessage( "Finished!", 3, Color( 10, 200, 10, 255 ) )
end
else
self:Finish()
ply:SendMessage( "Finished!", 3, Color( 10, 200, 10, 255 ) )
end
end
[/code]
[lua]self:SetCollisionGroup( COLLISION_GROUP_WEAPON )[/lua]
This makes it solid to everything except players.
[QUOTE=Kogitsune;40797312][lua]self:SetCollisionGroup( COLLISION_GROUP_WEAPON )[/lua]
This makes it solid to everything except players.[/QUOTE]
Worked.
Someone else had me try a couple other methods that did collide them to me, but it then ignored me pressing E on the entity so I couldn't actually construct it. This no collided it to me, AND let me press E on it.
Thanks.
Sorry, you need to Log In to post a reply to this thread.