• Health Regen UI Problem
    19 replies, posted
https://files.facepunch.com/forum/upload/278946/129205a0-867b-447f-a6d5-33a50067d834/image.png when i click purchase it does not purchase server side give health net.Receive("GiveHealthRegen", function(len, pl) local health = net.ReadString() if HealthRegenList[health] then local healthAmount = HealthRegenList[health].amount local price = HealthRegenList[health].price local money = pl:getDarkRPVar("money") if IsValid(pl) and pl:isCP() and money > price then if pl.boughtHealthRegenRecently == nil or CurTime() > pl.boughtHealthRegenRecently then local addHealth = pl:Health() + healthAmount pl:SetHealth(addHealth) pl:addMoney(-price) pl:EmitSound("items/battery_pickup.wav") buyhealthandarmor(pl, health, price, true) pl.boughtHealthRegenRecently = CurTime() + HealthConfig.RecentlyBoughtHealth else local timeLeft = string.sub(math.floor(CurTime() - pl.boughtHealthRegenRecently),2) pl:ChatPrint("You've purchased Health too recently! Please wait another ".. timeLeft.. " second(s).") end end end end) Client side ui, function openPageHealth()     local frame = vgui.Create("DFrame")     frame:SetSize(883, 650)     frame:Center()     frame:SetTitle("")     frame:SetSizable(true)     frame:MakePopup()     frame:ShowCloseButton( false )     frame.Paint = function(self)         draw.RoundedBox(0, 6, 0,871,50,Color( 31,33,41,255)) -- TOP surface.SetDrawColor( Color( 255, 255, 255, 255 ) ) --surface.DrawOutlinedRect( 6, 25, 871, 20 ) end local money  = LocalPlayer():getDarkRPVar("money") or 0 local PlayerWallet = "$"..FormatNumber( money ) playersmoney = vgui.Create( "DLabel", frame ) playersmoney:SetPos( 15,20 ) playersmoney:SetSize( 165, 18 ) playersmoney:SetFont("cash") playersmoney:SetTextColor(Color(144,183,152,255)) playersmoney:SetText ( "Cash: "..PlayerWallet ) playersmoney.Paint = function(self, w, h) surface.SetDrawColor(32,30,39,255) surface.DrawRect( 0, 0, w+10, h+10 ) surface.SetDrawColor( 32,30,39,255) surface.DrawOutlinedRect( 0, 0, w+10, h+10 ) end CloseButton = vgui.Create( "DButton", frame ) CloseButton:SetPos( 825,10 ) CloseButton:SetSize( 30, 10 ) CloseButton:SetText ( "" ) CloseButton.Paint = function(self, w, h) --surface.SetDrawColor(234,15,60,255) --surface.DrawRect(0,0,20,100) draw.RoundedBox(3,0,0,30,5,Color( 234,15,60,180)) --[[surface.SetDrawColor( 200,200,200, 150) surface.DrawRect( 0, 0, w, h ) surface.SetDrawColor( 20,20,20, 150) surface.DrawOutlinedRect( 0, 0, w, h )]]-- CloseButton.DoClick = function() frame:Close() end end local pagesback = vgui.Create( "DScrollPanel", frame) pagesback:SetPos(6, 45) pagesback:SetSize( 871, 600) pagesback.Paint = function (self, w, h) surface.SetDrawColor( 54,57,67,255) -- MAIN surface.DrawRect( 0, 0, w, h ) surface.SetDrawColor( 255,255,255, 255) --surface.DrawOutlinedRect( 0, 0, w, h ) --SHADOW MAIN surface.SetDrawColor( 60, 58, 70, 255 ) -- solid white, 0,0,0 is black surface.DrawRect( 0, 0, 880, 3 ) ---[-------------------------------------] end for k,v in pairs(HealthList) do local healthback = vgui.Create( "DPanel", pagesback) healthback:Dock( TOP ) healthback:SetSize( 0, 200 ) healthback:DockMargin( 5, 11, 5, 5) healthback.Paint = function (self, w, h ) surface.SetDrawColor( 63,65,74,255) -- SLICES surface.DrawRect(0,0,w,h) --GRADIENT MAIN surface.SetMaterial( gradient ) surface.SetDrawColor( 236, 21, 62, 255 ) -- solid white, 0,0,0 is black surface.DrawTexturedRect( 0, 195, 880, 5 ) surface.SetMaterial( gradientl ) surface.SetDrawColor( 252, 85, 85, 255 ) -- solid white, 0,0,0 is black surface.DrawTexturedRect( 0, 195, 880, 5 ) ---[-------------------------------------] GeneratePoly(0,0,50,300) end local healthnames = vgui.Create( "DLabel", healthback) healthnames:SetText(k) healthnames:Dock( FILL ) healthnames:DockMargin( 75, 5, 0, 0 ) healthnames:SetFont( "healthtext") healthnames:SetTextColor( Color(200,200,200,200) ) healthnames:SetExpensiveShadow( 2, Color(0,0,0, 200) ) local healthmodels = vgui.Create( "DModelPanel", healthback) healthmodels:Dock( FILL ) healthmodels:SetCamPos( Vector( 0, 200, 0 ) ) healthmodels:SetLookAng( Angle( 180, 90, 180 ) ) healthmodels:SetModel("models/Items/HealthKit.mdl") local healthprice = vgui.Create( "DLabel", healthback) healthprice:SetText("Price: "..v.price) healthprice:Dock( FILL ) healthprice:DockMargin( 75, 60, 0, 0 ) healthprice:SetFont( "policearmory" ) healthprice:SetTextColor( Color(200,200,200,200) ) healthprice:SetExpensiveShadow( 2, Color(0,0,0, 200) ) local healthbutton = vgui.Create( "DButton", healthback) healthbutton:SetSize( 264, 35 ) healthbutton:SetPos ( 650, 75 ) healthbutton:SetText( "" ) healthbutton.Paint = function( self, w, h ) surface.SetDrawColor(25,27,36,255) surface.DrawRect( 3, 3, 150, 30 ) surface.SetMaterial( gradient ) surface.SetDrawColor( 236, 21, 62, 255 ) -- solid white, 0,0,0 is black surface.DrawTexturedRect( 0, 0, 150, 30 ) surface.SetMaterial( gradientl ) surface.SetDrawColor( 252, 85, 85, 255 ) -- solid white, 0,0,0 is black surface.DrawTexturedRect( 0, 0, 150, 30 ) --draw.RoundedBox( 0, 0, 0,self:GetWide(),self:GetTall(),Color(40,40,40,0)) draw.SimpleText( "PURCHASE", "buytext", 10, 2, hovcol ) if healthbutton:IsHovered() then hovcol = Color(255,138,131,255) else hovcol = Color(255,255,255,255) end end function healthbutton:DoClick() net.Start("GiveHealthRegen") net.WriteString( k ) net.SendToServer() end end end
It should work if you activate your windows
lol
Do you get any errors? Does it take your money but not do anything else?
nah nothing does not take money or no errors for some reason
Did you run util.AddNetworkString("GiveHealthRegen") server side?
AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") AddCSLuaFile("health_regen_config.lua") include("shared.lua") include("health_regen_config.lua") resource.AddSingleFile( "resource/fonts/Belgrad.ttf" )   util.AddNetworkString( "GiveHealthRegen" ) util.AddNetworkString( "HealthRegen" ) util.AddNetworkString( "buyhealthandarmor" ) function ENT:Initialize() self:SetModel(HealthConfig.Model) self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) self:SetUseType(SIMPLE_USE) end function ENT:AcceptInput(activator, caller) net.Start("HealthRegen") net.Send(caller) end function buyhealthandarmor(ply, item, price, bool) net.Start("buyhealthandarmor") net.WriteString(tostring(item)) net.WriteString(tostring(price)) net.WriteBool(bool) net.Send(ply) end net.Receive("GiveHealthRegen", function(len, pl) local health = net.ReadString() if HealthRegenList[health] then local healthAmount = HealthRegenList[health].amount local price = HealthRegenList[health].price local money = pl:getDarkRPVar("money") if IsValid(pl) and pl:isCP() and money > price then if pl.boughtHealthRegenRecently == nil or CurTime() > pl.boughtHealthRegenRecently then local addHealth = pl:Health() + healthAmount pl:SetHealth(addHealth) pl:addMoney(-price) pl:EmitSound("items/battery_pickup.wav") buyhealthandarmor(pl, health, price, true) pl.boughtHealthRegenRecently = CurTime() + HealthConfig.RecentlyBoughtHealth else local timeLeft = string.sub(math.floor(CurTime() - pl.boughtHealthRegenRecently),2) pl:ChatPrint("You've purchased Health too recently! Please wait another ".. timeLeft.. " second(s).") end end end end) my whole server side
are you trying to get it to spawn a health kit in-front of you or just add the health directly?
add directly
im not sure if this could cause it to break, but you have some functions referring to ENT which will be useless in your case since you are adding it directly try remove these functions function ENT:Initialize() function ENT:AcceptInput()
You don't define the variable hovcol anywhere making it global so all the buttons are using the same variable.         draw.SimpleText( "PURCHASE", "buytext", 10, 2, hovcol )         if healthbutton:IsHovered() then             hovcol = Color(255,138,131,255)         else             hovcol = Color(255,255,255,255)         end What you should be doing is something like: local hovcol = self:IsHovered() and Color(255, 138, 131) or color_white in the button's paint function before you draw the text. Also you should check if a player's money is bigger than or equal to (>=) the price and network the amount of health they're buying instead of the item's entire name.
ok i will give u more feedback
Try add a print in the net.receive("GiveHealthRegen") to see if its actually being called, if it does, move the print inside an ifstatement then if that works move it inside the next... etc
so i put it here net.Receive("GiveHealthRegen", function(len, pl) local health = net.ReadString() if HealthRegenList[health] then print ("net.receiveeee health works" ) and it doesnt print!
Try change function healthbutton:DoClick() net.Start("GiveHealthRegen") net.WriteString( k ) net.SendToServer() end to healthbutton.DoClick = function() net.Start("GiveHealthRegen") net.WriteString( k ) net.SendToServer() end
tried still nothing
try add if CLIENT then return end to the top of your server file, above the util.AddNetworkString's
AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") AddCSLuaFile("health_regen_config.lua") include("shared.lua") include("health_regen_config.lua") resource.AddSingleFile( "resource/fonts/Belgrad.ttf" ) if CLIENT then util.AddNetworkString( "GiveHealthRegen" ) util.AddNetworkString( "HealthRegen" ) util.AddNetworkString( "buyhealthandarmor" ) function ENT:Initialize() self:SetModel(HealthConfig.Model) self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) self:SetUseType(SIMPLE_USE) end function ENT:AcceptInput(activator, caller) net.Start("HealthRegen") net.Send(caller) end function buyhealthandarmor(ply, item, price, bool) net.Start("buyhealthandarmor") net.WriteString(tostring(item)) net.WriteString(tostring(price)) net.WriteBool(bool) net.Send(ply) end net.Receive("GiveHealthRegen", function(len, pl) local health = net.ReadString() if HealthList[health] then print ("net.receiveeee health works" ) local healthAmount = HealthList[health].amount local price = HealthList[health].price local money = pl:getDarkRPVar("money") if IsValid(pl) and pl:isCP() and money > price then if pl.boughtHealthRegenRecently == nil or CurTime() > pl.boughtHealthRegenRecently then local addHealth = pl:Health() + healthAmount pl:SetHealth(addHealth) pl:addMoney(-price) pl:EmitSound("items/battery_pickup.wav") buyhealthandarmor(pl, health, price, true) pl.boughtHealthRegenRecently = CurTime() + HealthConfig.RecentlyBoughtHealth else local timeLeft = string.sub(math.floor(CurTime() - pl.boughtHealthRegenRecently),2) pl:ChatPrint("You've purchased Health too recently! Please wait another ".. timeLeft.. " second(s).") end end end end) end like that
also if you click all the buttons does nothing happen?
fixed it i had if IsValid(pl) and pl:isCP() and money > price then suppose to be if IsValid(pl) and money > price then
Sorry, you need to Log In to post a reply to this thread.