item_name = {} item_type = {} item_slot = {} item_weight = {} item_quantity = {} item_image = {} item_sprite = {} slot_taken = {} item_quantity_held = {} shown = 0 max_weight = 9 --how many items you can carry slot_sizex = 8 --how big 1 thumbnail slot is (x%) slot_sizey = 8 bag_x = 5 --position of the inventory bag on screen bag_y = 30 focus_sizex = slot_sizex * 8 --when mousing over an item how big it will show focus_sizey = slot_sizey * 8 focus_x = 50 - (focus_sizex/2) --where to place the image of a moused over item focus_y = 50 - (focus_sizey/2) bag_size_x = 24 --size of the inventory image on screen (x%) bag_size_y = 49 max_shown = 3 --how many icons are shown while inventory is open slot1_offsetx = 2 --position of the first slot inside your inventory image (relative to the inventory image) slot1_offsety = 10 inv_i = LoadImage("scriptbank\\images\\inventory\\inventory.png") --location of the inventory image cursor_size_x = 1 --size of the cursor image cursor_size_y = 1 cursor_i = LoadImage("scriptbank\\images\\inventory\\cursor.png") --location of the cursor image (mouse) inv = CreateSprite(inv_i) SetSpriteSize(inv,bag_size_x,bag_size_y) SetSpriteDepth(inv,10) SetSpritePosition(inv,200,200) cursor = CreateSprite(cursor_i) SetSpriteSize(cursor,cursor_size_x,cursor_size_y) SetSpriteDepth(cursor,9) SetSpritePosition(cursor,200,200) show_inv = 0 ipressed = 0 clicked = 0 current_slot = 1 current_weight = 0 current_slot_shown = 0 deleted = 0 last_gun = "" function inventory_init(e) end function inventory_main(e) if GetScancode() == 23 and ipressed == 0 then ipressed = 1 if show_inv == 0 then PlaySound(e,0) show_inv = 1 last_gun = g_PlayerGunName SetPlayerWeapons(0) ActivateMouse() else PlaySound(e,1) SetPlayerWeapons(1) ChangePlayerWeapon(last_gun) show_inv = 0 DeactivateMouse() end end if show_inv == 1 then PasteSpritePosition(inv,bag_x,bag_y) TextCenterOnX(bag_x+(bag_size_x/2),bag_y+(slot1_offsety/2),3,"Weight = "..current_weight.." / "..max_weight) slotx = (bag_x+slot1_offsetx)+(bag_size_x/4) sloty = bag_y+slot1_offsety shown = 0 for a = current_slot_shown, 999 do if slot_taken[a] ~= nil then if tonumber(item_quantity_held[item_name[slot_taken[a]]]) > 0 then shown = shown + 1 if g_MouseX > slotx and g_MouseX <= slotx+slot_sizex then if g_MouseY > sloty and g_MouseY <= sloty+slot_sizey then SetSpriteSize(item_sprite[slot_taken[a]],focus_sizex,focus_sizey) PasteSpritePosition(item_sprite[slot_taken[a]],focus_x,focus_y) Text(focus_x+(focus_sizex/4),focus_y+(focus_sizey/2.5),5,item_quantity_held[item_name[slot_taken[a]]].." x ") Text(focus_x+(focus_sizex/4),focus_y+(focus_sizey/1.5),4,"W "..(item_weight[slot_taken[a]]*(item_quantity_held[item_name[slot_taken[a]]]/item_quantity[slot_taken[a]])).."kg") if g_MouseClick == 1 and clicked == 0 then clicked = 1 if item_type[slot_taken[a]] == "ammo" then AddPlayerAmmo(slot_taken[a]) item_quantity_held[item_name[slot_taken[a]]] = item_quantity_held[item_name[slot_taken[a]]] - item_quantity[slot_taken[a]] current_weight = current_weight - item_weight[slot_taken[a]] PlaySound(slot_taken[a],0) elseif item_type[slot_taken[a]] == "health" then AddPlayerHealth(slot_taken[a]) item_quantity_held[item_name[slot_taken[a]]] = item_quantity_held[item_name[slot_taken[a]]] - item_quantity[slot_taken[a]] current_weight = current_weight - item_weight[slot_taken[a]] PlaySound(slot_taken[a],0) elseif item_type[slot_taken[a]] == "key" and g_Entity[slot_taken[a]]['collected'] == 0 then PromptDuration("Added "..item_name[slot_taken[a]].." to keyring",2000) current_weight = current_weight - item_weight[slot_taken[a]] item_weight[slot_taken[a]] = 0 Collected(slot_taken[a]) PlaySound(slot_taken[a],1) elseif item_type[slot_taken[a]] == "drink" then if thirsty > 0 then thirsty = thirsty - item_weight[slot_taken[a]] if thirsty < 0 then thirsty = 0 end end item_quantity_held[item_name[slot_taken[a]]] = item_quantity_held[item_name[slot_taken[a]]] - item_quantity[slot_taken[a]] current_weight = current_weight - item_weight[slot_taken[a]] item_weight[slot_taken[a]] = 0 PlaySound(slot_taken[a],1) elseif item_type[slot_taken[a]] == "food" then if hungry > 0 then hungry = hungry - item_weight[slot_taken[a]] if hungry < 0 then hungry = 0 end end item_quantity_held[item_name[slot_taken[a]]] = item_quantity_held[item_name[slot_taken[a]]] - item_quantity[slot_taken[a]] current_weight = current_weight - item_weight[slot_taken[a]] item_weight[slot_taken[a]] = 0 PlaySound(slot_taken[a],1) end end else SetSpriteSize(item_sprite[slot_taken[a]],slot_sizex,slot_sizey) end else SetSpriteSize(item_sprite[slot_taken[a]],slot_sizex,slot_sizey) end SetSpriteSize(item_sprite[slot_taken[a]],slot_sizex,slot_sizey) PasteSpritePosition(item_sprite[slot_taken[a]],slotx,sloty) Text(slotx+1,sloty+(slot_sizey/2.5),2,item_quantity_held[item_name[slot_taken[a]]].." x ") Text(slotx+1,sloty+(slot_sizey/1.5),2,"W "..(item_weight[slot_taken[a]]*(item_quantity_held[item_name[slot_taken[a]]]/item_quantity[slot_taken[a]])).."kg") sloty = sloty+slot_sizey else Destroy(slot_taken[a]) shown = shown - 1 deleted = deleted + 1 slot_taken[a] = nil end end if shown >= max_shown then break end end if g_MouseWheel < 0 and current_slot_shown < current_slot-shown and shown >= 3 then current_slot_shown = current_slot_shown + 1 elseif g_MouseWheel > 0 and current_slot_shown > 0 then current_slot_shown = current_slot_shown - 1 end SetSpritePosition(cursor,g_MouseX,g_MouseY) else current_slot_shown = 0 SetSpritePosition(cursor,200,200) end if GetScancode() == 0 then ipressed = 0 end if g_MouseClick == 0 then clicked = 0 end end function inventory_exit(e) 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