Okay so im completely lost on this part of my code. Im fairly new to gmod lua and i would like for some pointers.
Where the file is located
gamemodes/darkrp/gamemode/modules/inventory
the Error
[CODE]
[ERROR] gamemodes/darkrp/gamemode/modules/noc_inventory/sh_items.lua:9: attempt to index a nil value
1. Create - gamemodes/darkrp/gamemode/modules/noc_inventory/sh_items.lua:9
2. unknown - gamemodes/darkrp/gamemode/modules/noc_inventory/sv_invinit.lua:84
3. include - [C]:-1
4. unknown - gamemodes/darkrp/gamemode/init.lua:65
[/CODE]
sh_items.lua
[CODE]
Item = {"Cake"}
Item.Saved = {}
function Item:Create(Nick, iname, iinfo, imodel, iuse, idrop, iweight, ilimit, idist)
self.Saved[Nick].Name = iname
self.Saved[Nick].Info = iinfo
self.Saved[Nick].Model = imodel
self.Saved[Nick].CanUse = iuse
self.Saved[Nick].CanDrop = idrop
self.Saved[Nick].Weight = iweight
self.Saved[Nick].Limit = ilimit
self.Saved[Nick].Dist = idist
if(SERVER) then
self[Nick].CanUse = iuse or function(ply) end
self[Nick].CanDrop = idrop or function(ply) end
print("[Inventory] - Created item : "..iname)
end
end
--[[
function Item:Register(unique, Itable)
tb = self.Saved
self[unique].Name = Itable.Name or ""
self[unique].Info = Itable.Info or ""
self[unique].Model = Itable.Model or ""
self[unique].CanUse = Itable.CanUse or 1
self[unique].CanDrop = Itable.CanDrop or 1
self[unique].Weight = Itable.Weight or 1
self[unique].Limit = Itable.Limit or 2147483647
self[unique].dist = Itable.dist or 1.2
if(SERVER)then
self[unique].CanUse = Itable.CanUse or function( ply ) end
self[unique].CanDrop = Itable.CanDrop or function( ply ) end
print("[sInventory] - Registered "..Itable.Name)
end
end
local fol = GM.FolderName.."/gamemode/items/"
local files, folders = file.Find(fol.."*","LUA")
print("[Inventory] Items: ",files,#files)
print("[Inventory] Folders: ",folders,#folders)
print("[Inventory] Path: ",fol)
for k, v in pairs( files ) do
include(fol .. v)
print("FILE ",v)
if (SERVER) then
AddCSLuaFile(fol .. v)
end
end]]--
function Item:Retrieve( item )
if(table.HasValue(Item, item)) then
return item
else
print("[sInventory] Item : " ..item.. " does not exist or could not be retrieved!")
end
end
[/CODE]
sv_invinit.lua
[CODE]
print("##############################################################")
print("##############################################################")
print("##############################################################")
print()
print()
print("Hello There, ive initalized :D")
print()
print("I am the inventory!")
print()
print("I was made by ProfessorSpace.")
print()
print()
print("##############################################################")
print("##############################################################")
print("##############################################################")
local meta = FindMetaTable("Player")
function Shared( fl )
Server( fl )
Client( fl )
end
function Server( fl )
if not SERVER then return end
include( fl )
end
function Client( fl )
if SERVER then
AddCSLuaFile( fl )
elseif CLIENT then
include( fl )
end
end
Shared("sh_items.lua")
Shared("sh_invshared.lua")
function SpawnLog(text)
if(file.Exists("Inventory/SpawnLog.txt",".txt","DATA")) then
file.Append("Inventory/SpawnLog.txt",text)
elseif(!file.Exists("Inventory/SpawnLog.txt",".txt","DATA")) then
file.CreateDir("Inventory")
file.Write("Inventory/SpawnLog.txt",text)
end
end
function meta:Spawn(item)
if(table.HasValue(Item, item)) then
local tr = self:EyeTrace(100)
local entItem = ents.Create("i_item")
entItem:SetPos(tr.HitPos)
entItem.Unique = item
entItem:Spawn()
end
end
concommand.Add("item_spawn", function( ply, cmd, args )
local item = args[1] or ""
if( ply:SteamID() == "STEAM_0:1:24445839" or ply:SteamID() == "STEAM_0:0:0") then
if(table.HasValue(Item, item)) then
ply:ChatPrint( "Spawned item: "..item..", This has been logged!" )
ply:Spawn( item )
SpawnLog("=================== START OF LOG ========================")
SpawnLog(ply:Nick().." - ["..ply:SteamID().."] spawned item: "..item)
SpawnLog("==================== END OF LOG =========================")
elseif(!table.HasValue(Item, item)) then
ply:ChatPrint( "There is no item Registered as: "..item )
end
else
ply:ChatPrint("Sorry you do not have access to this command, This has been logged!")
SpawnLog("=================== START OF LOG ========================")
SpawnLog(ply:Nick().." - ["..ply:SteamID().."] attempted to spawn: "..item)
SpawnLog("==================== END OF LOG =========================")
end
end)
Item:Create("test","Test Item","This was created as a test","models/props_c17/canister02a.mdl",0,0,1,1,1.2)
[/CODE]
init.lua
[CODE]
GM.Version = "2.5.1"
GM.Name = "DarkRP"
GM.Author = "By Rickster, Updated: Pcwizdan, Sibre, philxyz, [GNC] Matt, Chrome Bolt, FPtje Falco, Eusion, Drakehawke"
DeriveGamemode("sandbox")
AddCSLuaFile("libraries/simplerr.lua")
AddCSLuaFile("libraries/interfaceloader.lua")
AddCSLuaFile("libraries/modificationloader.lua")
AddCSLuaFile("libraries/disjointset.lua")
AddCSLuaFile("libraries/fn.lua")
AddCSLuaFile("config/config.lua")
AddCSLuaFile("config/addentities.lua")
AddCSLuaFile("config/jobrelated.lua")
AddCSLuaFile("config/ammotypes.lua")
AddCSLuaFile("cl_init.lua")
GM.Config = GM.Config or {}
GM.NoLicense = GM.NoLicense or {}
include("libraries/interfaceloader.lua")
include("config/_MySQL.lua")
include("config/config.lua")
include("config/licenseweapons.lua")
include("libraries/fn.lua")
include("libraries/simplerr.lua")
include("libraries/modificationloader.lua")
include("libraries/mysqlite/mysqlite.lua")
include("libraries/disjointset.lua")
/*---------------------------------------------------------------------------
Loading modules
---------------------------------------------------------------------------*/
local fol = GM.FolderName.."/gamemode/modules/"
local files, folders = file.Find(fol .. "*", "LUA")
for k,v in pairs(files) do
if DarkRP.disabledDefaults["modules"][v:Left(-5)] then continue end
if string.GetExtensionFromFilename(v) ~= "lua" then continue end
include(fol .. v)
end
for _, folder in SortedPairs(folders, true) do
if folder == "." or folder == ".." or DarkRP.disabledDefaults["modules"][folder] then continue end
for _, File in SortedPairs(file.Find(fol .. folder .."/sh_*.lua", "LUA"), true) do
AddCSLuaFile(fol..folder .. "/" ..File)
if File == "sh_interface.lua" then continue end
include(fol.. folder .. "/" ..File)
end
for _, File in SortedPairs(file.Find(fol .. folder .."/sv_*.lua", "LUA"), true) do
if File == "sv_interface.lua" then continue end
include(fol.. folder .. "/" ..File)
end
for _, File in SortedPairs(file.Find(fol .. folder .."/cl_*.lua", "LUA"), true) do
if File == "cl_interface.lua" then continue end
AddCSLuaFile(fol.. folder .. "/" ..File)
end
end
MySQLite.initialize()
DarkRP.DARKRP_LOADING = true
include("config/jobrelated.lua")
include("config/addentities.lua")
include("config/ammotypes.lua")
DarkRP.DARKRP_LOADING = nil
DarkRP.finish()
[/CODE]
[CODE]function Item:Create(Nick, iname, iinfo, imodel, iuse, idrop, iweight, ilimit, idist)
if (not self.Saved[Nick]) then self.Saved[Nick] = {} end
self.Saved[Nick].Name = iname
self.Saved[Nick].Info = iinfo
self.Saved[Nick].Model = imodel
self.Saved[Nick].CanUse = iuse
self.Saved[Nick].CanDrop = idrop
self.Saved[Nick].Weight = iweight
self.Saved[Nick].Limit = ilimit
self.Saved[Nick].Dist = idist
if(SERVER) then
self[Nick].CanUse = iuse or function(ply) end
self[Nick].CanDrop = idrop or function(ply) end
print("[Inventory] - Created item : "..iname)
end
end[/CODE]
That should fix that error. The reason why the error happened is literally because of what it says. You are trying to index a nonexistent value.
The nonexistent value was whatever "Nick" was referenced to. Also a tip, I'm not sure if this inventory is saving items by a nickname of some sort, but I recommend using a ID.
[QUOTE=Maravis;48764258][CODE]function Item:Create(Nick, iname, iinfo, imodel, iuse, idrop, iweight, ilimit, idist)
if (not self.Saved[Nick]) then self.Saved[Nick] = {} end
self.Saved[Nick].Name = iname
self.Saved[Nick].Info = iinfo
self.Saved[Nick].Model = imodel
self.Saved[Nick].CanUse = iuse
self.Saved[Nick].CanDrop = idrop
self.Saved[Nick].Weight = iweight
self.Saved[Nick].Limit = ilimit
self.Saved[Nick].Dist = idist
if(SERVER) then
self[Nick].CanUse = iuse or function(ply) end
self[Nick].CanDrop = idrop or function(ply) end
print("[Inventory] - Created item : "..iname)
end
end[/CODE]
That should fix that error. The reason why the error happened is literally because of what it says. You are trying to index a nonexistent value.
The nonexistent value was whatever "Nick" was referenced to. Also a tip, I'm not sure if this inventory is saving items by a nickname of some sort, but I recommend using a ID.[/QUOTE]
I have quite got to saving the inventorys right now im working on getting them to register the items and spawn them into the world
but when i get to saving the inventorys im going to use their steamid's and probally filewrite because i have no idea how to save using mysql
By an ID I meant an integer value key, so just in case strings don't catch the same names.
Whatever works for your server man, but if you ever plan on synchronizing data across multiple platforms or servers you should really give MySQL a try.
There are plenty of resources to use on the internet if you want to learn. Google is your friend.
[QUOTE=Maravis;48764291]By an ID I meant an integer value key, so just in case strings don't catch the same names.
Whatever works for your server man, but if you ever plan on synchronizing data across multiple platforms or servers you should really give MySQL a try.
There are plenty of resources to use on the internet if you want to learn. Google is your friend.[/QUOTE]
I figured i could use google, ive learned what i know mostly from the wiki. Ahh yes the wiki ive spent many hours there! lol
anyways Do you mean
instead of
[CODE]
self.Saved[Nick]
[/CODE]
i do
[CODE]
self.Saved[Id]
[/CODE]
?
[QUOTE=DiscoKnight;48764301]I figured i could use google, ive learned what i know mostly from the wiki. Ahh yes the wiki ive spent many hours there! lol
anyways Do you mean
instead of
[CODE]
self.Saved[Nick]
[/CODE]
i do
[CODE]
self.Saved[Id]
[/CODE]
?[/QUOTE]
No, not like that. That is just a variable name. You wrote the code right? I'm assuming the variable Nick as the parameter you're passing in is a type string.
I'm just recommending it be a type integer. Your choice of course.
[QUOTE=Maravis;48764313]No, not like that. That is just a variable name. You wrote the code right? I'm assuming the variable Nick as the parameter you're passing in is a type string.
I'm just recommending it be a type integer. Your choice of course.[/QUOTE]
Yea it is, i might try using integers but right now the spawn item command relies on strings. ill later invest on swapping it over but for now "item_spawn test" looks decent for me... -snip-
-edit-
Apparently it doesnt know that the item in there is being saved. at first i didnt think it was saving at all but now i realized the spawn command isnt thinking it was saved
[CODE]
for item, _ in pairs( Item.Saved ) do
print(item)
end
[/CODE]
that tells me the spawn id name, so i know its being saved but
[CODE]
concommand.Add("item_spawn", function( ply, cmd, args )
local item = args[1] or ""
if( ply:SteamID() == "STEAM_0:1:24445839" or ply:SteamID() == "STEAM_0:0:0") then
if(table.HasValue(Item.Saved, item)) then
ply:ChatPrint( "Spawned item: "..item..", This has been logged!" )
ply:Spawn( item )
SpawnLog("=================== START OF LOG ========================")
SpawnLog(ply:Nick().." - ["..ply:SteamID().."] spawned item: "..item)
SpawnLog("==================== END OF LOG =========================")
elseif(!table.HasValue(Item, item)) then
ply:ChatPrint( "There is no item Registered as: "..item )
end
else
ply:ChatPrint("Sorry you do not have access to this command, This has been logged!")
SpawnLog("=================== START OF LOG ========================")
SpawnLog(ply:Nick().." - ["..ply:SteamID().."] attempted to spawn: "..item)
SpawnLog("==================== END OF LOG =========================")
end
end)
[/CODE]
is shooting back that item doesnt exist
Sorry, you need to Log In to post a reply to this thread.