• Get Eyetrace of a person that see an entities
    8 replies, posted
I've been working on making a entities that could kill someone if they see the item. But I cant get the geteyetrace in the right commands. [CODE]function ENT:Think() local tr = Player:GetEyeTrace(); if tr.Entity.PrintName == "voodoodoll" then tr.Entity:EmitSound(self.Shout) timer.Simple( 1, function() self.player:KillSilent() end) end end[/CODE] [QUOTE][ERROR] attempt to call method 'GetEyeTrace' (a nil value)[/QUOTE] [CODE]function ENT:Think() local tr = self.Player:GetEyeTrace(); if tr.Entity.PrintName == "voodoodoll" then tr.Entity:EmitSound(self.Shout) timer.Simple( 1, function() self.player:KillSilent() end) end end[/CODE] [QUOTE][ERROR] attempt to index field 'Player' (a nil value)[/QUOTE] Help please
Use [URL="http://wiki.garrysmod.com/page/util/TraceLine"]util.TraceLine[/URL] or util.TraceHull and detect if the tr.Entity is a player. And if so kill them. Neither of your examples would ever work. Player is not defined in either.
[QUOTE=crazyscouter;45714091]Use [URL="http://wiki.garrysmod.com/page/util/TraceLine"]util.TraceLine[/URL] or util.TraceHull and detect if the tr.Entity is a player. And if so kill them. Neither of your examples would ever work. Player is not defined in either.[/QUOTE] I still dont get it, could you please help me to solve the problem? Here's the full SWEP [CODE]ENT.Base = "base_gmodentity" ENT.PrintName = "voodoodoll" ENT.MineModel = Model("doll01") ENT.MineMat = Material("doll01") ENT.Type = "AI" ENT.Shout = Sound("vo/npc/male01/ohno.wav") function ENT:Initialize() self:SetModel("models/props_c17/doll01.mdl") self:PhysicsInit(SOLID_BBOX) -- Make us work with physics, self:SetMoveType(MOVETYPE_VPHYSICS) -- after all, gmod is a physics self:SetSolid(SOLID_VPHYSICS) -- Toolbox local phys = self:GetPhysicsObject() if (phys:IsValid()) then self:PhysWake() end end function ENT:Use( activator, caller ) return end function ENT:Think() local ply = self.Owner if not IsValid(ply) then return end if ply:GetEyeTrace().Entity.PrintName == "voodoodoll" then ply:EmitSound(self.Shout) timer.Simple( 1, function() ply:KillSilent() end) end if IsValid(self) and IsValid(self.fire) then self.fire:SetPos(tr.Entity:GetPos()) end end[/CODE]
TraceHull traces out the shape of an object to see if it'll hit something. tr.Entity can be anything from the world, to a prop to a player... tr.Entity can be anything regardless of whether the trace was a thin line, or a large box... GetEyeTrace is a helper-function to perform a trace commonly performed from the eyes to where the eyes are pointing, i.e. what the player is looking at... As you're doing the check to see if your player object IsValid, do a check on the tr.Entity as well. Don't assume each entity has a PrintName, do a check for that too.
[QUOTE=Acecool;45714779]TraceHull traces out the shape of an object to see if it'll hit something. tr.Entity can be anything from the world, to a prop to a player... tr.Entity can be anything regardless of whether the trace was a thin line, or a large box... GetEyeTrace is a helper-function to perform a trace commonly performed from the eyes to where the eyes are pointing, i.e. what the player is looking at... As you're doing the check to see if your player object IsValid, do a check on the tr.Entity as well. Don't assume each entity has a PrintName, do a check for that too.[/QUOTE] I still don't know how to solve the geteyetrace... :(
[QUOTE=kiryuki;45715397]I still don't know how to solve the geteyetrace... :([/QUOTE] Are you sure the owner is being set? It's clear that the player is invalid.
Dude your player object is non existant, it isn't available in the scope of the function you are using. Self.owner has NEVER worked for me. Store the player on the entity yourself somewhere so it is accessable. [editline]17th August 2014[/editline] Not to mention outside of sandbox p sure the setowner method isn't even called. How is this entity put into the game? I can tell you how you create setowner if I know how it comes to be
self.Owner does not exist for entities unless you explicitly set it.
[QUOTE=Robotboy655;45717381]self.Owner does not exist for entities unless you explicitly set it.[/QUOTE] I still don't know how to set the entities are just players... If I use IsPlayer or Player they will still appear as error.
Sorry, you need to Log In to post a reply to this thread.