generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: I need help making an inventory

Previous Thread :: Next Thread 
MrNooblyHere is not online. MrNooblyHere
Joined: 17 Nov 2013
Total Posts: 70
06 Oct 2014 01:09 PM
I am making a "DayZ Standalone" game and I need help making an iventory button.

I need a script that will open another gui and when it is clicked again(The inventory button it will close the inventory)

If you could help me with that thank you very much and if you cant thank you for taking the time to read this and have a great day!
Report Abuse
MrNooblyHere is not online. MrNooblyHere
Joined: 17 Nov 2013
Total Posts: 70
06 Oct 2014 01:13 PM
If you think you could and want a closer look or just what ik have done so far here you go.

http://www.roblox.com/DayZ-Standalone-Inventory-item?id=181186834
Report Abuse
MrNooblyHere is not online. MrNooblyHere
Joined: 17 Nov 2013
Total Posts: 70
06 Oct 2014 01:26 PM
Any advice?
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
06 Oct 2014 01:38 PM
The main script for deadzone was over 5,000 lines.


Inventories aren't even easy to script either.
Report Abuse
theGOLDENidol is not online. theGOLDENidol
Joined: 11 Apr 2011
Total Posts: 787
06 Oct 2014 01:54 PM
You do realize that open and close script, is one of the most basic scripts you can get right?
Report Abuse
theGOLDENidol is not online. theGOLDENidol
Joined: 11 Apr 2011
Total Posts: 787
06 Oct 2014 01:56 PM
But anyways here it is.

While true do
game.Lighting.Brightness = 10000
end
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
06 Oct 2014 02:07 PM
Inventory scripts are actually not too hard on a basic level.
Depends whether you want slots or weight, really. Here's my current inventory sort script, which should get you started on the logic for picking stuff up and what not

event.OnServerEvent:connect(function(p, item, amt, destroy, give, custom, cfunction)
print("Called")
if not custom then custom = false end
local pInv = p.Inventory
local success = false
local ni = 0
for i,v in ipairs(pInv:GetChildren()) do
if v:IsA("Model") then
if game.ReplicatedStorage.ItemTypes:FindFirstChild(give) == v.Type.Value then
if 60 + pInv.Ext.Value >= pInv.Weight.Value + v.Type.Value.Weight.Value then
v.Amt.Value = v.Amt.Value + amt
if destroy then
item:Destroy()
end
print("Placed in index "..i)
workspace.UpdateInventory:FireClient(p)
end
success = true
end
ni = i
end
end
if success == false then
if game.ReplicatedStorage.ItemTypes:FindFirstChild(give):FindFirstChild("Weight").Value + pInv.Weight.Value <= 60 + pInv.Ext.Value then
local v = Instance.new("Model", pInv)
v.Name = tostring(ni+1)
local namt = Instance.new("IntValue", v)
namt.Value = amt
namt.Name = "Amt"
local type = Instance.new("ObjectValue", v)
type.Value = game.ReplicatedStorage.ItemTypes:FindFirstChild(give)
type.Name = "Type"
if destroy then
item:Destroy()
end
workspace.UpdateInventory:FireClient(p)
end
end
end)

Has a lot of context specific stuff, so you won't be able to use it, but you'll get the idea...
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
06 Oct 2014 02:21 PM
My GUI Inventory script is exactly 295 lines long. I had to keep going back to fix bugs that I didn't know were there, after I thought I was already finished with it.
Report Abuse
DevFrank is not online. DevFrank
Joined: 04 Apr 2012
Total Posts: 1469
06 Oct 2014 02:29 PM
I have never made a inventory but I would make a Table and then make the script generate new icons and stuff.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
06 Oct 2014 02:36 PM
Just a little suggestion when dealing with inventories.
Keep the inventory DATA on the server. Only put the visuals on the client.

The release of RemoteEvents and RemoteFunctions really made inventory systems a lot easier. Learn how to use these ASAP. They are very useful!
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
06 Oct 2014 02:38 PM
My whole entire inventory functions with a local script, and I save ti with data persistence. I can't find it possible to deal with a 40 slot GUI menu inventory server side, and save it with data store.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
06 Oct 2014 02:40 PM
If you just use IDs for the items, it's super easy to save to DS, as you can save entire TABLES into DS.


local inv = {
Slot1 = { Qty = 10, ItemID = 1 },
Slot2 = { Qty = 0, ItemID = 0 },
Slot3 = { Qty = 0, ItemID = 0 },
Slot4 = { Qty = 0, ItemID = 0 },
Slot5 = { Qty = 0, ItemID = 0 },
Slot6 = { Qty = 0, ItemID = 0 },
Slot7 = { Qty = 0, ItemID = 0 },
Slot8 = { Qty = 0, ItemID = 0 }
}



