I'm trying to set my entity code shown below, so when it touches the entities below "vault_jedi" "vault_sith" etc... It disappears, and plays the sound show below and the effect.
Sound works well and effect, But heres the issue: When the entity touches ANYTHING it disappears and plays the sound and effect.
I want it to do so ONLY when it touches "vault_jedi". Any idea how to?
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
function ENT:Initialize()
self:SetModel("models/swtor/arsenic/tyler/yellowholocron.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
local phys = self:GetPhysicsObject()
if phys:IsValid() then
phys:Wake()
end
end
function ENT:StartTouch( vault_jedi )
self:EmitSound( "blink/enter" .. math.random( 1, 2 ) .. ".wav" )
PrintMessage( HUD_PRINTTALK, "<lg>The Eternal Empire's Holocron has been returned.</lg>" )
self:VisualEffect();
self:Remove()
end
function ENT:StartTouch( vault_sith )
self:EmitSound( "blink/enter" .. math.random( 1, 2 ) .. ".wav" )
PrintMessage( HUD_PRINTTALK, "<lg>The Eternal Empire's Holocron has been stolen!</lg>" )
self:VisualEffect();
self:Remove()
end
function ENT:StartTouch( vault_ee )
self:EmitSound( "blink/enter" .. math.random( 1, 2 ) .. ".wav" )
PrintMessage( HUD_PRINTTALK, "<lg>The Eternal Empire's Holocron has been returned.</lg>" )
self:VisualEffect();
self:Remove()
end
function ENT:StartTouch( vault_sith )
self:EmitSound( "blink/enter" .. math.random( 1, 2 ) .. ".wav" )
PrintMessage( HUD_PRINTTALK, "<lg>The Eternal Empire's Holocron has been stolen!</lg>" )
self:VisualEffect();
self:Remove()
end
function ENT:VisualEffect()
local effectData = EffectData();
effectData:SetStart(self:GetPos());
effectData:SetOrigin(self:GetPos());
effectData:SetScale(8);
util.Effect("mr_effect27", effectData, true, true);
self:Remove();
end;
Maybe try this.
function ENT:Touch( ent )
if ent:GetClass() == Entity( 1 ) then
-- Code Here
end
end
You might have to find a better way of finding the entity that is touching it though because if you put that on a server it will only run the code when the first player on the server runs into the vault. Not sure if this'll work though, just guessing.
That if sentence will never be true because you are comparing a string with a player object.
Here are a few examples on how you can make ENT:Touch work with specific entities:
function ENT:Touch( ent )
-- 1st way: comparing the entity classes
if not ( ent:GetClass() == --[[INSERT THE CLASS OF THE ENTITY HERE]] ) then return; end
-- 2nd way: checking if the entity is a player
if not ( ent:IsPlayer() ) then return; end
-- 3rd way: only target a specific player
if not ( ent:IsPlayer() ) then and ( ent:Team() == --[[INSERT THE INDEX OF THE TEAM HERE]] ) return; end
-- NOTE: You can always use other methods if you want to be more specific.
-- 4th way: we only want to target NPC's
if not ( ent:IsNPC() ) then return; end
-- NOTE: These conditions need to be put at top of the function.
end
I hope that gives you an insight on how to do it.
You guys didn't read the part where he said 'only be able to touch a specific entity?'
This means he wants to edit collisions, on both CLIENT and SERVER use GM/ShouldCollide
Also put this on the entity you are checking for Entity/SetCustomCollisionCheck, otherwise the above wont work.
team.GetName
What of it? I was just showing him a couple of ways he could do it.
Thanks a lot everyone
Sorry, you need to Log In to post a reply to this thread.