Hey, I have been trying to code a bit miner entity. It is automatically adding bits to its networked int. But my problem is with creating a collect button, I have no idea how can I create one.
Here is the init.lua
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
util.AddNetworkString("bithud")
util.AddNetworkString("receive")
function ENT:Initialize()
self:SetModel("models/props_lab/servers.mdl")
self.Entity:SetUseType(SIMPLE_USE)
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
local phys = self:GetPhysicsObject()
if phys:IsValid() then
phys:Wake()
end
end
function ENT:Use(activator)
local myBits = tonumber( self:GetNWInt("bits") )
local myMoney = tonumber( activator:GetNWInt("money") )
local myBitMoney = myBits*100
net.Start("bithud")
net.Send(activator)
end
function ENT:Think()
local myBits = tonumber( self:GetNWInt("bits") )
self:SetNWInt("bits", myBits + 1 )
self:NextThink(CurTime() + 3)
return true
end
and the cl_init.lua
include("shared.lua")
function ENT:Draw()
self:DrawModel()
end
function bithud()
local bitmenu = vgui.Create("DFrame")
bitmenu:SetTitle("Bitminer Menu")
bitmenu:SetSize(250,190)
bitmenu:SetPos(ScrW()/2-125, ScrH()/2-95)
bitmenu:SetDraggable(true)
bitmenu:ShowCloseButton(true)
bitmenu:MakePopup()
bitmenu.Paint = function()
local client = LocalPlayer()
local eye = client:GetEyeTrace()
if eye.Entity:GetClass() == "bitminer" then
surface.CreateFont("BitFont",{font = Tahoma, size = 25, })
draw.RoundedBox(2,0,0,ScrW(),ScrH(),Color(70,70,70,200))
draw.SimpleText(eye.Entity:GetNetworkedInt("bits").. " bitcoins mined.","BitFont",37,35,Color(255,255,255,255))
local bcol = vgui.Create("DButton", bitmenu)
bcol:SetSize(110,40)
bcol:SetText("Collect")
bcol:SetPos(50,90)
function bcol:DoClick()
local ply = LocalPlayer()
net.Start("receive")
net.SendToServer(ply)
end
end
end
end
net.Receive("bithud", bithud)
Don’t mind the “if eye.Entity:GetClass() == “bitminer” then” part, I have been trying things, I know it’s not necessary.
Thanks!