A little LUA help, maybe
Posted: Wed Mar 04, 2015 2:51 pm
Nothing related to Vanguard, but I am trying to get a plug-in working for a Rust server. I can't seem to figure out how or if it can be fixed. What is occurring is the equipment "Packs" are not equipping and coming back with an error that reads "Deathmatch: Error while giving [item name]: [item name] is not a valid item name."
I have attached the original LUA file to this post in hopes someone can figure out why it is returning the value. Here is some of the code in question:
Any help when someone has some spare time would be greatly appreciated.
I have attached the original LUA file to this post in hopes someone can figure out why it is returning the value. Here is some of the code in question:
Code: Select all
local packData = self.Config.Packs[packNum]
-- Equip player with armor
if (packData.armor) then
for i = 1, #packData.armor do
str = packData.armor[i]
giveitem, err = self:GiveItem(player.inventory,str,1,"wear")
if(not giveitem) then print("Deathmatch: Error while giving " .. str .. ": " .. err) end
end
end
-- Equip player with items in their backpack
if (packData.backpack) then
for i = 1, #packData.backpack do
if (packData.backpack[i][2]) then
giveitem, err = self:GiveItem(player.inventory,packData.backpack[i][1],packData.backpack[i][2],"main")
if(not giveitem) then print("Deathmatch: Error while giving " .. packData.backpack[i][1] .. ": " .. err) end
else
giveitem, err = self:GiveItem(player.inventory,packData.backpack[i][1],1,"main")
if(not giveitem) then print("Deathmatch: Error while giving " .. packData.backpack[i][1] .. ": " .. err) end
end
end
end
-- Equip player with items on their belt
if (packData.belt) then
for i = 1, #packData.belt do
if (packData.belt[i][2]) then
giveitem, err = self:GiveItem(player.inventory,packData.belt[i][1],packData.belt[i][2],"belt")
if(not giveitem) then print("Deathmatch: Error while giving " .. packData.belt[i][1] .. ": " .. err) end
else
giveitem, err = self:GiveItem(player.inventory,packData.belt[i][1],1,"belt")
if(not giveitem) then print("Deathmatch: Error while giving " .. packData.belt[i][1] .. ": " .. err) end
end
end
end
end
Code: Select all
function PLUGIN:GiveItem(inv,name,amount,type)
local itemname = false
name = string.lower(name)
if(Table[name]) then
itemname = Table[name]
else
itemname = name
end
if(tonumber(amount) == nil) then
return false, "amount is not valid"
end
local container
if(type == "belt") then
container = inv.containerBelt
elseif(type == "main") then
container = inv.containerMain
elseif(type == "wear") then
container = inv.containerWear
else
return false, "wrong type: belt, main or wear"
end
local giveitem = global.ItemManager.CreateByName(itemname,amount)
if(not giveitem) then
return false, itemname .. " is not a valid item name"
end
inv:GiveItem(giveitem,container);
return giveitem
end
Code: Select all
self.Config.Packs =
{
{belt = {{"Thompson"},{"Medical Syringe", 1}}, armor = {"Hazmat Boots", "Hazmat Jacket", "Hazmat Gloves", "Hazmat Pants"}, backpack = {{"Pistol Bullet", 250}}},
{belt = {{"Thompson"},{"Medical Syringe", 1}}, armor = {"Hazmat Boots", "Hazmat Jacket", "Hazmat Gloves", "Hazmat Pants"}, backpack = {{"Pistol Bullet", 250}}}
}