So I’ve got the base for my NPC, as well as the DFrame and button layout, but I have no clue how to use this table formatting someone gave me to implement entities in it to buy.
What the person gave me:
net.WriteTable(itemtable)
for k,v in pairs(itemtable) do
local itemtable = {} --main table
itemtable["entity_example"] = { -- registering a entity to table
name = "Health Pack",
entity = "health_pack",
price = 500,
}
and
ply:getDarkRPVar("money") //will return how much money ply has
ply:addMoney(50) //will add $50 to the player's balance
ply:addMoney(-100) //will take $100 from the player's balance, same as the one above but note use of a negative value to take vs. add
ply:canAfford(600) //will return true if the player can afford $600, false if not
local itemtable = {} --main table
itemtable["entity_example"] = { -- registering a entity to table
name = "Health Pack",
entity = "health_pack",
price = 500,
}
I also have my init.lua and my cl_init.lua here
init.lua
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
function ENT:Initialize()
self:SetModel("models/npc/bf2_reg/91st/bf291.mdl")
self:SetHullType( HULL_HUMAN );
self:SetHullSizeNormal();
self:SetSolid( SOLID_BBOX )
self:SetMoveType( MOVETYPE_STEP )
self:CapabilitiesAdd(CAP_TURN_HEAD + CAP_ANIMATEDFACE)
self:SetHullType(HULL_HUMAN)
self:SetHullSizeNormal()
self:SetUseType( SIMPLE_USE )
self:SetMaxYawSpeed( 5000 )
end
util.AddNetworkString("OpenMenu")
function ENT:AcceptInput(input, activator, caller)
if input == "Use" and activator:IsPlayer() then
net.Start("OpenMenu")
net.Send(caller)
end
end
cl_init.lua
include("shared.lua")
ENT.RenderGroup = RENDERGROUP_BOTH
net.WriteTable(itemtable)
surface.CreateFont( "Shop Title", {
font = "coolvetica",
size = 55,
weight = 1000,
antialias = true,
} )
surface.CreateFont( "DLabel", {
font = "coolvetica",
size = 30,
weight = 1000,
antialias = true,
} )
surface.CreateFont( "DButton", {
font = "coolvetica",
size = 25,
weight = 1000,
antialias = true,
} )
surface.CreateFont( "Price", {
font = "coolvetica",
size = 25,
weight = 1000,
antialias = true,
} )
net.Receive("OpenMenu", function()
local frame = vgui.Create("DFrame")
frame:SetSize(ScrW()/2, ScrH()/2)
frame:SetBackgroundBlur(true)
frame:Center()
frame:MakePopup()
frame:IsDraggable(false)
frame:SetTitle("")
function frame:Paint( w, h )
draw.RoundedBox( 5, 0, 0, w, h, Color( 0, 0, 0 ) )
draw.RoundedBox(0,5,5,w-10,h-10,Color(111,111,111))
end
local text = vgui.Create("DLabel", frame)
text:SetText("Hey there, so you wanna try your hand at piloting? Go ahead.")
text:SetPos(125, 5)
text:SetFont("DLabel")
text:SetColor(Color(255, 144, 0))
text:SetSize(1000, 30)
local text2 = vgui.Create("DLabel", frame)
text2:SetText("Here is a list of ships you can buy.")
text2:SetPos(300, 40)
text2:SetFont("DLabel")
text2:SetColor(Color(255, 144, 0))
text2:SetSize(1000, 30)
local rgb = Color
local DScrollPanel = vgui.Create( "DScrollPanel", frame )
DScrollPanel:SetSize( 565, 300 )
DScrollPanel:SetPos( 5, 500 )
DScrollPanel:Dock( FILL )
DScrollPanel:Center()
local sbar = DScrollPanel:GetVBar()
function sbar:Paint( w, h )
draw.RoundedBox( 0, 0, 0, w, h, rgb(52, 73, 94,100) )
end
function sbar.btnUp:Paint( w, h )
draw.RoundedBox( 0, 0, 0, w, h, rgb(192, 57, 43) )
end
function sbar.btnDown:Paint( w, h )
draw.RoundedBox( 0, 0, 0, w, h, rgb(192, 57, 43) )
end
function sbar.btnGrip:Paint( w, h )
draw.RoundedBox( 0, 0, 0, w, h, rgb(44, 62, 80) )
end
for k,v in pairs(itemtable) do
local button = vgui.Create("DButton", frame)
button:SetSize(200, 150)
button:SetPos(15, 80)
button:SetText("Buy a V-Wing")
button:SetFont("DButton")
button:SetColor(Color(0,0,0))
end
local text2 = vgui.Create("DLabel", frame)
text2:SetText("Cost: $250")
text2:SetPos(60, 170)
text2:SetFont("Price")
text2:SetColor(Color(255, 144, 0))
text2:SetSize(1000, 30)
end)
local itemtable = {} --main table
itemtable["entity_example"] = { -- registering a entity to table
name = "Health Pack",
entity = "health_pack",
price = 500,
}
hook.Add("PostDrawOpaqueRenderables", "NpcTitle", function()
for _, ent in pairs (ents.FindByClass("testnpc")) do
if ent:GetPos():Distance(LocalPlayer():GetPos()) < 800 then
local plyAng = LocalPlayer():GetAngles()
local ang = Angle(0, plyAng.y - 180, 0)
ang:RotateAroundAxis(ang:Forward(), 90)
ang:RotateAroundAxis(ang:Right(), -90)
cam.Start3D2D(ent:GetPos() + ent:GetForward() + ent:GetUp() * 85, ang, 0.1)
draw.RoundedBox(4, -155, -22, 310, 55, Color(10, 10, 10, 150))
draw.SimpleText( "Ship Merchant", "Shop Title", 0, -25, Color(0, 139, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP)
cam.End3D2D()
end
end
end)
If you can help me learn how to set up this table to buy entities I would be very appreciative, because I have no idea where any of it is supposed to go.