Can anyone explain why this is happening? I've done everything in my knowledge to try and fix it but nothing worked.
[IMG]http://i.imgur.com/BTlnTrn.jpg[/IMG]
Could you give us your code. We can't really do anything without the code.
[QUOTE=Unknown Gamer;50351354]Could you give us your code. We can't really do anything without the code.[/QUOTE]
server side and client side scripts?
[QUOTE=H4;50351382]server side and client side scripts?[/QUOTE]
Just client side code.
I doubt that anything done on the server is causing this, but give them both anyway (unless that makes you uncomfortable).
[QUOTE=Unknown Gamer;50351388]Just client side code.[/QUOTE]
[CODE]local inventory = {}
local function inventoryReceive(tab)
inventory = tab
end
net.Receive("senddata",function(len)
local tab = net.ReadTable()
inventoryReceive(tab)
end)
function inventoryTable()
return inventory
end
function inventoryGetValue(name)
local d = inventoryTable()
return d[name]
end
function inventoryTableCheck()
return inventoryGetValue("inventory") or {}
end
function inventoryHasItem(name, amount)
if not amount then amount = 1 end
local i = inventoryTableCheck()
if i then
if i[name] then
if i[name].amount >= amount then
return true
else
return false
end
else
return false
end
else
return false
end
end
local function pickupKey()
if input.IsKeyDown(KEY_LALT) and input.IsKeyDown(KEY_R) then
net.Start("pickup")
net.SendToServer()
end
end
hook.Add("Think", "iskeysdown", pickupKey)
surface.CreateFont( "evo1", {
font = "Trebuchet24",
size = 22,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = true,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
} )
surface.CreateFont( "evo2", {
font = "Trebuchet24",
size = 22,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
} )
surface.CreateFont( "evo3", {
font = "Trebuchet24",
size = 18,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
} )
local function inventoryDrop(item)
net.Start("drop")
net.WriteString(tostring(item))
net.SendToServer()
end
local function inventoryUse(item)
net.Start("use")
net.WriteString(tostring(item))
net.SendToServer()
end
local function InventoryPanel(iname, name, amount, desc, model, parent)
local itempanel = vgui.Create( "DPanel", parent )
itempanel:SetSize( 600, 60 )
itempanel.Paint = function( self, w, h )
draw.SimpleText( string.lower(name), "evo2", 70, 10, Color( 255, 255, 255 ) )
draw.SimpleText( string.lower(desc), "evo3", 70, 35, Color( 255, 255, 255 ) )
end
local inventory = inventoryTableCheck()
for k, v in pairs(inventory) do
local use = vgui.Create( "DButton", itempanel )
use:SetSize( 120, 56 )
use:SetPos( 300, 1 )
use:SetText( "Use" )
use:SetFont( "evo2" )
use:SetTextColor( Color( 255, 255, 255 ) )
use.Paint = function( s, w, h )
surface.SetDrawColor(60,60,60,180)
surface.DrawRect(0,0,w,h)
if s.hover then
surface.SetDrawColor(50,50,50,190)
surface.DrawRect(0,0,w,h)
end
end
use.DoClick = function()
inventoryUse(k)
end
use.OnCursorEntered = function(s)
s.hover = true
end
use.OnCursorExited = function(s)
s.hover = false
end
local drop = vgui.Create( "DButton", itempanel )
drop:SetSize( 120, 56 )
drop:SetPos( 450, 1 )
drop:SetText( "Drop" )
drop:SetFont( "evo2" )
drop:SetTextColor( Color( 255, 255, 255 ) )
drop.Paint = function( s, w, h )
surface.SetDrawColor(60,60,60,180)
surface.DrawRect(0,0,w,h)
if s.hover then
surface.SetDrawColor(50,50,50,190)
surface.DrawRect(0,0,w,h)
end
end
drop.DoClick = function()
inventoryDrop(k)
end
drop.OnCursorEntered = function(s)
s.hover = true
end
drop.OnCursorExited = function(s)
s.hover = false
end
end
local image = vgui.Create( "SpawnIcon", itempanel )
image:SetSize( 64, 64 )
image:SetPos( 0, 0 )
image:SetModel(model)
image:SetMouseInputEnabled(false)
image.PaintOver = function()end
if amount < 1 then
local amountdisplay = vgui.Create("DLabel", image)
amountdisplay:SetPos(55,55)
amountdisplay:SetFont("evo3")
amountdisplay:SetText(amount)
amountdisplay:SizeToContents()
end
end
local isOpen = false
net.Receive("openinventory", function()
if isOpen == false then
isOpen = true
local f = vgui.Create("DFrame")
f:SetSize(600,600)
f:SetTitle("")
f:Center()
f:MakePopup()
f:SetDraggable(false)
f:ShowCloseButton(false)
f.Paint = function(s,w,h)
surface.SetDrawColor(60,60,60,180)
surface.DrawRect(0,0,w,h)
surface.SetDrawColor(60,60,60,190)
surface.DrawRect(0,0,w,h-(600-25))
surface.SetTextColor(255,255,255,255)
surface.SetFont("evo1")
surface.SetTextPos(2,0)
surface.DrawText("Inventory")
end
local close = vgui.Create("DButton", f)
close:SetSize(50,20)
close:SetPos(f:GetWide()-51,2)
close:SetText("X")
close:SetFont("evo2")
close:SetTextColor(Color(255,255,255,255))
close.Paint = function(s,w,h)
draw.RoundedBox(5,0,0,w,h,Color(150,150,150,255))
if s.hover then
draw.RoundedBox(5,0,0,w,h,Color(135,135,135,255))
end
end
close.DoClick = function(ply)
f:Close()
isOpen = false
end
close.OnCursorEntered = function(s)
s.hover = true
end
close.OnCursorExited = function(s)
s.hover = false
end
local itemlist = vgui.Create( "DPanelList", f)
itemlist:SetSize( f:GetWide(), f:GetTall()-25)
itemlist:SetPos( 0, 25 )
itemlist:EnableVerticalScrollbar( true )
itemlist:EnableHorizontal( false )
itemlist.VBar.Paint = function( s, w, h )
surface.SetDrawColor(75,75,75,180)
surface.DrawRect(0,0,w,h)
end
itemlist.VBar.btnUp.Paint = function( s, w, h )
surface.SetDrawColor(75,75,75,180)
surface.DrawRect(0,0,w,h)
end
itemlist.VBar.btnDown.Paint = function( s, w, h )
surface.SetDrawColor(75,75,75,180)
surface.DrawRect(0,0,w,h)
end
itemlist.VBar.btnGrip.Paint = function( s, w, h )
surface.SetDrawColor(75,75,75,180)
surface.DrawRect(0,0,w,h)
end
local inventory = inventoryTableCheck()
local function inventoryItems()
for k, v in pairs(inventory) do
local i = getItems(k)
if i then
local b = InventoryPanel(k, i.name, v.amount, i.desc, i.model, itemlist)
itemlist:AddItem(b)
end
end
end
inventoryItems()
end
end)[/CODE]
Change the 5 to how much space you want between each panel list and add it under your DPanelList itemlist
itemlist:SetSpacing( 5 ) -- Space between each item
and here's the server side.
[CODE]util.AddNetworkString("senddata")
util.AddNetworkString("openinventory")
util.AddNetworkString("pickup")
util.AddNetworkString("use")
util.AddNetworkString("drop")
local ply = FindMetaTable("Player")
function ply:inventoryDefault()
local i = {}
i["m1911"] = {amount = 1}
i["browninghp"] = {amount = 0}
i["po8lugar"] = {amount = 0}
i["tokarevtt33"] = {amount = 1}
i["waltherp38"] = {amount = 0}
i["waltherppk"] = {amount = 0}
i["mauserc96"] = {amount = 0}
i["thompson1921a1"] = {amount = 0}
i["thompson1944a1"] = {amount = 0}
i["thompsonm1a1"] = {amount = 0}
i["mp40"] = {amount = 1}
i["stennemk3"] = {amount = 0}
i["m3gg"] = {amount = 1}
self:inventorySetValue("inventory", i)
end
function ply:inventoryFolders()
return "ww2/inventory/"
end
function ply:inventoryPath()
return self:inventoryFolders() .. self:UniqueID() .. ".txt"
end
function ply:inventorySet( tab )
self.inventory = tab
end
function ply:inventoryGet()
return self.inventory
end
function ply:inventoryCheck()
self.inventory = {}
local f = self:inventoryExists()
if f then
self:inventoryRead()
else
self:inventoryCreate()
end
self:inventorySend()
end
function ply:inventorySend()
net.Start("senddata")
net.WriteTable(self:inventoryGet())
net.Send(self)
end
function ply:inventoryExists()
local f = file.Exists(self:inventoryPath(),"DATA")
return f
end
function ply:inventoryRead()
local str = file.Read(self:inventoryPath(),"DATA")
self:inventorySet(util.KeyValuesToTable(str))
end
function ply:inventorySave()
local str = util.TableToKeyValues(self.inventory)
local f = file.Write(self:inventoryPath(), str)
self:inventorySend()
end
function ply:inventoryCreate()
self:inventoryDefault()
local b = file.CreateDir(self:inventoryFolders())
self:inventorySave()
end
function ply:inventoryDisconnect()
self:inventorySave()
end
function ply:inventorySetValue(name,v)
if not v then return end
if type(v) == "table" then
if name == "inventory" then
for k,b in pairs(v) do
if b.amount <= 0 then
v[k] = nil
end
end
end
end
local d = self:inventoryGet()
d[name] = v
self:inventorySave()
end
function ply:inventoryGetValue(name)
local d = self:inventoryGet()
return d[name]
end
function ply:inventorySaveInv(i)
if not i then return end
self:inventorySetValue("inventory", i)
end
function ply:inventoryGetInv()
local i = self:inventoryGetValue( "inventory" )
return i
end
function ply:inventoryHasItem(name,amount)
if not amount then amount = 1 end
local i = self:inventoryGetInv()
if i then
if i[name] then
if i[name].amount >= amount then
return true
else
return false
end
else
return false
end
else
return false
end
end
function ply:inventoryTakeItem(name,amount)
if not amount then amount = 1 end
local i = self:inventoryGetInv()
if self:inventoryHasItem(name,amount) then
i[name].amount = i[name].amount - amount
self:inventorySaveInv(i)
return true
else
return false
end
end
function ply:inventoryGiveItem(name,amount)
if not amount then amount = 1 end
local i = self:inventoryGetInv()
local item = getItems(name)
if not item then return end
if amount == 1 then
self:ChatPrint("Added " .. item.name .. " to your inventory.")
elseif amount > 1 then
self:ChatPrint("Added " .. amount .. "" .. item.name .. " to your inventory.")
end
if self:inventoryHasItem(name,amount) then
i[name].amount = i[name].amount + amount
else
i[name] = {amount = amount}
end
self:inventorySave()
end
net.Receive("drop",function(len,ply)
local name = net.ReadString()
if ply:inventoryHasItem(name,1) then
ply:inventoryTakeItem(name,1)
CreateItem(ply,name,itemSpawnPos(ply))
end
end)
net.Receive("use",function(len,ply)
local name = net.ReadString()
local item = getItems(name)
if item then
if ply:inventoryHasItem(name,1) then
ply:inventoryTakeItem(name,1)
item.use(ply)
end
end
end)
local idd = 0
function CreateItem(ply,name,pos)
local itemT = getItems(name)
if itemT then
idd = idd + 1
local item = ents.Create(itemT.ent)
item:SetNWString("name",itemT.name)
item:SetNWString("itemName",name)
item:SetNWInt("uID",idd)
item:SetNWBool("pickup",true)
item:SetPos(pos)
item:SetNWEntity("owner",ply)
item:SetSkin(itemT.skin or 0)
itemT.drop(ply,item)
item:Spawn()
item:Activate()
else
return false
end
end
function itemSpawnPos(ply)
local pos = ply:GetShootPos()
local ang = ply:GetAimVector()
local td = {}
td.start = pos
td.endpos = pos+(ang*80)
local trace = util.TraceLine(td)
return trace.HitPos
end
net.Receive("pickup",function(len,ply)
local trace = {}
trace.start = ply:EyePos()
trace.endpos = trace.start + ply:GetAimVector() * 85
trace.filter = ply
local tr = util.TraceLine(trace)
if (tr.HitWorld) then return end
if !tr.Entity:IsValid() then return end
if tr.Entity:GetNWBool("pickup") then
local item = getItems(tr.Entity:GetNWString("itemName"))
if tr.Entity:GetNWBool("pickup") == nil then
ply:inventoryGiveItem(tr.Entity:GetNWString("itemName"),1)
tr.Entity:Remove()
else
if tr.Entity:GetNWBool("pickup") then
ply:inventoryGiveItem(tr.Entity:GetNWString("itemName"),1)
tr.Entity:Remove()
end
end
end
ply:inventorySave()
end)
[/CODE]
[editline]19th May 2016[/editline]
[QUOTE=Unknown Gamer;50351437]Change the 5 to how much space you want between each panel list and add it under your DPanelList itemlist
itemlist:SetSpacing( 5 ) -- Space between each item[/QUOTE]
Didn't work.
In your code:
[code]
local function inventoryItems()
for k, v in pairs(inventory) do
local i = getItems(k)
if i then
local b = InventoryPanel(k, i.name, v.amount, i.desc, i.model, itemlist)
itemlist:AddItem(b)
end
end
end[/code]
The function InventoryPanel never returns any panels.
Either call itemlist:AddItem() from InventoryPanel, or make InventoryPanel return a value.
[QUOTE=Robotboy655;50351507]In your code:
[code]
local function inventoryItems()
for k, v in pairs(inventory) do
local i = getItems(k)
if i then
local b = InventoryPanel(k, i.name, v.amount, i.desc, i.model, itemlist)
itemlist:AddItem(b)
end
end
end[/code]
The function InventoryPanel never returns any panels.
Either call itemlist:AddItem() from InventoryPanel, or make InventoryPanel return a value.[/QUOTE]
Awesome it worked, thanks for the help.
Sorry, you need to Log In to post a reply to this thread.