Hello, I am making a DarkRP module for an auto cinema and I want an entity to be at the desk and has a derma menu that offers entry for however much. (Let's just say $100)
This is my serverside [LUA]AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
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:SetNPCState( NPC_STATE_SCRIPT )
self:SetSolid( SOLID_BBOX ) -- This entity uses a solid bounding box for collisions.
self:CapabilitiesAdd( 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:OnTakeDamage()
return false -- This NPC won't take damage from anything.
end
function ENT:AcceptInput( Name, Activator, Caller )
if Name == "Use" and Caller:IsPlayer() then
umsg.Start("ShopNPCUsed", Caller) -- Prepare the usermessage to that same player to open the menu on his side.
umsg.End() -- We don't need any content in the usermessage so we're sending it empty now.
end
end
function CheckMoney( ply )
if target.DarkRPVars.money >= 100 then--(ply:canAfford(100) == true) then
umsg.Start( "EntryPriceWork" )
umsg.Bool( true )
umsg.End()
ply:SetPos(Vector(-1626.050293, 1601.689575, -39.780334))
else
umsg.Start( "EntryPriceWork" );
umsg.Bool( false );
umsg.End();
end
end[/LUA]
And client: [LUA]include('shared.lua') -- At this point the contents of shared.lua are ran on the client only.
function NPCShopMenu()
local DButton1
local DLabel4
local DLabel3
local DFrame2
DFrame2 = vgui.Create('DFrame')
DFrame2:SetSize(450, 250)
DFrame2:Center()
DFrame2:SetTitle('Cinema Clerk')
DFrame2:SetSizable(true)
DFrame2:SetDeleteOnClose(false)
DFrame2:MakePopup()
DLabel3 = vgui.Create('DLabel')
DLabel3:SetParent(DFrame2)
DLabel3:SetPos(15, 35)
DLabel3:SetText('Welcome to the cinema')
DLabel3:SizeToContents()
DLabel3:SetTextColor(Color(255, 0, 0, 255))
DLabel4 = vgui.Create('DLabel')
DLabel4:SetParent(DFrame2)
DLabel4:SetPos(15, 55)
DLabel4:SetText('Tickets are 100$')
DLabel4:SizeToContents()
DLabel4:SetTextColor(Color(0, 128, 0, 255))
DButton1 = vgui.Create('DButton')
DButton1:SetParent(DFrame2)
DButton1:SetSize(70, 25)
DButton1:SetPos(15, 205)
DButton1:SetText('Buy Ticket')
DButton1.DoClick = function()
PlayerEntry()
end
-- We can also do anything else the client can do, like using the chat!
chat.AddText(Color(255,255,128), "Cinema Clerk: ",Color(255,255,255), "Welcome to the cinema, how can I help you?" )
end
usermessage.Hook("ShopNPCUsed", NPCShopMenu) --Hook to messages from the server so we know when to display the menu.
local function PlayerEntry( data )
if data:ReadBool() == true then
chat.AddText(Color(255,255,128), "Cinema Clerk: ",Color(255,255,255), "Payment made! Enjoy." )
else
chat.AddText(Color(255,255,128), "Cinema Clerk: ",Color(255,255,255), "You do not have enough money! Please come back when you have enough." )
end
end
usermessage.Hook( "EntryPriceWork", PlayerEntry )[/LUA]
Where have I gone wrong? (There aren't any console errors)
Help much appreciated! :)
I would rather not use the UserMessage Library, since it's outdated, better use the Net Library
[URL="http://wiki.garrysmod.com/page/Using_the_net_library"]Here [/URL]you can see how it works
Then, is there a specific reason, that you don't use the ENT:Use() Callback?
Thank you for the reply, though it didn't really help me.
It is probably a good idea that I start to use Net Library, but I am still unknowing of what the problem with this entity is.
Anyone able to help?
[editline]7th November 2013[/editline]
I found the problem. *Solved*
Sorry, you need to Log In to post a reply to this thread.