Lua NPC ''Vendor''

Hey guys, i’ve been looking around on the gmod wiki and such, but I cant seem to find any hooks for NPC:OnUse or something like that, since I want that if you click the use button on a NPC a derma panel shows up. (I know how to make the derma panel.) Help would be great.
-Staneh

Hey, just today I’ve been messing around with the exact same thing, and I’m stuck where you are aswell. Can’t wait for a helpfull reply. (I’m a mapper, not a coder) :wink:

I think you need to use **[Gamemode.PlayerUse

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.PlayerUse)**.

Can I have your steam name? :smiley:

[editline]11:18AM[/editline]

Additional Notes

* If you override GM:PlayerUse, true must be returned to allow it!
* Seems to be called every 0.016 seconds (in my testing)
* Appears to be broken <-- Its broken.

Use this then use a table to search for what type of npc vendor it is…

“GMod Tower” team done something like this

Aren’t you helpful.

Use http://wiki.garrysmod.com/?title=KeyPress, the IN_* enums, a traceline and a usermessage :slight_smile:

Umm well, thanks, but i’m still… pretty noob in lua, and I have NO idea how to do that xD

Appears != It is


] lua_run hook.Add( "PlayerUse", "lol", function( ply, ent ) print( ply, ent ) end )
> hook.Add( "PlayerUse", "lol", function( ply, ent ) print( ply, ent ) end )...
Player [1][Overv]	Vehicle [122][prop_vehicle_jeep_old]
Player [1][Overv]	Vehicle [122][prop_vehicle_jeep_old]
Player [1][Overv]	Vehicle [122][prop_vehicle_jeep_old]
Player [1][Overv]	Vehicle [122][prop_vehicle_jeep_old]
Player [1][Overv]	Vehicle [122][prop_vehicle_jeep_old]
Player [1][Overv]	Vehicle [122][prop_vehicle_jeep_old]
Player [1][Overv]	[NPC 155/npc_citizen]
Player [1][Overv]	[NPC 155/npc_citizen]
Player [1][Overv]	[NPC 155/npc_citizen]
Player [1][Overv]	[NPC 155/npc_citizen]
Player [1][Overv]	[NPC 155/npc_citizen]
Player [1][Overv]	[NPC 155/npc_citizen]
Player [1][Overv]	[NPC 155/npc_citizen]
Player [1][Overv]	[NPC 155/npc_citizen]

So, how to make a code for this? D:

The code below should work, but I haven’t coded a SNPC ever before, so I’m not entirely sure.
[lua]hook.Add( “PlayerUse”, “lol”, function( ply, ent )
if ( ent:GetClass() == “stanehnpc” ) then
ent:OnUse( ply )
end
end )

function NPC:OnUse( ply )
print( ply:Nick() … " wants to open the shop!" )
end[/lua]

On the programming forum you wouldn’t be able to get away with these kind of ‘get me code i can copy’ requests, but if I don’t post a solution, someone else will.

From a gamemode. Not telling our all the noobie server will start using the script.

Where’d you get that then.

That looks about right, but yeah. Where DID you get that?

Staneh, you have a PM waiting.

He got it from a released gamemod (That was never done) called Roleplay

Link?

I invited u.

Just make entity with npc model and handle ent:use

Make a simple SNPC, copy and paste from gmod wiki if needed.

Add this to the serverside lua of the SNPC.

[lua]
function ENT:AcceptInput( input, activator, caller )
if input == “Use” && activator:IsPlayer() then
–Call your store menu here with a umsg or whatever.
self:SetAngles((activator:GetForward():Normalize()*-1):Angle()) – makes shopkeeper face user.
end
end
[/lua]

i have the every same problem trying to make a car dealer for darkRP using an NPC i have no idea what to do and this has confused me even more lol can some one please help me