One of the reasons I created a group for the game is so that I can just fill the group’s model inventory with items.
I wish to simplify things with coding(/admin commands) and just use the name
So instead of doing
_G.giveItem("dispeller",2528526639)
I can just do
_G.giveItem("dispeller","apple")
This is how I am currently doing it:
itemNameIDs = {
["apple"] = 2528526639,
["basic sword"] = 2547563854,
["flight potion"] = 2547734481,
}
--// function to get ID of item name
function findID(name)
for i,v in pairs(itemNameIDs) do
if string.find(i,string.lower(name)) then
return v
end
end
end
Is there an easier more automatic method than having to add something to this table every time a new item is added to the game?
One of the reasons I’m asking is because I might let a few friends add their own items to the game.
I don’t think there is an easier way, as you’ll need to put the IDs somewhere – the way you have now is pretty good anyway. My game’s item system is more complex than yours, and I think it is pretty good too, so I doubt you have much to worry about
If you were really feeling the need to share it with people, you could create a Google Spreadsheet to hold your item index then give it a web app and stuff. You could share it with your friends, and you could even have items update without a game server being restarted as where the actual updating happens is on the spreadsheet. This method sounds great, but it’ll be a lot of work and not worth it for a Roblox game IMO.
@EmeraldSlash
Yeah I thought about having a separate thing like that as well, but that would just be a pain.
I could just have a module instead of a spreadsheet if I wanted to do that.
@Fm_Trick
Actually, I have the loop so I can shorthand things when feeling lazy
so I could just be like
findID("app") -- returns 2528526639
Also, because I’m a lazy individual, I just have my admin commands be global with _G.
It’s actually pretty cool.
For an example, this is my giveGold command
_G.giveGold = function(p,a)
if type(a) == "number" then
p = findPlayer(p)
giveGold:Invoke(p,a)
print("Gave",p,a,"Gold")
else
warn("Can't give",a,"gold to",p"!")
print'Maybe you got the vars switched?'
end
end
So now, if I ever want to give gold to a player in game, I can just open up the dev console and type
True but the module wouldn’t be editable by your friends (unless it was in group models or something) whereas with your spreadsheet you could easily share and manage the index.