I'm trying to make a remove item function and this is what I came up with, but it confuses me because I set 4 items, sword,hammer, thunder , timeless dagger.
function inventory:remove(id)
table.remove(inventory, id)
End
I'm getting confused because when u remove an item I'd of 4 and u Print out inventory[2]
My item still gives an I'd of 4 I'm confused. Is there a proper way to remove an item, am I doing it wrong ?
Inventory and equipment inventory help
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Inventory and equipment inventory help
Sry to double post I'm on my iPod , I think I explained it badly.
inventory:set(1,"sword")
inventory:set(2, "hammer")
inventory:set (3, "thunder ")
inventory:set(4, "timeless")
k this is an example in my real code I have 2 more perimeters. K I don't know if this is a problem but ,
inventory:remove(3)
inventory:remove(2)
k so the inventory item that's id wud become
inventory[2]
is this supposed to happen
inventory:set(1,"sword")
inventory:set(2, "hammer")
inventory:set (3, "thunder ")
inventory:set(4, "timeless")
k this is an example in my real code I have 2 more perimeters. K I don't know if this is a problem but ,
inventory:remove(3)
inventory:remove(2)
k so the inventory item that's id wud become
inventory[2]
is this supposed to happen
Re: Inventory and equipment inventory help
In the original code I posted, the inventory object was supposed to be the tangible set of items the player is currently carrying. The actual item classes should probably be defined seperately. For instance:
And then modify the inventory View to write item[id].name rather than the id directly.
Code: Select all
item = {}
item[1] = {
name = "Potion"
}
Re: Inventory and equipment inventory help
K I understood what u just typed so I have 3 items identified now how do I do the actual inventory system
- Jasoco
- Inner party member
- Posts: 3726
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Inventory and equipment inventory help
The way I would do an inventory system is to have a table with every item available all numbered with an ID that holds all the information about them like what their name is, what happens when you use it, how many times it can be used before it is gone, what happens when it's gone, etc...
Note: It would be best to have a separate table for inventory and for equipment for simplicities sake.
Then you have to decide which system to use. Type A) A list of every item you have as you pick them up, or B) a solid list of every item available with flags for whether or not you have it, and how many you have.
Examples of use are Type A is used in EarthBound or DragonQuest while Type B is used in classic Final Fantasy games.
So baslcally a player's inventory list would look something like this:
Type A:
As it would just list every item you have. You'd set an arbitrary item count limit.
But I prefer Type B:
In this example, the player doesn't have any of "bombs". But has 5 of "health" and 2 of "macguffins".
To display this on screen you would loop through the player.inventory table in both examples, but with Type A:
Simply list each item, let the player select them, then when used up completely you would simply remove that item from the table. This method lets you have items with multiple uses, like a health potion that has 2 uses before it's gone.
With Type B:
Run through the table and list only items that have a count greater than 0.
When displaying information about the item, or using the item, you'd look up the item in the inventoryList table by using the ID.
Equipment/armor/weapon would be similar. But more complicated. Your player might have flags for different parts of the body that can be protected, head, torso, hands, legs, feet... And flags for what weapon(s) are equipped. Then your equipment list might be a Type A so you can have a helmet, et al, that can have a damage percentage that will make it disappear when it reaches 0. Then just handle removing (unequipping) it from the part of the body it goes on. If you don't want armor taking damage, you can use Type B instead and let the player pick up and stack multiple copies of that armor/weapon for selling. Just make sure to either prevent the last one of that type from being sold if it's equipped in either case. Personally in this case I'd go with Type A. Just list every single one and have a flag for equipped true or false.
Of course you'd need to suit it to fit your needs for your game. It all depends on the style you use.
Displaying this on screen is up to you. You can have a simple text list of your items or use icons. It depends on if you want to draw icons for everything or not. DQ/EB used text as did FF, but FF also had genre icons rather than icons for every single item. Mario RPG also did this.
Games like MineCraft use a hybrid of Type A and B where some items can't be stacked normally. Zelda also uses a hybrid. Especially for items like the Bottle which has a few states. Whether it's empty or full. What it's full of. And how many times that liquid/object can be used before it becomes empty again. Zelda's is more like, here's every item you can have. Here's a flag that says whether you found it or not. Here's a flag depending on the type that says whether it's full or not. Whether it has 1 or 2 uses left or is empty. What's in it. For things like arrows, that's a bit different in that they're not the same inventory, but a separate count. Arrows can only be used when you have the Bow item. Bombs are a hybrid where the bomb is an item you pick up, doesn't get completely removed when you are out, but has a count.
Code: Select all
inventoryItem = {
[1] = { name = "Health Potion", type = "heal", uses = 1, health = 10, where = "anywhere" },
[2] = { name = "Bomb", type = "hurt", uses = 1, damage = 5, where = "battle" },
[3] = { name = "Book", type = "macguffin", where = "game" }
}
Then you have to decide which system to use. Type A) A list of every item you have as you pick them up, or B) a solid list of every item available with flags for whether or not you have it, and how many you have.
Examples of use are Type A is used in EarthBound or DragonQuest while Type B is used in classic Final Fantasy games.
So baslcally a player's inventory list would look something like this:
Type A:
Code: Select all
player.inventory = {
{ id = 1, uses = 1 },
{ id = 1, uses = 1 },
{ id = 1, uses = 1 },
{ id = 3, uses = 1 },
{ id = 2, uses = 1 },
{ id = 1, uses = 1 },
{ id = 1, uses = 1 },
{ id = 2, uses = 1 },
{ id = 3, uses = 1 },
{ id = 1, uses = 1 }
}
But I prefer Type B:
Code: Select all
player.inventory = {
[1] = { count = 5 },
[2] = { count = 0 },
[3] = { count = 2 }
}
To display this on screen you would loop through the player.inventory table in both examples, but with Type A:
Simply list each item, let the player select them, then when used up completely you would simply remove that item from the table. This method lets you have items with multiple uses, like a health potion that has 2 uses before it's gone.
With Type B:
Run through the table and list only items that have a count greater than 0.
When displaying information about the item, or using the item, you'd look up the item in the inventoryList table by using the ID.
Equipment/armor/weapon would be similar. But more complicated. Your player might have flags for different parts of the body that can be protected, head, torso, hands, legs, feet... And flags for what weapon(s) are equipped. Then your equipment list might be a Type A so you can have a helmet, et al, that can have a damage percentage that will make it disappear when it reaches 0. Then just handle removing (unequipping) it from the part of the body it goes on. If you don't want armor taking damage, you can use Type B instead and let the player pick up and stack multiple copies of that armor/weapon for selling. Just make sure to either prevent the last one of that type from being sold if it's equipped in either case. Personally in this case I'd go with Type A. Just list every single one and have a flag for equipped true or false.
Of course you'd need to suit it to fit your needs for your game. It all depends on the style you use.
Displaying this on screen is up to you. You can have a simple text list of your items or use icons. It depends on if you want to draw icons for everything or not. DQ/EB used text as did FF, but FF also had genre icons rather than icons for every single item. Mario RPG also did this.
Games like MineCraft use a hybrid of Type A and B where some items can't be stacked normally. Zelda also uses a hybrid. Especially for items like the Bottle which has a few states. Whether it's empty or full. What it's full of. And how many times that liquid/object can be used before it becomes empty again. Zelda's is more like, here's every item you can have. Here's a flag that says whether you found it or not. Here's a flag depending on the type that says whether it's full or not. Whether it has 1 or 2 uses left or is empty. What's in it. For things like arrows, that's a bit different in that they're not the same inventory, but a separate count. Arrows can only be used when you have the Bow item. Bombs are a hybrid where the bomb is an item you pick up, doesn't get completely removed when you are out, but has a count.
Re: Inventory and equipment inventory help
Thanks a lot, I heard there's a big rpg game made called steam something, is it done yet and are we aloud to play
Re: Inventory and equipment inventory help
...Allowed?coke905 wrote:aloud
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: Inventory and equipment inventory help
I really don't think you should develop an MMORPG, or an RPG for that matter with the amount of skill you have thus far. I'm sorry to say but I can almost assure you the project will fall by the wayside. Try something more simple, get into the logics of it. Create code, don't copy code. You gotta learn, coding isn't fitting bits and pieces of someone else's code together.
We're more than willing to help you, but we aren't completely dedicated to your cause. I'm sorry but I don't think anyone is going to make a video or write a tutorial specifically for you, thats asking a lot.
We're more than willing to help you, but we aren't completely dedicated to your cause. I'm sorry but I don't think anyone is going to make a video or write a tutorial specifically for you, thats asking a lot.
Who is online
Users browsing this forum: Ahrefs [Bot] and 1 guest