• Question about derma and NPC's
    4 replies, posted
I was wondering recently how to make a simple NPC that sells you armor, or health or anything of the sort. For example, just a regular NPC. Walk up to it and press E, a small menu would open with a button that says "Buy Armor ($50)" {or something like that} and also an x button to close out. I've been looking around and quite frankly I'm not the greatest with derma. The commands to buy health/armor are already taken care of, just need the NPC to be taken care of. If I could get some pointers in a direction to show me where I should go, it would help a lot. (And no, by this I don't mean link me to a wiki page) Any help is greatly appreciated!
on ENT:Use, send a net message to the player to open a menu when the player clicks the buy button, send a message to the server (which will then verify that the player has the money) and then give them armor
An alternative is using AcceptInput: [lua]function ENT:AcceptInput( Name, Activator, Caller ) // If the input is the Use key, and a player did it if Name == "Use" and Caller:IsPlayer( ) then // networking -- networking:SendToClient( "ShopNPCUsed", Caller, self.shopid ); end end[/lua]
This might be a lot to ask but if anyone is up for it could you please supply me with an example code for the derma linking to a use function with the specified code in mind. Most tutorials that I've seen completely pass by what I want and I have to guess functions, etc so I can't do much. I didn't come here to just ask someone to make me a code but if it's possible to give me a code like such for future reference I would very much appreciate it
With the example above, in the place of //networking you'd do something like [lua]net.Start( "NameOfMessage" ); net.Send( Caller );[/lua] Also, in a server file make sure you call: [lua]util.AddNetworkString( "NameOfMessage" );[/lua] then on the client: [lua]net.Receive( "NameOfMessage", function( len ) local _panel = vgui.Create( "DPanel" ); _panel:SetSize( 500, 500 ); _panel:Center( ); end );[/lua]
Sorry, you need to Log In to post a reply to this thread.