Anyone who has experience with GMod gamemode creation…
I was recently trying to create a code for an inventory. My gamemode is called trollbox.
> trollbox/entities/autorun
inv_base
local player = LocalPlayer()
player.Inventory = {}
function GenerateInventory() -- Create a 2D array (4x10) called Inventory. In every cell, create a slot.
for i = 1, 4
do
player.Inventory[i] = {}
for j = 1, 10
do
player.Inventory[i][j] = Slot:new(nil, false, nil, 0)
end
end
print("Inventory has been generated!")
end
hook.Add("PlayerSpawn", "GenerateInventory", GenerateInventory)
function InsertItemInInventory(item, amount)
for i = 1, 4
do
for j = 1, 10
do
if (player.Inventory[i][j].isStoring == false or player.Inventory[i][j].objectStored == item)
then
player.Inventory[i][j]:assignObject(item, amount)
break
end
end
end
end
inv_slot
-- Meta Class Slot
Slot = {isStoring = false, objectStored = nil, objectQty = 0}
-- Base Class method new
function Slot:new(o, isStoring, objectStored, objectQty)
o = o or {}
setmetatable(o, self)
self.__index = self
self.isStoring = isStoring or false
self.objectStored = objectStored or nil
self.objectQty = objectQty or 0
return o
end
-- Base Class method assignObject
function Slot:assignObject(objectString, objectAmount)
if (self.objectStored == nil) -- If not storing any object, then add x amount of said object
then
self.objectStored = objectString
self.objectQty = objectAmount
self.isStoring = true
elseif (self.objectStored == objectString) -- If storing the same object, then add the amount to current quantity
then
self.objectQty = self.objectQty + objectAmount
else -- If not storing the same object, then don't do anything
return
end
end
As you can see, inv_slot.lua contains a class called ‘Slot’. I’m trying to access it from inv_base.lua, but the code doesn’t seem to run whatsoever. What am I doing wrong?
Sorry if I’m asking here, but if I post on the GMod Steam forums, I fear I won’t get an answer.
Update: Okay, so it seems that I required to cut those files and paste their content in:
trollbox/gamemode/init.lua
Now, it works!
… or at least in theory.
@hhyyrylainen, just a question about speech synthesis, text to speech, etc. Do you know anything about dictionary databases? I mean, I heard that hackers find passwords by using words from dictionaries, so wouldn’t those speech software actually use dictionaries too? Isn’t there any such thing made in Lua?