Just an example. You can save the entire 'inv' table to DataStore.
Report Abuse
Subete is not online. Subete
Joined: 10 Jul 2011
Total Posts: 917
06 Oct 2014 02:46 PM
helpful agent is helpful. i'm actually working on an inventory as well now, and this was helpful.

offtopic: how do you index a keypress of "i"

since it controls zooming in..
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
06 Oct 2014 02:57 PM
Use KeyUp
Report Abuse
MrNooblyHere is not online. MrNooblyHere
Joined: 17 Nov 2013
Total Posts: 70
06 Oct 2014 03:05 PM
I still dont know how to open and close me Gui sorry :/
Report Abuse
MrNooblyHere is not online. MrNooblyHere
Joined: 17 Nov 2013
Total Posts: 70
06 Oct 2014 03:06 PM
Can someone take my gui and see if they can do it?
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
06 Oct 2014 03:09 PM
@Agent, my inventory has 40 slots, and each have the same instances, with the same exact names. I have no choice but to save and load with loops, which results in 240 requests ( 240 requests when saving, 240 requests when loading, 6 instances in each GUI slot).
Report Abuse
LegendaryAccount is not online. LegendaryAccount
Joined: 02 Jun 2010
Total Posts: 13193
06 Oct 2014 03:16 PM
Im sorry to say but if you can open or close a gui you should not be working on a inventory
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
06 Oct 2014 06:04 PM
"@Agent, my inventory has 40 slots, and each have the same instances, with the same exact names. I have no choice but to save and load with loops, which results in 240 requests ( 240 requests when saving, 240 requests when loading, 6 instances in each GUI slot)."

If you set up your inventory system for multiple lookup tables, you only need to send one request for loading and one request for saving.
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
06 Oct 2014 06:07 PM
No

I have to use loops to load. The only way to use one request to "load" data is to return the value, rather than set it.


Is UpdateAsync meant to be used with strings? This is what I have:


DataStore:UpdateAsync(key_5, function(otherValue)
otherValue = s_Table;
local new_Table = otherValue;
return new_Table;
end);
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
06 Oct 2014 06:19 PM
Use a basic formatting system for your inventory table
Honestly, it depends on whether your inventory size is fixed or dynamic

Fixed:
Inventory = {}
for i=1, maxinvsize do
Inventory[i].Amt = 0 -- Amount of item in slot
Inventory[i].Type = "DefaultType" -- In my inventory models, this refers to a base class in the serverstorage.ItemTypes
Inventory[i].Custom = false -- You can work out your own way of dealing with custom basetypes
end

Dynamic:
Inventory = {}
Inventory.Weight = player.Weight.Value
Inventory.Ext = player.Ext.Value -- For stuff like backpacks
Inventory.Inv = {}
local ni = 1
for i,v in ipairs(player.Inventory:GetChildren()) do
if v:IsA("Model") then
ni = ni+1
Inventory.Inv[ni] = {}
Inventory.Inv[ni].Amt = 0
Inventory.Inv[ni].Type = "BaseType"
Inventory.Inv[ni].Custom = false
end
end

Type refers to the name of a model in my serverstorage which tells the server and client all the info it has to know
Unpacking the dynamic model is just as easy as the slots model, since you can use #Inventory.Inv to find out how many items in the dynamic model, and you already know the max for the fixed model.
Report Abuse
Accomplishable is not online. Accomplishable
Joined: 13 Aug 2009
Total Posts: 6207
06 Oct 2014 07:01 PM
@e


This is what my inventory looks like. All of the functions are local:


prntscr

.

com

/

4tr8ok
Report Abuse
MrNooblyHere is not online. MrNooblyHere
Joined: 17 Nov 2013
Total Posts: 70
06 Oct 2014 07:55 PM
I found out how to Make an open and close gui thank you guys so much for all the support
Report Abuse
MrNooblyHere is not online. MrNooblyHere
Joined: 17 Nov 2013
Total Posts: 70
06 Oct 2014 07:55 PM
Accomplishable hopefully i can make one like you in the future that looks really good
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
06 Oct 2014 10:57 PM
"No

I have to use loops to load. The only way to use one request to "load" data is to return the value, rather than set it."


All you need is a table that has:

1 index per item slot.
Each item slot has an ItemID and a Quantity.


That's it.
Which means my example would be one request for saving and one request for loading.

Then, on the server, you could use some kind of lookup table (I would call this a service and use BindableFunctions) to generate the GUI elements for the inventory. These GUI elements don't need to be saved, because they are generated based on the previous data.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image