This completely depends on how you've made your F4 menu, in 99% of cases I'd say yes there's a way. Without code we can't give you a specific way however.
General idea
local menu = nil
local inventory = {}
local function RefreshMenu()
menu:Close()
menu = nil
timer.Simple(0.1, function() ToggleInventory() end)
end
local function DeleteItem()
net.Start("InvDelete")
net.WriteString(selection["name"])
net.SendToServer()
RefreshMenu()
end
local function DropItem(amount)
net.Start("InvDrop")
net.WriteString(selection["name"])
net.WriteInt(amount, 32)
net.SendToServer()
RefreshMenu()
end
-- Draw the items that the player possesses
local function ListInventory()
local x = 4
local y = 4
for k,v in pairs(inventory) do
if inventory[k]["amount"] > 0 then
-- Draw a button for each item found in the server-side list
end
end
end
-- Draw the menu
local function DrawInventory()
menu = vgui.Create("DFrame")
menu:SetSize(ScrW()/2,ScrH()/2)
menu:SetPos((ScrW()/2)-(menu:GetWide()/2),(ScrH()/2)-(menu:GetTall()/2))
menu:SetTitle("Inventory - Press F4 to Close")
menu:SetDraggable(false)
function menu:OnClose()
menu:SetVisible(false)
gui.EnableScreenClicker(false)
menu = nil
end
ListInventory()
end
function ToggleInventory()
if !IsValid(menu) then
DrawInventory()
gui.EnableScreenClicker(true)
else
if menu:IsVisible() then
menu:SetVisible(false)
gui.EnableScreenClicker(false)
menu = nil
else
menu:SetVisible(true)
gui.EnableScreenClicker(true)
end
end
end
-- Receive command to open menu
concommand.Add("opn_inventory", ToggleInventory)
net.Receive("InvAdd", function()
local iName = net.ReadString()
local iCount = net.ReadInt(32)
print("Received "..iCount.." "..iName)
local this_item = {}
this_item["name"] = iName
this_item["amount"] = iCount
PrintTable(this_item)
table.insert(inventory, this_item)
PrintTable(inventory)
end)
This doesn't really help as you haven't posted the button creation code. None the less the basic idea is just make your menu local to the file and not a function, then just add to it when you receive the info.
I took out all the button create because it was a bunch of drawing fluff, irrelevant to the situation at hand. If you need to know about the buttons, it's more or less a bunch of variable setting, and custom .Paint = function()
This is untrue, you simply remove or add the buttons to the panel.
According to RobotBoy, you cannot refresh Derma.
Adding/Removing the content wouldn't accomplish what I was looking for - They'd disappear and reappear. I just want it to be updated. (So when 2 items are removed from the inventory, 2 of the items would just disappear while the other X amount are unchanged).
Update Derma?
He said exactly what I said in that thread. Yes there's no magical function that will update your menu, this can't exist because there's a unlimited amount of ways to create a menu. The answer he gave was to delete all the icons and simply remake them, this wouldn't involve recreating the menu, just the icons.
You don't have to do that, you could just delete the icons of the removed items. There's times where this may not be suitable, but I imagine it is here. The reason I can't say for sure and the reason I can't post any code snippets for help is because you never posted the actual icon/button logic, just the menu creation.
i have a table with teams listed, it looks like
tbl = {
[1] = {stuff = "blah", team = TEAM_HOBO}
}
but on startup teams are nil, i suppose that happens because script is loaded before dark rp creates these teams, what can i do?
Creating it in this hook would probably suffice, GM/Initialize.
How do I create a global table similar to what authors use for configuring an addon? I want to be able to attach both methods and values to the table. Kinda like in the example below.
character.lua
CHAR = {}
CHAR.Name = "Placeholder"
function CHAR:SetupName()
if self.Name == "Placeholder"
return true
else
return false
end
Then in another file I can use something like this
anotherfile.lua
function CHAR:GetName()
return self.Name
end
print(CHAR:GetName())
I understand my example is a little redundant, but I only made it up as an example. I just want to be able to create a global table similar to the existing GM one, and allow myself to push and pull data from it in various different lua files. Thanks for any help.
That's exactly how you do it. The only thing you need to do is make sure the files are ran in the correct order so that the proper values exist for the next script that loads.
Okay, I think my problem is that it's not being loaded before other files. I'm using a for loop to include all the lua files in a specified directory so that makes sense.
Another question I have is if I store server-side globals and client-side globals inside the same file and use both include and addcsluafile, is that bad practice? I notice when I do this, it initializes all the variables and methods client-side too, which shouldn't matter since they can't communicate with the server-side equivalent, but it also doesn't seem optimal.
Can you get an entity by index or id? I see a function for player but not for a generic entity.
Entity or ents.GetByIndex, they do the same.
Wrap it in an if statement.
Instead of
SERVER_VARIABLE = ...
CLIENT_VARIABLE = ...
write
if SERVER then
SERVER_VARIABLE = ...
else
CLIENT_VARIABLE = ...
end
Then they are both inside the same file, but nothing is created in the improper realm.
Hey guys!
Trying to name the return value of this util.SpriteTrail, I cannot figure out how to name the return of the sprite trail.
Here's what I got so far:
spritetrail = util.SpriteTrail( ply:GetVehicle(), 3, Color(244, 134, 66), false, 25, 15, .2, 1/(15+1)*0.5, "trails/plasma.vmt")
timer.Simple(2, function()
spritetrail:Remove()
end)
This function works for the first time it's executed, but for the second and onward, it tells me that it cannot remove the entity because it is null. Any help would be appreciated!
Is there a way to stop the player moving their hand to the ear when you start chatting?
GM/GrabEarAnimation
How to make an entity collide with npcs' model hitboxes, not bounding box?
Its returning GetPData as a nil value, with this error
Now I get this [ERROR] lua/autorun/server/sv_init.lua:44: attempt to call method 'GetPData' (a nil value)
1. GetInv - lua/autorun/server/sv_init.lua:44
2. func - lua/autorun/server/sv_init.lua:65
3. unknown - lua/includes/extensions/net.lua:32
The lines the error is moaning about
[code]
function pMeta:GetInv(pl)
tableS = pl:GetPData("Inv")
return util.JSONToTable(tableS)
end
[/code]
Where its called from
[code]
hook.Add("PlayerSpawn", "OpenDerma", function(pl)
net.Start("PlayerSpawned");
print("Server Spawn");
net.WriteString(pMeta:GetInv(pl));
net.Send(pl);
pl:SetPos(Vector(-6335.488281, -7643.241699, 136.031250))
end);
[/code]
Is anybody else having abysmal problems with the SetGlobal* and GetGlobal* functions? Like they legit just refuse to work at all.
https://files.facepunch.com/forum/upload/111825/eb8087e6-df77-4fc6-aec5-deb753699bbb/whatthefuck.png
????????
Just ran this exactly with the intended result.
I just finished a gamemode I want to beta test, but I can't upload it to the workshop because of the "gamemode/myGamemode/myGamemode.txt" file, since txt files are banned from the workshop. However, this file is required for the gamemode to show up on the bottom right menu and more.
How do I get around this?
Maybe just put it on GitHub and share the link. This would be the easiest solutin I think.
structure it properly. mine worked, in gamemodes/sweptdm/sweptdm.txt. Note that gamemode is plural
Yeah, that was a typo sorry. Point being the Workshop does not allow you to upload .txt files, but it contains gamemode settings, and without it, it won't show up in the bottom-right gamemode selection menu... So I'm not sure how to get around needing this file.
I want to draw text that's really tiny. I want to fill the box in this image, but the text is that big white blur.
https://files.facepunch.com/forum/upload/107178/1a9a4ba5-f480-4344-841b-0139558e0867/c2a2h0000.jpg
How could I, inside a 3d2d environment, make really tiny text that's easy to read?
Two quick problems/questions.
First, on TTT Crummy Cradle, the map is rotating some props every few ticks and is spamming console.log. Is it possible to remove only this and only on the map?
[code]Entity [471][func_rotating]
Entity [471][func_rotating]
Entity [471][func_rotating]
Entity [471][func_rotating]
Entity [471][func_rotating]
Entity [471][func_rotating]
Entity [469][func_rotating]
Entity [471][func_rotating]
Entity [469][func_rotating]
Entity [469][func_rotating]
Entity [469][func_rotating]
Entity [469][func_rotating]
Entity [469][func_rotating]
Entity [469][func_rotating]
Entity [469][func_rotating]
[/code]
Second, we have modified karma.lua in TTT a bit to use Sourcebans instead of ULX to ban people. The issue being is that when they reconnect to the server after being banned initially it rebans them. I'm trying to figure out what's easiest; to reset their karma when they're initially banned or what?
Here is the code we're using:
[code]local reason = "Karma too low"
function KARMA.CheckAutoKick(ply)
if ply:GetBaseKarma() <= config.kicklevel:GetInt() then
if hook.Call("TTTKarmaLow", GAMEMODE, ply) == false then
return
end
ServerLog(ply:Nick() .. " autokicked/banned for low karma.\n")
-- flag player as autokicked so we don't perform the normal player
-- disconnect logic
ply.karma_kicked = true
if config.persist:GetBool() then
local k = math.Clamp(config.starting:GetFloat() * 0.8, config.kicklevel:GetFloat() * 1.1, config.max:GetFloat())
ply:SetPData("karma_stored", k)
KARMA.RememberedPlayers[ply:UniqueID()] = k
end
if config.autoban:GetBool() then
sourcebans.BanPlayerBySteamID( ply:SteamID(), 480*60, "Auto-Karma Ban")
ChatPrint(ply:Nick() .." was banned for low karma.")
ply:KickBan(config.bantime:GetInt(), reason)
else
ply:Kick(reason)
end
end
end
[/code]
We're using "Another ULX Source Bans Module".
You have to upload it in addon format.
For example my gamemode is assassins. It goes `assassins/gamemodes/assassins/assassins.txt`
Another image of my issue. I raised the font size to 8.
https://files.facepunch.com/forum/upload/107178/4e5e71d0-78af-4207-91a1-bc527a90b7e7/c2a2g0002.jpg
Idk if there's a way to thumbnail these images cus I hate posting such massive images on here.
Sorry, you need to Log In to post a reply to this thread.