creating a basic inventory is simple, the hard part is actually using the items.
the inventory;
player_inventory.lua
item_name = {}
PQ_item = {}
--adjusts location of player inventory on screen
local invx = 10
local invy = 8
local text_size = 3
local panel_width = 9 --adjusts the size of the panel behind the inventory screen (make is larger if you have long item names
local show_inv = 0 --set to 1 to show inventory on screen at start (otherwise press i to toggle it)
max_items = 9 --change if you want player to be able to hold more items
local inv_pressed = 0
function player_inventory_init(e)
--set up player's starting quantity of items (all items set to 0 for speed)
for a = 1, max_items do
PQ_item[a] = 0
end
--name all items here (must name them all or you will get errors)
item_name[1] = "Scrap Metal"
item_name[2] = "Paper"
item_name[3] = "Cloth"
item_name[4] = "Pencil"
item_name[5] = "Rubber Band"
item_name[6] = "Matchstick"
item_name[7] = "Broken Mirror Shard"
item_name[8] = "Spent Bullet Case"
item_name[9] = "Old Cheese"
end
function player_inventory_main(e)
if GetScancode() == 23 and inv_pressed == 0 then
inv_pressed = 1
if show_inv == 0 then
show_inv = 1
else
show_inv = 0
end
end
if show_inv == 1 then
local ix = invx
local iy = invy
Panel(ix - panel_width,iy - (text_size*2), ix + panel_width, iy + (text_size*max_items))
TextCenterOnX(ix,iy-text_size,text_size,"INVENTORY")
for a = 1, max_items do
TextCenterOnX(ix,iy,text_size,item_name[a].." x "..PQ_item[a])
iy = iy + text_size
end
end
if GetScancode() == 0 then
inv_pressed = 0
end
end
function player_inventory_exit(e)
end
and the code to find an item
loot.lua
--This Will give a Random amount of money, health, or what ever you
--want from entities with this script.
local looted = {}
local lootRange = {}
local loot_min = {}
local loot_max = {}
local loot_quantity = {}
local temp_loot = 1
function loot_init(e)
--checks for a random item between 2 numbers
loot_min[e] = 1 --first item in array
loot_max[e] = max_items --last item in array
loot_quantity[e] = math.random(1,3) --how many to give
looted[e] = 0
end
function loot_main(e)
--if your close to the entity prompt to search it
if PlayerLooking(e,90,30) == 1 and looted[e] == 0 then -- start2
Prompt("Press E to loot")
--if you press e and your close enough
if g_KeyPressE == 1 then
looted[e] = 1
temp_loot = math.random(loot_min[e],loot_max[e])
PQ_item[temp_loot] = PQ_item[temp_loot] + loot_quantity[e]
PromptDuration("You found "..loot_quantity[e].." x "..item_name[temp_loot],3000)
end
end
end
function PlayerLooking(e,dis,v)
if g_Entity[e] ~= nil then
if dis == nil then
dis = 3000
end
if v == nil then
v = 0.5
end
if GetPlayerDistance(e) <= dis then
local destx = g_Entity[e]['x'] - g_PlayerPosX
local destz = g_Entity[e]['z'] - g_PlayerPosZ
local angle = math.atan2(destx,destz)
angle = angle * (180.0 / math.pi)
if angle <= 0 then
angle = 360 + angle
elseif angle > 360 then
angle = angle - 360
end
while g_PlayerAngY < 0 or g_PlayerAngY > 360 do
if g_PlayerAngY <= 0 then
g_PlayerAngY = 360 + g_PlayerAngY
elseif g_PlayerAngY > 360 then
g_PlayerAngY = g_PlayerAngY - 360
end
end
local L = angle - v
local R = angle + v
if L <= 0 then
L = 360 + L
elseif L > 360 then
L = L - 360
end
if R <= 0 then
R = 360 + R
elseif R > 360 then
R = R - 360
end
if (L < R and math.abs(g_PlayerAngY) > L and math.abs(g_PlayerAngY) < R) then
return 1
elseif (L > R and (math.abs(g_PlayerAngY) > L or math.abs(g_PlayerAngY) < R)) then
return 1
else
return 0
end
else
return 0
end
end
end
this should put you on the right track at least, good luck