So im fairly new to Lua and to coding in general so please forgive my stupidity.
Anyways my plan was if someone presses a the given key than the server should take a Veste away from ur inventory and after than give u an animationen. This works just fine the problem is it still give u the animation and the armor even if u dont have a veste anymore and thats the point where i need help.
You need to store the player inventory in a list.
then you loop through and check if that list contains the item already.
I could be wrong anyone correct me if i am, im a C# coder lol
-- Client side implementation
local inventory = {'item1', 'item5', 'item 9'}
function hasItem(itemName)
for i, name in ipairs(names) do
if name == item then
return true
end
end
return false
end
if not hasItem("item5") then
table.insert(inventory, "item5")
end
If you want it to be server side
local playerInventories = {}
function createPlayer(playerHandle)
local player = {}
player.Handle = playerHandle
player.Inventory = {}
return player
end
function createItem(itemName)
local item = {}
item.name = itemName
return item
end
function getPlayerInventory(playerHandle)
for i, player in ipairs(playerInventories) do
if player.Handle == playerHandle then
return player.Inventory
end
end
end
function addItemToPlayerInventory(playerHandle, item)
table.insert(getPlayerInventory(playerHandle), item)
end
function hasPlayerItemInInventory(playerHandle, itemName)
for i, item in ipairs(getPlayerInventory(playerHandle)) do
if item.name == itemName then
return true
end
end
return false
end
...onPlayerConnecting
createPlayer(src)
...onPlayerPickupItem
local item = createItem("the item name")
if not hasPlayerItemInInventory(src, item) then
addItemToPlayerInventory(src, item)
end