Ent:Use

Hey guys! I’ve been working on this Npc for pointshop, and the Use is not working :c
[lua]
–init
AddCSLuaFile( “cl_init.lua” ) – Make sure clientside
AddCSLuaFile( “shared.lua” ) – and shared scripts are sent.

include(‘shared.lua’)

function ENT:Initialize( ) --This function is run when the entity is created so it’s a good place to setup our entity.

self:SetModel( "models/humans/group01/female_01.mdl" ) -- Sets the model of the NPC.
self:SetHullType( HULL_HUMAN ) -- Sets the hull type, used for movement calculations amongst other things.
self:SetHullSizeNormal( )
self:SetSolid(  SOLID_BBOX ) -- This entity uses a solid bounding box for collisions.
self:CapabilitiesAdd( CAP_ANIMATEDFACE | CAP_TURN_HEAD ) -- Adds what the NPC is allowed to do ( It cannot move in this case ).
self:SetUseType( SIMPLE_USE ) -- Makes the ENT.Use hook only get called once at every use.
self:DropToFloor()

self:SetMaxYawSpeed( 90 ) --Sets the angle by which an NPC can rotate at once.

end

function ENT:Use( activator, caller )

if ( activator:IsPlayer() ) then

	activator:PS_ToggleMenu()
	activator:BroadcastLua([[surface.PlaySound('npc/roller/remote_yes.wav')]])


end

end

function ENT:Think()
– We don’t need to think, we are just a prop after all!
end
[/lua]
Does anyone know why?

Replace ENT:Use with ENT:AcceptInput. I know ENT:Use doesn’t always work on some NPCs.

[lua]
function ENT:AcceptInput( activator, caller )

	activator:PS_ToggleMenu()

end
[/lua]
Does not work :c

Did you check if the player was valid? I’m fairly new to lua and I’ve never done NPC’s so I’m not sure if I’m helping at all.

Try it like this.


function ENT:AcceptInput( name, activator, ply )
    if name == "Use" && ply:IsPlayer() then
		activator:PS_ToggleMenu()
	end
end


That doesn’t work, I think it may be one of these:
[lua]
self:SetModel( “models/humans/group01/female_01.mdl” ) – Sets the model of the NPC.
self:SetHullType( HULL_HUMAN ) – Sets the hull type, used for movement calculations amongst other things.
self:SetHullSizeNormal( )
self:SetSolid( SOLID_VPHYSICS ) – This entity uses a solid bounding box for collisions.
self:CapabilitiesAdd( CAP_ANIMATEDFACE | CAP_TURN_HEAD | CAP_MOVE_GROUND ) – Adds what the NPC is allowed to do ( It cannot move in this case ).
self:SetUseType( SIMPLE_USE ) – Makes the ENT.Use hook only get called once at every use.
self:DropToFloor()

self:SetMaxYawSpeed( 90 ) --Sets the angle by which an NPC can rotate at once.

[/lua]

Did you try debuging it to see if the PS_ToggleMenu() is being called?


function ENT:AcceptInput( name, activator, ply )
    if name == "Use" && ply:IsPlayer() then
		activator:PS_ToggleMenu()
                print("hi mom!")
	end
end

Already did that :slight_smile: No workerino :c

Hmmm I checked mine and didn’t find anything wrong with your Initialize function(Uses the same that mine does basically). What is your ENT.Type and ENT.Base set to?

ENT.Base = “base_ai” – This entity is based on “base_ai”
ENT.Type = “ai” – What type of entity is it, in this case, it’s an AI.

Derp forgot somthing. Try this adding this to the Initialize function(its the only difference I can see)

[lua]local PhysAwake = self.Entity:GetPhysicsObject( )
if PhysAwake:IsValid( ) then
PhysAwake:Wake( )
end
[/lua]

I decided to make it a prop instead, a lot more simple. :stuck_out_tongue: It works now. Thanks for trying.