function showInventory (key,keyState)
if getElementData(getLocalPlayer(),"logedin") then
if ( keyState == "down" ) then
guiSetVisible(inventoryWindows,not guiGetVisible(inventoryWindows))
showCursor(not isCursorShowing())
refreshInventory()
if guiGetVisible(inventoryWindows) == true then
onClientOpenInventoryStopMenu ()
else
hideRightClickInventoryMenu ()
end
if isPlayerInLoot() then
local col = getElementData(getLocalPlayer(),"currentCol")
local gearName = getElementData(getLocalPlayer(),"lootname")
refreshLoot(col,gearName)
end
end
end
end
bindKey ( "j", "down", showInventory )
function showInventoryManual ()
guiSetVisible(inventoryWindows,not guiGetVisible(inventoryWindows))
showCursor(not isCursorShowing())
refreshInventory()
if guiGetVisible(inventoryWindows) == true then
onClientOpenInventoryStopMenu ()
end
end
function hideInventoryManual ()
guiSetVisible(inventoryWindows,false)
showCursor(false)
hideRightClickInventoryMenu ()
end
addEvent("hideInventoryManual",true)
addEventHandler("hideInventoryManual",getLocalPlayer(),hideInventoryManual)
function refreshInventoryManual ()
refreshInventory()
end
addEvent("refreshInventoryManual",true)
addEventHandler("refreshInventoryManual",getLocalPlayer(),refreshInventoryManual)
function refreshLootManual (loot)
refreshLoot(loot)
end
addEvent("refreshLootManual",true)
addEventHandler("refreshLootManual",getLocalPlayer(),refreshLootManual)
function refreshInventory()
if ( gridlistItems["inventory_colum"] ) then --If the column has been created, fill it with players
row1,column1 = guiGridListGetSelectedItem ( gridlistItems["inventory"] )
guiGridListClear(gridlistItems["inventory"])
local row = guiGridListAddRow ( gridlistItems["inventory"] )
--guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum"],"ITEMS", false, false )
local row = guiGridListAddRow ( gridlistItems["inventory"] )
guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum"],"Основное оружие", true, false )
for id, item in ipairs(inventoryItems["Weapons"]["Primary Weapon"]) do
if getElementData(getLocalPlayer(),item[1]) and getElementData(getLocalPlayer(),item[1]) >= 1 then
local row = guiGridListAddRow ( gridlistItems["inventory"] )
guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum"],item[1], false, false )
guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum_amount"],getElementData(getLocalPlayer(),item[1]), false, false )
end
end
local row = guiGridListAddRow ( gridlistItems["inventory"] )
guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum"],"Дополнительное оружие", true, false )
for id, item in ipairs(inventoryItems["Weapons"]["Secondary Weapon"]) do
if getElementData(getLocalPlayer(),item[1]) and getElementData(getLocalPlayer(),item[1]) >= 1 then
local row = guiGridListAddRow ( gridlistItems["inventory"] )
guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum"],item[1], false, false )
guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum_amount"],getElementData(getLocalPlayer(),item[1]), false, false )
end
end
local row = guiGridListAddRow ( gridlistItems["inventory"] )
guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum"],"Специальное оружие", true, false )
for id, item in ipairs(inventoryItems["Weapons"]["Specially Weapon"]) do
if getElementData(getLocalPlayer(),item[1]) and getElementData(getLocalPlayer(),item[1]) >= 1 then
local row = guiGridListAddRow ( gridlistItems["inventory"] )
guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum"],item[1], false, false )
guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum_amount"],getElementData(getLocalPlayer(),item[1]), false, false )
end
end
local row = guiGridListAddRow ( gridlistItems["inventory"] )
guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum"],"Боеприпасы", true, false )
for id, item in ipairs(inventoryItems["Ammo"]) do
if getElementData(getLocalPlayer(),item[1]) and getElementData(getLocalPlayer(),item[1]) >= 1 then
local row = guiGridListAddRow ( gridlistItems["inventory"] )
guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum"],item[1], false, false )
guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum_amount"],getElementData(getLocalPlayer(),item[1]), false, false )
end
end
local row = guiGridListAddRow ( gridlistItems["inventory"] )
guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum"],"Еда и вода", true, false )
for id, item in ipairs(inventoryItems["Food"]) do
if getElementData(getLocalPlayer(),item[1]) and getElementData(getLocalPlayer(),item[1]) >= 1 then
local row = guiGridListAddRow ( gridlistItems["inventory"] )
guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum"],item[1], false, false )
guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum_amount"],getElementData(getLocalPlayer(),item[1]), false, false )
end
end
local row = guiGridListAddRow ( gridlistItems["inventory"] )
guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum"],"Прочее", true, false )
for id, item in ipairs(inventoryItems["Items"]) do
if getElementData(getLocalPlayer(),item[1]) and getElementData(getLocalPlayer(),item[1]) >= 1 then
local row = guiGridListAddRow ( gridlistItems["inventory"] )
guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum"],item[1], false, false )
guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum_amount"],getElementData(getLocalPlayer(),item[1]), false, false )
end
end
local row = guiGridListAddRow ( gridlistItems["inventory"] )
guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum"],"Инструменты", true, false )
for id, item in ipairs(inventoryItems["Toolbelt"]) do
if getElementData(getLocalPlayer(),item[1]) and getElementData(getLocalPlayer(),item[1]) >= 1 then
local row = guiGridListAddRow ( gridlistItems["inventory"] )
guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum"],item[1], false, false )
guiGridListSetItemText ( gridlistItems["inventory"], row, gridlistItems["inventory_colum_amount"],getElementData(getLocalPlayer(),item[1]), false, false )
end
end
if row1 and column1 then
guiGridListSetSelectedItem ( gridlistItems["inventory"], row1,column1)
end
guiSetText(headline["slots"],"Слоты: "..getPlayerCurrentSlots().."/"..getPlayerMaxAviableSlots())
end
end
function refreshLoot(loot,gearName)
if loot == false then
guiGridListClear(gridlistItems["loot"])
guiSetText(headline["loot"],"Пусто")
return
end
if ( gridlistItems["loot_colum"] ) then
row2,column2 = guiGridListGetSelectedItem ( gridlistItems["inventory"] )
guiGridListClear(gridlistItems["loot"])
if gearName then
guiSetText(headline["loot"],gearName)
end
local row = guiGridListAddRow ( gridlistItems["loot"] )
--guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum"],"Weapons", true, false )
local row = guiGridListAddRow ( gridlistItems["loot"] )
guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum"],"Основное оружие", true, false )
for id, item in ipairs(inventoryItems["Weapons"]["Primary Weapon"]) do
if getElementData(loot,item[1]) and getElementData(loot,item[1]) >= 1 then
local row = guiGridListAddRow ( gridlistItems["loot"] )
guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum"],item[1], false, false )
guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum_amount"],getElementData(loot,item[1]), false, false )
end
end
local row = guiGridListAddRow ( gridlistItems["loot"] )
guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum"],"Дополнительное оружие", true, false )
for id, item in ipairs(inventoryItems["Weapons"]["Secondary Weapon"]) do
if getElementData(loot,item[1]) and getElementData(loot,item[1]) >= 1 then
local row = guiGridListAddRow ( gridlistItems["loot"] )
guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum"],item[1], false, false )
guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum_amount"],getElementData(loot,item[1]), false, false )
end
end
local row = guiGridListAddRow ( gridlistItems["loot"] )
guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum"],"Специальное оружие", true, false )
for id, item in ipairs(inventoryItems["Weapons"]["Specially Weapon"]) do
if getElementData(loot,item[1]) and getElementData(loot,item[1]) >= 1 then
local row = guiGridListAddRow ( gridlistItems["loot"] )
guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum"],item[1], false, false )
guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum_amount"],getElementData(loot,item[1]), false, false )
end
end
local row = guiGridListAddRow ( gridlistItems["loot"] )
guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum"],"Боеприпасы", true, false )
for id, item in ipairs(inventoryItems["Ammo"]) do
if getElementData(loot,item[1]) and getElementData(loot,item[1]) >= 1 then
local row = guiGridListAddRow ( gridlistItems["loot"] )
guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum"],item[1], false, false )
guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum_amount"],getElementData(loot,item[1]), false, false )
end
end
local row = guiGridListAddRow ( gridlistItems["loot"] )
guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum"],"Еда и вода", true, false )
for id, item in ipairs(inventoryItems["Food"]) do
if getElementData(loot,item[1]) and getElementData(loot,item[1]) >= 1 then
local row = guiGridListAddRow ( gridlistItems["loot"] )
guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum"],item[1], false, false )
guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum_amount"],getElementData(loot,item[1]), false, false )
end
end
local row = guiGridListAddRow ( gridlistItems["loot"] )
guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum"],"Прочее", true, false )
for id, item in ipairs(inventoryItems["Items"]) do
if getElementData(loot,item[1]) and getElementData(loot,item[1]) >= 1 then
local row = guiGridListAddRow ( gridlistItems["loot"] )
guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum"],item[1], false, false )
guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum_amount"],getElementData(loot,item[1]), false, false )
end
end
local row = guiGridListAddRow ( gridlistItems["loot"] )
guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum"],"Инструменты", true, false )
for id, item in ipairs(inventoryItems["Toolbelt"]) do
if getElementData(loot,item[1]) and getElementData(loot,item[1]) >= 1 then
local row = guiGridListAddRow ( gridlistItems["loot"] )
guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum"],item[1], false, false )
guiGridListSetItemText ( gridlistItems["loot"], row, gridlistItems["loot_colum_amount"],getElementData(loot,item[1]), false, false )
end
end
code
if row2 and column2 then
--guiGridListSetSelectedItem ( gridlistItems["loot"], row2,column2)
end
guiSetText(headline["slots_loot"],"Слоты: "..getLootCurrentSlots(loot).."/"..(getLootMaxAviableSlots(loot)or 0))
end
end
function getPlayerMaxAviableSlots()
return getElementData(getLocalPlayer(),"MAX_Slots")
end
function getLootMaxAviableSlots(loot)
return getElementData(loot,"MAX_Slots")
end
function getPlayerCurrentSlots()
local current_SLOTS = 0
for id, item in ipairs(inventoryItems["Weapons"]["Primary Weapon"]) do
if getElementData(getLocalPlayer(),item[1]) and getElementData(getLocalPlayer(),item[1]) >= 1 then
current_SLOTS = current_SLOTS + item[2]*getElementData(getLocalPlayer(),item[1])
end
end
for id, item in ipairs(inventoryItems["Weapons"]["Secondary Weapon"]) do
if getElementData(getLocalPlayer(),item[1]) and getElementData(getLocalPlayer(),item[1]) >= 1 then
current_SLOTS = current_SLOTS + item[2]*getElementData(getLocalPlayer(),item[1])
end
end
for id, item in ipairs(inventoryItems["Weapons"]["Specially Weapon"]) do
if getElementData(getLocalPlayer(),item[1]) and getElementData(getLocalPlayer(),item[1]) >= 1 then
current_SLOTS = current_SLOTS + item[2]*getElementData(getLocalPlayer(),item[1])
end
end
for id, item in ipairs(inventoryItems["Ammo"]) do
if getElementData(getLocalPlayer(),item[1]) and getElementData(getLocalPlayer(),item[1]) >= 1 then
current_SLOTS = current_SLOTS + item[2]*getElementData(getLocalPlayer(),item[1])
end
end
for id, item in ipairs(inventoryItems["Food"]) do
if getElementData(getLocalPlayer(),item[1]) and getElementData(getLocalPlayer(),item[1]) >= 1 then
current_SLOTS = current_SLOTS + item[2]*getElementData(getLocalPlayer(),item[1])
end
end
for id, item in ipairs(inventoryItems["Items"]) do
if getElementData(getLocalPlayer(),item[1]) and getElementData(getLocalPlayer(),item[1]) >= 1 then
current_SLOTS = current_SLOTS + item[2]*getElementData(getLocalPlayer(),item[1])
end
end
return math.floor(current_SLOTS)
end
function getLootCurrentSlots(loot)
local current_SLOTS = 0
for id, item in ipairs(inventoryItems["Weapons"]["Primary Weapon"]) do
if getElementData(loot,item[1]) and getElementData(loot,item[1]) >= 1 then
current_SLOTS = current_SLOTS + item[2]*getElementData(loot,item[1])
end
end
for id, item in ipairs(inventoryItems["Weapons"]["Secondary Weapon"]) do
if getElementData(loot,item[1]) and getElementData(loot,item[1]) >= 1 then
current_SLOTS = current_SLOTS + item[2]*getElementData(loot,item[1])
end
end
for id, item in ipairs(inventoryItems["Weapons"]["Specially Weapon"]) do
if getElementData(loot,item[1]) and getElementData(loot,item[1]) >= 1 then
current_SLOTS = current_SLOTS + item[2]*getElementData(loot,item[1])
end
end
for id, item in ipairs(inventoryItems["Ammo"]) do
if getElementData(loot,item[1]) and getElementData(loot,item[1]) >= 1 then
current_SLOTS = current_SLOTS + item[2]*getElementData(loot,item[1])
end
end
for id, item in ipairs(inventoryItems["Food"]) do
if getElementData(loot,item[1]) and getElementData(loot,item[1]) >= 1 then
current_SLOTS = current_SLOTS + item[2]*getElementData(loot,item[1])
end
end
for id, item in ipairs(inventoryItems["Items"]) do
if getElementData(loot,item[1]) and getElementData(loot,item[1]) >= 1 then
current_SLOTS = current_SLOTS + item[2]*getElementData(loot,item[1])
end
end
return math.floor(current_SLOTS)
end
function getItemSlots(itema)
local current_SLOTS = 0
for id, item in ipairs(inventoryItems["Weapons"]["Primary Weapon"]) do
if itema == item[1] then
return item[2]
end
end
for id, item in ipairs(inventoryItems["Weapons"]["Secondary Weapon"]) do
if itema == item[1] then
return item[2]
end
end
for id, item in ipairs(inventoryItems["Weapons"]["Specially Weapon"]) do
if itema == item[1] then
return item[2]
end
end
for id, item in ipairs(inventoryItems["Ammo"]) do
if itema == item[1] then
return item[2]
end
end
for id, item in ipairs(inventoryItems["Food"]) do
if itema == item[1] then
return item[2]
end
end
for id, item in ipairs(inventoryItems["Items"]) do
if itema == item[1] then
return item[2]
end
end
return false
end
function isToolbeltItem(itema)
local current_SLOTS = 0
for id, item in ipairs(inventoryItems["Toolbelt"]) do
if itema == item[1] then
return true
end
end
return false
end
function getVehicleMaxFuel(loot)
local modelID = getElementModel(getElementData(loot,"parent"))
for i,vehicle in ipairs(vehicleFuelTable) do
if modelID == vehicle[1] then
return vehicle[2]
end
end
return false
end
function onPlayerMoveItemOutOfInventory ()
if playerMovedInInventory then startRollMessage2("Inventory", "Не торопись!", 255, 22, 0 ) return end -- [ID:0000005 - Several grammar + spelling mistakes and typos] //L
local itemName = guiGridListGetItemText ( gridlistItems["inventory"], guiGridListGetSelectedItem ( gridlistItems["inventory"] ), 1 )
if getElementData(getLocalPlayer(),itemName) and getElementData(getLocalPlayer(),itemName) >= 1 then
if isPlayerInLoot() then
local isVehicle = getElementData(isPlayerInLoot(),"vehicle")
local isTent = getElementData(isPlayerInLoot(),"tent")
if isVehicle and not isTent then
local veh = getElementData(isPlayerInLoot(),"parent")
local tires,engine,parts = getVehicleAddonInfos (getElementModel(veh))
if itemName == "Колесо" and (getElementData(isPlayerInLoot(),"Колесо_inVehicle") or 0) < tires or itemName == "Двигатель" and (getElementData(isPlayerInLoot(),"Двигатель_inVehicle") or 0) < engine or itemName == "Бензобак" and (getElementData(isPlayerInLoot(),"Parts_inVehicle") or 0) < parts then
if itemName == "Бензобак" then itemName = "Parts" end
triggerEvent("onPlayerMoveItemOutOFInventory",getLocalPlayer(),itemName.."_inVehicle",isPlayerInLoot())
playerMovedInInventory = true
setTimer(function()
playerMovedInInventory = false
end,700,1)
elseif isToolbeltItem(itemName) then
triggerEvent("onPlayerMoveItemOutOFInventory",getLocalPlayer(),itemName,isPlayerInLoot())
playerMovedInInventory = true
setTimer(function()
playerMovedInInventory = false
end,700,1)
elseif getLootCurrentSlots(getElementData(getLocalPlayer(),"currentCol")) + getItemSlots(itemName) <= getLootMaxAviableSlots(isPlayerInLoot()) then
triggerEvent("onPlayerMoveItemOutOFInventory",getLocalPlayer(),itemName,isPlayerInLoot())
playerMovedInInventory = true
setTimer(function()
playerMovedInInventory = false
end,700,1)
else
startRollMessage2("Inventory", "Инвентарь полон!", 255, 22, 0 )
return
end
elseif isToolbeltItem(itemName) then
triggerEvent("onPlayerMoveItemOutOFInventory",getLocalPlayer(),itemName,isPlayerInLoot())
playerMovedInInventory = true
setTimer(function()
playerMovedInInventory = false
end,700,1)
elseif getLootCurrentSlots(getElementData(getLocalPlayer(),"currentCol")) + getItemSlots(itemName) <= getLootMaxAviableSlots(isPlayerInLoot()) then
triggerEvent("onPlayerMoveItemOutOFInventory",getLocalPlayer(),itemName,isPlayerInLoot())
playerMovedInInventory = true
setTimer(function()
playerMovedInInventory = false
end,700,1)
else
startRollMessage2("Inventory", "Инвентарь полон!", 255, 22, 0 )
return
end
else
triggerEvent("onPlayerMoveItemOutOFInventory",getLocalPlayer(),itemName,isPlayerInLoot())
playerMovedInInventory = true
setTimer(function()
playerMovedInInventory = false
end,700,1)
end
end
local gearName = guiGetText(headline["loot"])
local col = getElementData(getLocalPlayer(),"currentCol")
setTimer(refreshInventory,200,2)
if isPlayerInLoot() then
setTimer(refreshLoot,200,2,col,gearName)
end
end
addEventHandler ( "onClientGUIClick", buttonItems["inventory"], onPlayerMoveItemOutOfInventory )
function onPlayerMoveItemOutOFInventory (itemName,loot)
local itemPlus = 1
if itemName == "M1911 Mag" then
itemPlus = 7
elseif itemName == "M9 SD Mag" then
itemPlus = 15
elseif itemName == ".45ACP" then
itemPlus = 7
elseif itemName == "PDW Mag" then
itemPlus = 30
elseif itemName == "MP5A5 Mag" then
itemPlus = 20
elseif itemName == "AK" then
itemPlus = 30
elseif itemName == "STANAG" then
itemPlus = 20
elseif itemName == "1866 Slug" then
itemPlus = 7
elseif itemName == "2Rnd. Slug" then
itemPlus = 2
elseif itemName == "SPAZ-12 Pellet" then
itemPlus = 7
elseif itemName == "CZ550 Mag" then
itemPlus = 5
elseif itemName == "Lee Enfield Mag" then
itemPlus = 10
elseif itemName == "M136 Rocket" then
itemPlus = 0
elseif itemName == "М4А1 CCO" or itemName == "AK-74" or itemName == "CZ550" or itemName == "Винчестер 1866" or itemName == "SPAZ-12 Combat Shotgun" or itemName == "Sawn-Off Shotgun" or itemName == "Heat-Seeking RPG" or itemName == "M136 Rocket Launcher" or itemName == "Lee Enfield" then
triggerServerEvent("removeBackWeaponOnDrop",getLocalPlayer())
end
if loot then
if not getElementData(loot,"itemloot") and getElementType(getElementData(loot,"parent")) == "vehicle" then
if itemName == "Наполненная канистра" then
if getElementData(loot,"fuel")+20 < getVehicleMaxFuel(loot) then
addingfuel = 20
elseif getElementData(loot,"fuel")+20 > getVehicleMaxFuel(loot)+15 then
triggerEvent ("displayClientInfo", getLocalPlayer(),"Vehicle","Бензобак полон!",255,22,0)
return
else
addingfuel = getVehicleMaxFuel(loot)-getElementData(loot,"fuel")
end
setElementData(loot,"fuel",getElementData(loot,"fuel")+addingfuel)
setElementData(getLocalPlayer(),itemName,getElementData(getLocalPlayer(),itemName)-itemPlus)
setElementData(getLocalPlayer(),"Пустая канистра",(getElementData(getLocalPlayer(),"Пустая канистра") or 0)+itemPlus)
triggerEvent ("displayClientInfo", getLocalPlayer(),"Vehicle","Вы заправили транспорт на 20 литров!",22,255,0)
return
end
end
end
itemName2 = itemName
if itemName == "Колесо_inVehicle" then itemName2 = "Колесо" end
if itemName == "Двигатель_inVehicle" then itemName2 = "Двигатель" end
if itemName == "Parts_inVehicle" then itemName2 = "Бензобак" end
if (getElementData(getLocalPlayer(),itemName2) or 0)/itemPlus < 1 then
triggerEvent ("displayClientInfo", getLocalPlayer(),"Inventory","Вы не можете использовать это!",255,22,0)
return
end
if loot then
setElementData(loot,itemName,(getElementData(loot,itemName) or 0)+1)
local players = getElementsWithinColShape (loot,"player")
if #players > 1 then
triggerServerEvent("onPlayerChangeLoot",getRootElement(),loot)
end
if not getElementData(loot,"itemloot") and getElementType(getElementData(loot,"parent")) == "vehicle" then
end
else
triggerServerEvent("playerDropAItem",getLocalPlayer(),itemName)
end
if itemName == "Колесо_inVehicle" then itemName = "Колесо" end
if itemName == "Двигатель_inVehicle" then itemName = "Двигатель" end
if itemName == "Parts_inVehicle" then itemName = "Бензобак" end
setElementData(getLocalPlayer(),itemName,getElementData(getLocalPlayer(),itemName)-itemPlus)
if loot and getElementData(loot,"itemloot") then
triggerServerEvent("refreshItemLoot",getRootElement(),loot,getElementData(loot,"parent"))
end
end
addEvent( "onPlayerMoveItemOutOFInventory", true )
addEventHandler( "onPlayerMoveItemOutOFInventory", getRootElement(), onPlayerMoveItemOutOFInventory )
function onPlayerMoveItemInInventory ()
local itemName = guiGridListGetItemText ( gridlistItems["loot"], guiGridListGetSelectedItem ( gridlistItems["loot"] ), 1 )
if isPlayerInLoot() then
if getElementData(isPlayerInLoot(),itemName) and getElementData(isPlayerInLoot(),itemName) >= 1 then
if not isToolbeltItem(itemName) then
if getPlayerCurrentSlots() + getItemSlots(itemName) <= getPlayerMaxAviableSlots() then
if not playerMovedInInventory then
triggerEvent("onPlayerMoveItemInInventory",getLocalPlayer(),itemName,isPlayerInLoot())
playerMovedInInventory = true
setTimer(function()
playerMovedInInventory = false
end,700,1)
else
startRollMessage2("Inventory", "Не торопись!", 255, 22, 0 )
return
end
else
startRollMessage2("Inventory", "Инвентарь полон!", 255, 22, 0 )
return
end
else
playerMovedInInventory = true
setTimer(function()
playerMovedInInventory = false
end,700,1)
triggerEvent("onPlayerMoveItemInInventory",getLocalPlayer(),itemName,isPlayerInLoot())
end
end
if isPlayerInLoot() then
local gearName = guiGetText(headline["loot"])
local col = getElementData(getLocalPlayer(),"currentCol")
setTimer(refreshInventory,200,2)
setTimer(refreshLoot,200,2,col,gearName)
end
end
end
addEventHandler ( "onClientGUIClick", buttonItems["loot"], onPlayerMoveItemInInventory )
function onPlayerMoveItemInInventory (itemName,loot)
local itemPlus = 1
if itemName == "M1911 Mag" then
itemPlus = 7
elseif itemName == "M9 SD Mag" then
itemPlus = 15
elseif itemName == ".45ACP" then
itemPlus = 7
elseif itemName == "PDW Mag" then
itemPlus = 30
elseif itemName == "MP5A5 Mag" then
itemPlus = 20
elseif itemName == "AK" then
itemPlus = 30
elseif itemName == "STANAG" then
itemPlus = 20
elseif itemName == "1866 Slug" then
itemPlus = 7
elseif itemName == "2Rnd. Slug" then
itemPlus = 2
elseif itemName == "SPAZ-12 Pellet" then
itemPlus = 7
elseif itemName == "CZ550 Mag" then
itemPlus = 5
elseif itemName == "Lee Enfield Mag" then
itemPlus = 10
elseif itemName == "M136 Rocket" then
itemPlus = 0
elseif itemName == "Assault Pack (ACU)" then
if getElementData(getLocalPlayer(),"MAX_Slots") == 12 then triggerEvent (getLocalPlayer(), "displayClientInfo", getLocalPlayer(),"Inventory","You are using this backpack already!",255,22,0) return end
if getElementData(getLocalPlayer(),"MAX_Slots") > 12 then triggerEvent (getLocalPlayer(), "displayClientInfo", getLocalPlayer(),"Inventory","The currently equipped backpack has more space!",255,22,0) return end
setElementData(getLocalPlayer(),"MAX_Slots",12)
setElementData(loot,itemName,getElementData(loot,itemName)-1)
itemPlus = 0
elseif itemName == "Alice Pack" then
if getElementData(getLocalPlayer(),"MAX_Slots") == 16 then triggerEvent (getLocalPlayer(), "displayClientInfo", getLocalPlayer(),"Inventory","You are using this backpack already!",255,22,0) return end
if getElementData(getLocalPlayer(),"MAX_Slots") > 16 then triggerEvent (getLocalPlayer(), "displayClientInfo", getLocalPlayer(),"Inventory","The currently equipped backpack has more space!",255,22,0) return end
setElementData(getLocalPlayer(),"MAX_Slots",16)
setElementData(loot,itemName,getElementData(loot,itemName)-1)
itemPlus = 0
elseif itemName == "Czech Backpack" then
if getElementData(getLocalPlayer(),"MAX_Slots") == 26 then triggerEvent (getLocalPlayer(), "displayClientInfo", getLocalPlayer(),"Inventory","You are using this backpack already!",255,22,0) return end
if getElementData(getLocalPlayer(),"MAX_Slots") > 26 then triggerEvent (getLocalPlayer(), "displayClientInfo", getLocalPlayer(),"Inventory","The currently equipped backpack has more space!",255,22,0) return end
setElementData(getLocalPlayer(),"MAX_Slots",26)
setElementData(loot,itemName,getElementData(loot,itemName)-1)
itemPlus = 0
elseif itemName == "Coyote Backpack" then
if getElementData(getLocalPlayer(),"MAX_Slots") == 36 then triggerEvent (getLocalPlayer(), "displayClientInfo", getLocalPlayer(),"Inventory","You already have the best backpack!",255,22,0) return end
if getElementData(getLocalPlayer(),"MAX_Slots") > 36 then triggerEvent (getLocalPlayer(), "displayClientInfo", getLocalPlayer(),"Inventory","The currently equipped backpack has more space!",255,22,0) return end
setElementData(getLocalPlayer(),"MAX_Slots",36)
setElementData(loot,itemName,getElementData(loot,itemName)-1)
itemPlus = 0
end
if loot then
--if itemPlus > (getElementData(loot,itemName) or 0) then
--itemPlus = getElementData(loot,itemName)
--end
setElementData(getLocalPlayer(),itemName,(getElementData(getLocalPlayer(),itemName) or 0)+itemPlus)
if itemPlus == 0 then
setElementData(loot,itemName,getElementData(loot,itemName)-0)
else
setElementData(loot,itemName,getElementData(loot,itemName)-1)
end
local players = getElementsWithinColShape (loot,"player")
if #players > 1 then
triggerServerEvent("onPlayerChangeLoot",getRootElement(),loot)
end
end
if getElementData(loot,"itemloot") then
triggerServerEvent("refreshItemLoot",getRootElement(),loot,getElementData(loot,"parent"))
end
end
addEvent( "onPlayerMoveItemInInventory", true )
addEventHandler( "onPlayerMoveItemInInventory", getRootElement(), onPlayerMoveItemInInventory )
function onClientOpenInventoryStopMenu ()
triggerEvent("disableMenu",getLocalPlayer())
end
function isPlayerInLoot()
if getElementData(getLocalPlayer(),"loot") then
return getElementData(getLocalPlayer(),"currentCol")
end
return false
end
--right-click menu
function onPlayerPressRightKeyInInventory ()
local itemName = guiGridListGetItemText ( gridlistItems["inventory"], guiGridListGetSelectedItem ( gridlistItems["inventory"] ), 1 )
local itemName,itemInfo = getInventoryInfosForRightClickMenu(itemName)
if isCursorShowing() and guiGetVisible(inventoryWindows) and itemInfo then
if itemName == "Спички" then
if getElementData(getLocalPlayer(),"Дрова") == 0 then
return
end
end
if itemName == "Бинт" then
if getElementData(getLocalPlayer(),"bleeding") == 0 then
return
end
end
if itemName == "Аптечка" then
if getElementData(getLocalPlayer(),"blood") > 10500 then
return
end
end
if itemName == "Грелка" then
if getElementData(getLocalPlayer(),"temperature") > 35 then
return
end
end
if itemName == "Болеутоляющие" then
if not getElementData(getLocalPlayer(),"pain") then
return
end
end
if itemName == "Морфий" then
if not getElementData(getLocalPlayer(),"brokenbone") then
return
end
end
if itemName == "Пакет крови" then
--if getElementData(getLocalPlayer(),"blood") < 1150 then
return
--end
end
showRightClickInventoryMenu (itemName,itemInfo)
end
end
bindKey("mouse2","down",onPlayerPressRightKeyInInventory)
function getInventoryInfosForRightClickMenu(itemName)
for i,itemInfo in ipairs(inventoryItems["Weapons"]["Primary Weapon"]) do
if itemName == itemInfo[1] then
return itemName,"Взять осн. оружие"
end
end
for i,itemInfo in ipairs(inventoryItems["Weapons"]["Secondary Weapon"]) do
if itemName == itemInfo[1] then
return itemName,"Взять доп. оружие"
end
end
for i,itemInfo in ipairs(inventoryItems["Weapons"]["Specially Weapon"]) do
if itemName == itemInfo[1] then
return itemName,"Взять спец. оружие"
end
end
for i,itemInfo in ipairs(inventoryItems["Ammo"]) do
if itemName == itemInfo[1] then
return itemName,false
end
end
for i,itemInfo in ipairs(inventoryItems["Food"]) do
if itemName == itemInfo[1] then
if itemInfo[1] == "Фляга" or itemInfo[1] == "Молоко" or itemInfo[1] == "Банка соды" then
info = "Выпить"
else
info = "Съесть"
end
return itemName,info
end
end
for i,itemInfo in ipairs(inventoryItems["Items"]) do
if itemName == itemInfo[1] then
return itemName,itemInfo[3] or false
end
end
for i,itemInfo in ipairs(inventoryItems["Toolbelt"]) do
if itemName == itemInfo[1] then
return itemName,itemInfo[3] or false
end
end
end
function showRightClickInventoryMenu (itemName,itemInfo)
if itemInfo then
local screenx, screeny, worldx, worldy, worldz = getCursorPosition()
guiSetVisible(rightclickWindow,true)
guiSetText(headline["rightclickmenu"],itemInfo)
local whith = guiLabelGetTextExtent (headline["rightclickmenu"])
guiSetPosition(rightclickWindow,screenx,screeny,true)
local x,y = guiGetSize(rightclickWindow,false)
guiSetSize(rightclickWindow,whith,y,false)
guiBringToFront(rightclickWindow)
setElementData(rightclickWindow,"iteminfo",{itemName,itemInfo})
end
end
function hideRightClickInventoryMenu ()
guiSetVisible(rightclickWindow,false)
end
function onPlayerClickOnRightClickMenu (button,state)
if button == "left" then
local itemName,itemInfo = getElementData(rightclickWindow,"iteminfo")[1],getElementData(rightclickWindow,"iteminfo")[2]
hideRightClickInventoryMenu ()
playerUseItem(itemName,itemInfo)
end
end
addEventHandler("onClientGUIClick",headline["rightclickmenu"],onPlayerClickOnRightClickMenu,false)
local playerFire = {}
local fireCounter = 0
function playerUseItem(itemName,itemInfo)
if itemInfo == "Выпить" then
triggerServerEvent("onPlayerRequestChangingStats",getLocalPlayer(),itemName,itemInfo,"thirst")
elseif itemInfo == "Съесть" then
triggerServerEvent("onPlayerRequestChangingStats",getLocalPlayer(),itemName,itemInfo,"food")
elseif itemInfo == "Переодется" then
triggerServerEvent("onPlayerChangeSkin",getLocalPlayer(),itemName)
elseif itemName == "Пустая фляга" then
triggerServerEvent("onPlayerRefillWaterBottle",getLocalPlayer(),itemName)
elseif itemName == "Палатка" then
triggerServerEvent("onPlayerPitchATent",getLocalPlayer(),itemName)
elseif itemInfo == "Поставить проволоку" then
triggerServerEvent("onPlayerBuildAWireFence",getLocalPlayer(),itemName)
elseif itemName == "Фаер" then
triggerServerEvent("onPlayerPlaceRoadflare",getLocalPlayer(),itemName)
elseif itemInfo == "Поджечь" then
triggerServerEvent("onPlayerMakeAFire",getLocalPlayer(),itemName)
elseif itemInfo == "Исп." then
triggerServerEvent("onPlayerUseMedicObject",getLocalPlayer(),itemName)
elseif itemName == "Бинт" then
triggerServerEvent("onPlayerUseMedicObject",getLocalPlayer(),itemName)
elseif itemInfo == "Исп. Googles" then
triggerServerEvent("onPlayerChangeView",getLocalPlayer(),itemName)
elseif itemInfo == "Взять осн. оружие" then
triggerServerEvent("onPlayerRearmWeapon",getLocalPlayer(),itemName,1)
elseif itemInfo == "Взять доп. оружие" then
triggerServerEvent("onPlayerRearmWeapon",getLocalPlayer(),itemName,2)
elseif itemInfo == "Взять спец. оружие" then
triggerServerEvent("onPlayerRearmWeapon",getLocalPlayer(),itemName,3)
end
function getWeaponAmmoType2 (weaponName)
for i,weaponData in ipairs(weaponAmmoTable["others"]) do
if weaponName == weaponData[2] then
return weaponData[1],weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["M1911 Mag"]) do
if weaponName == weaponData[2] then
return "M1911 Mag",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["M9 SD Mag"]) do
if weaponName == weaponData[2] then
return "M9 SD Mag",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable[".45ACP"]) do
if weaponName == weaponData[2] then
return ".45ACP",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["PDW Mag"]) do
if weaponName == weaponData[2] then
return "PDW Mag",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["MP5A5 Mag"]) do
if weaponName == weaponData[2] then
return "MP5A5 Mag",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["AK"]) do
if weaponName == weaponData[2] then
return "AK",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["STANAG"]) do
if weaponName == weaponData[2] then
return "STANAG",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["1866 Slug"]) do
if weaponName == weaponData[2] then
return "1866 Slug",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["SPAZ-12 Pellet"]) do
if weaponName == weaponData[2] then
return "SPAZ-12 Pellet",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["2Rnd. Slug"]) do
if weaponName == weaponData[2] then
return "2Rnd. Slug",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["CZ550 Mag"]) do
if weaponName == weaponData[2] then
return "CZ550 Mag",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["Lee Enfield Mag"]) do
if weaponName == weaponData[2] then
return "Lee Enfield Mag",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["M136 Rocket"]) do
if weaponName == weaponData[2] then
return "M136 Rocket",weaponData[2]
end
end
end
function weaponSwitch (weapon)
if source == getLocalPlayer() then
local ammoName,_ = getWeaponAmmoType2 (weapon)
if getElementData(getLocalPlayer(),ammoName) > 0 then
setElementData(getLocalPlayer(),ammoName,getElementData(getLocalPlayer(),ammoName)-1)
end
end
end
addEventHandler ( "onClientPlayerWeaponFire", getLocalPlayer(), weaponSwitch )
function getWeaponAmmoType (weaponName,notOthers)
if not notOthers then
for i,weaponData in ipairs(weaponAmmoTable["others"]) do
if weaponName == weaponData[1] then
return weaponData[1],weaponData[2]
end
end
end
for i,weaponData in ipairs(weaponAmmoTable["M1911 Mag"]) do
if weaponName == weaponData[1] then
return "M1911 Mag",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["M9 SD Mag"]) do
if weaponName == weaponData[1] then
return "M9 SD Mag",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable[".45ACP"]) do
if weaponName == weaponData[1] then
return ".45ACP",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["PDW Mag"]) do
if weaponName == weaponData[1] then
return "PDW Mag",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["MP5A5 Mag"]) do
if weaponName == weaponData[1] then
return "MP5A5 Mag",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["AK"]) do
if weaponName == weaponData[1] then
return "AK",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["STANAG"]) do
if weaponName == weaponData[1] then
return "STANAG",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["1866 Slug"]) do
if weaponName == weaponData[1] then
return "1866 Slug",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["2Rnd. Slug"]) do
if weaponName == weaponData[1] then
return "2Rnd. Slug",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["SPAZ-12 Pellet"]) do
if weaponName == weaponData[1] then
return "SPAZ-12 Pellet",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["CZ550 Mag"]) do
if weaponName == weaponData[1] then
return "CZ550 Mag",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["Lee Enfield Mag"]) do
if weaponName == weaponData[1] then
return "Lee Enfield Mag",weaponData[2]
end
end
for i,weaponData in ipairs(weaponAmmoTable["M136 Rocket"]) do
if weaponName == weaponData[1] then
return "M136 Rocket",weaponData[2]
end
end
return false
end
function createItemPickup(item,x,y,z,tableStringName)
if item and x and y and z then
local object = createObject(itemTable[tostring(tableStringName)][item][2],x,y,z-0.875,itemTable[tostring(tableStringName)][item][4],0,math.random(0,360))
setObjectScale(object,itemTable[tostring(tableStringName)][item][3])
setElementCollisionsEnabled(object, false)
setElementFrozen (object,true)
local col = createColSphere(x,y,z,0.75)
setElementData(col,"item",itemTable[tostring(tableStringName)][item][1])
setElementData(col,"parent",object)
setTimer(function()
if isElement(col) then
destroyElement(col)
destroyElement(object)
end
end,900000,1)
return object
end
end
function table.size(tab)
local length = 0
for _ in pairs(tab) do length = length + 1 end
return length
end
function math.percentChance (percent,repeatTime)
local hits = 0
for i = 1, repeatTime do
local number = math.random(0,200)/2
if number <= percent then
hits = hits+1
end
end
return hits
end
function createItemLoot (lootPlace,x,y,z,id)
col = createColSphere(x,y,z,1.25)
setElementData(col,"itemloot",true)
setElementData(col,"parent",lootPlace)
setElementData(col,"MAX_Slots",12)
--Items
for i, item in ipairs(itemTable[lootPlace]) do
local value = math.percentChance (item[5],math.random(1,2))
setElementData(col,item[1],value)
--weapon Ammo
local ammoData,weapID = getWeaponAmmoType (item[1],true)
if ammoData and value > 0 then
setElementData(col,ammoData,math.random(1,2))
end
end
--itemLoot
refreshItemLoot (col,lootPlace)
code
return col
end
function refreshItemLoot (col,place)
local objects = getElementData(col,"objectsINloot")
if objects then
if objects[1] ~= nil then
destroyElement(objects[1])
end
if objects[2] ~= nil then
destroyElement(objects[2])
end
if objects[3] ~= nil then
destroyElement(objects[3])
end
end
--setting objects
local counter = 0
local obejctItem = {}
--Tables
for i, item in ipairs(itemTable["other"]) do
if getElementData(col,item[1]) and getElementData(col,item[1]) > 0 then
if counter == 3 then
break
end
counter = counter + 1
local x,y,z = getElementPosition(col)
obejctItem[counter] = createObject(item[2],x+math.random(-1,1),y+math.random(-1,1),z-0.875,item[4])
setObjectScale(obejctItem[counter],item[3])
setElementCollisionsEnabled(obejctItem[counter], false)
setElementFrozen (obejctItem[counter],true)
end
end
-------Debug
if obejctItem[1] == nil then
local x,y,z = getElementPosition(col)
obejctItem[1] = createObject(1463,x+math.random(-1,1),y+math.random(-1,1),z-0.875,0)
setObjectScale(obejctItem[1],0)
setElementCollisionsEnabled(obejctItem[1], false)
setElementFrozen (obejctItem[1],true)
end
if obejctItem[2] == nil then
local x,y,z = getElementPosition(col)
obejctItem[2] = createObject(1463,x+math.random(-1,1),y+math.random(-1,1),z-0.875,0)
setObjectScale(obejctItem[2],0)
setElementCollisionsEnabled(obejctItem[2], false)
setElementFrozen (obejctItem[2],true)
end
if obejctItem[3] == nil then
local x,y,z = getElementPosition(col)
obejctItem[3] = createObject(1463,x+math.random(-1,1),y+math.random(-1,1),z-0.875,0)
setObjectScale(obejctItem[3],0)
setElementCollisionsEnabled(obejctItem[3], false)
setElementFrozen (obejctItem[3],true)
end
setElementData(col,"objectsINloot",{obejctItem[1], obejctItem[2], obejctItem[3]})
end
addEvent( "refreshItemLoot", true )
addEventHandler( "refreshItemLoot", getRootElement(), refreshItemLoot )
function createPickupsOnServerStart()
iPickup = 0
for i,pos in ipairs(pickupPositions["residential"]) do
iPickup = iPickup + 1
createItemLoot("residential",pos[1],pos[2],pos[3],iPickup)
end
setTimer(createPickupsOnServerStart2,5000,1)
end
function createPickupsOnServerStart2()
for i,pos in ipairs(pickupPositions["industrial"]) do
iPickup = iPickup + 1
createItemLoot("industrial",pos[1],pos[2],pos[3],iPickup)
end
setTimer(createPickupsOnServerStart3,5000,1)
end
function createPickupsOnServerStart3()
for i,pos in ipairs(pickupPositions["farm"]) do
iPickup = iPickup + 1
createItemLoot("farm",pos[1],pos[2],pos[3],iPickup)
end
setTimer(createPickupsOnServerStart4,5000,1)
end
function createPickupsOnServerStart4()
for i,pos in ipairs(pickupPositions["supermarket"]) do
iPickup = iPickup + 1
createItemLoot("supermarket",pos[1],pos[2],pos[3],iPickup)
end
setTimer(createPickupsOnServerStart5,5000,1)
end
function createPickupsOnServerStart5()
for i,pos in ipairs(pickupPositions["military"]) do
iPickup = iPickup + 1
createItemLoot("military",pos[1],pos[2],pos[3],iPickup)
end
end
function getVehicleMaxFuel(loot)
local modelID = getElementModel(getElementData(loot,"parent"))
for i,vehicle in ipairs(vehicleFuelTable) do
if modelID == vehicle[1] then
return vehicle[2]
end
end
return false
end
function onPlayerTakeItemFromGround (itemName,col)
itemPlus = 1
if itemName == "M1911 Mag" then
itemPlus = 7
elseif itemName == "M9 SD Mag" then
itemPlus = 15
elseif itemName == ".45ACP" then
itemPlus = 7
elseif itemName == "PDW Mag" then
itemPlus = 30
elseif itemName == "MP5A5 Mag" then
itemPlus = 20
elseif itemName == "AK" then
itemPlus = 30
elseif itemName == "STANAG" then
itemPlus = 20
elseif itemName == "1866 Slug" then
itemPlus = 7
elseif itemName == "2Rnd. Slug" then
itemPlus = 2
elseif itemName == "SPAZ-12 Pellet" then
itemPlus = 7
elseif itemName == "CZ550 Mag" then
itemPlus = 5
elseif itemName == "Lee Enfield Mag" then
itemPlus = 10
elseif itemName == "M136 Rocket" then
itemPlus = 0
elseif itemName == "М4А1 CCO" or itemName == "AK-74" or itemName == "CZ550" or itemName == "Винчестер 1866" or itemName == "SPAZ-12 Combat Shotgun" or itemName == "Sawn-Off Shotgun" or itemName == "Heat-Seeking RPG" or itemName == "M136 Rocket Launcher" or itemName == "Lee Enfield" then
removeBackWeaponOnDrop()
end
local x,y,z = getElementPosition(source)
local id,ItemType = getItemTablePosition (itemName)
setElementData(source,itemName,(getElementData(source,itemName) or 0)+itemPlus)
destroyElement(getElementData(col,"parent"))
destroyElement(col)
end
addEvent( "onPlayerTakeItemFromGround", true )
addEventHandler( "onPlayerTakeItemFromGround", getRootElement(), onPlayerTakeItemFromGround )
function onPlayerChangeLoot(loot)
local players = getElementsWithinColShape (loot,"player")
for theKey,player in ipairs(players) do
triggerClientEvent(player,"refreshLootManual",player,loot)
end
end
addEvent( "onPlayerChangeLoot", true )
addEventHandler( "onPlayerChangeLoot", getRootElement(), onPlayerChangeLoot )
function playerDropAItem(itemName)
local x,y,z = getElementPosition(source)
local item,itemString = getItemTablePosition(itemName)
local itemPickup = createItemPickup(item,x+math.random(-1.25,1.25),y+math.random(-1.25,1.25),z,itemString)
end
addEvent( "playerDropAItem", true )
addEventHandler( "playerDropAItem", getRootElement(), playerDropAItem )
function getItemTablePosition (itema)
for id, item in ipairs(itemTable[tostring("other")]) do
if itema == item[1] then
return id,"other"
end
end
code
return item,itemString
end
function refreshItemLoots ()
outputChatBox("#ffaa00Внимание! #ffffff - Респавн лута! Просим не выходить с сервера во время NETWORK!",getRootElement(),255,255,255,true)
for i, loots in ipairs(getElementsByType("colshape")) do
local itemloot = getElementData(loots,"itemloot")
if itemloot then
local objects = getElementData(loots,"objectsINloot")
if objects then
if objects[1] ~= nil then
destroyElement(objects[1])
end
if objects[2] ~= nil then
destroyElement(objects[2])
end
if objects[3] ~= nil then
destroyElement(objects[3])
end
end
destroyElement(loots)
end
end
createPickupsOnServerStart()
setTimer(refreshItemLootPoints,gameplayVariables["itemrespawntimer"] ,1)
end
--Refresh items
function refreshItemLootPoints ()
local time = getRealTime()
local hour = time.hour
outputChatBox("#ff2200Внимание! #ffffff - Через 1 мин будет респавн лута!",getRootElement(),255,255,255,true)
setTimer(refreshItemLoots,60000,1)
end
setTimer(refreshItemLootPoints,gameplayVariables["itemrespawntimer"] ,1)
Напиши на основе двух этих скриптов инвентаря и предметов, логику крафта, чтоб меню крафта открывалось в GUI окне по команде /craft. Для примера можно сделать крафт предмета "Аптечка" из одного "Бинт" и одного "Болеутоляющего". Напиши полностью логику и выдай в виде кода!
Для создания системы крафта мы будем использовать некоторые из предоставленных функций, переменных и элементов GUI из инвентаря и предметов. Ниже приведен код, который необходимо добавить в ресурс DayZ для создания меню крафта, которое будет открываться по команде /craft.
Начнем с самой команды:
lua
-- Функция команды /craft, которая открывает меню крафта
function openCraftMenuCommand(player)
triggerClientEvent(player, "onPlayerOpenCraftMenu", player)
end
addCommandHandler("craft", openCraftMenuCommand)
Следующим шагом будет создание клиентского события и функции, которая показывает GUI меню крафта:
lua
-- Событие запускаемое на клиенте для открытия GUI меню крафта
addEvent("onPlayerOpenCraftMenu", true)
addEventHandler("onPlayerOpenCraftMenu", root, function()
local windowWidth, windowHeight = 0.3, 0.2
local screenWidth, screenHeight = guiGetScreenSize()
local windowX, windowY = (screenWidth - windowWidth * screenWidth) / 2, (screenHeight - windowHeight * screenHeight) / 2
-- Создаем окно для крафта
local craftWindow = guiCreateWindow(windowX, windowY, windowWidth * screenWidth, windowHeight * screenHeight, "Меню крафта", true)
-- Создаем кнопку для крафта аптечки
local craftButton = guiCreateButton(0.1, 0.5, 0.8, 0.2, "Сделать Аптечку", true, craftWindow)
-- Событие нажатия на кнопку крафта
addEventHandler("onClientGUIClick", craftButton, function(button, state)
if button == "left" and state == "up" then
-- Отправляем серверу запрос на крафт аптечки
triggerServerEvent("onPlayerCraftItem", localPlayer, "Аптечка")
end
end, false)
-- Показываем курсор и GUI
showCursor(true)
guiSetVisible(craftWindow, true)
-- Событие закрытия окна крафта
addEventHandler("onClientGUIDoubleClick", craftWindow, function()
destroyElement(craftWindow)
showCursor(false)
end, false)
end)
Теперь нам нужно обработать событие крафта аптечки на сервере:
lua
-- Серверное событие при запросе крафта аптечки
addEvent("onPlayerCraftItem", true)
addEventHandler("onPlayerCraftItem", root, function(itemName)
if itemName == "Аптечка" then
-- Проверяем, есть ли у игрока необходимые предметы
if getElementData(source, "Бинт") and getElementData(source, "Болеутоляющие") then
if getElementData(source, "Бинт") >= 1 and getElementData(source, "Болеутоляющие") >= 1 then
-- Уменьшаем количество предметов на 1
setElementData(source, "Бинт", getElementData(source, "Бинт") - 1)
setElementData(source, "Болеутоляющие", getElementData(source, "Болеутоляющие") - 1)
-- Добавляем аптечку
setElementData(source, "Аптечка", (getElementData(source, "Аптечка") or 0) + 1)
-- Обновляем инвентарь на клиенте
triggerClientEvent(source, "refreshInventoryManual", source)
outputChatBox("Вы сделали Аптечку", source, 0, 255, 0)
else
outputChatBox("У вас недостаточно предметов для крафта Аптечки", source, 255, 0, 0)
end
else
outputChatBox("У вас нет необходимых предметов для крафта Аптечки", source, 255, 0, 0)
end
end
end)
Эти фрагменты кода отражают базовую логику крафта в вашем инвентаре LUA и создают простое GUI окно для крафта аптечек из бинтов и болеутоляющих. Обратите внимание, что для работы кода необходимо добавить соответствующие триггеры и обработчики событий на сервер и клиент. Этот код может быть расширен для включения дополнительных рецептов крафта и логики взаимодействия.