Sziasztok, az External 2017.01.10_1.-ei kipublikált modban van az item-systemben egy weapon attach script, egyetlen egy errort ír a debugscript, valamint meg sem jelenik a háton egyik fegyver sem. Ha valaki tudna segíteni hogy mi lehet a probléma akkor megköszönném!
ERROR:mta_item\\weapon_client.lua:302: bad argument #1 to \'pairs\' (table expected, got nil)
local objs = {}
local playerCache = {}
local pedsToAttached = {}
local weaponModels = {
--- uzi, mp3, tec9
[28] = 352,
[29] = 353,
[32] = 372,
--- deagle
[24] = 348,
--- shotgunok
[25] = 349,
[26] = 350,
[27] = 351,
--- nagykaliber
[30] = 355,
[31] = 356,
--- ütőfegyverek
--[2] = 333,
[5] = 336,
--[6] = 337,
--[7] = 338,
--[8] = 339,
--- sniper
[33] = 357,
[34] = 358,
}
local attachedRootCache = {}
local pedWeapons = {}
function isInTable(ped, wep)
if pedWeapons[ped] then
for k, v in ipairs(pedWeapons[ped]) do
if v == wep then
return true, k
end
end
end
return false
end
function addWep(ped, wep)
if not pedWeapons[ped] then
pedWeapons[ped] = {}
end
table.insert(pedWeapons[ped], wep)
end
function attachWeaponToBone(ped, wep, walkingstyle)
if weaponModels[wep] then
if not objs[ped] then
objs[ped] = {}
end
if isInTable(ped, wep) then return end
local this = #objs[ped]+1
objs[ped][this] = createObject(weaponModels[wep], 0, 0, 0)
setElementData(objs[ped][this], \"wep\", wep)
setElementData(objs[ped][this], \"owner\", ped)
if not pedsToAttached[ped] then
pedsToAttached[ped] = {}
end
if not attachedRootCache[ped] then
attachedRootCache[ped] = {}
end
table.insert(attachedRootCache[ped], {wep, objs[ped][this]})
local newKey = #pedsToAttached[ped]
pedsToAttached[ped][newKey] = objs[ped][this]
if wep == 29 or wep == 28 then
exports.bone_attach:attachElementToBone(objs[ped][this], ped, 14, 0.1, 0.05, 0, 0, -90, 90)
elseif wep == 16 or wep == 17 or wep == 18 then
exports.bone_attach:attachElementToBone(objs[ped][this], ped, 14, 0.15, -0.1, 0.2, 0, 0, 90)
elseif wep == 32 then
exports.bone_attach:attachElementToBone(objs[ped][this], ped, 14, 0.12, 0.05, 0, 0, -90, 90)
elseif wep == 22 or wep == 23 or wep == 24 then
exports.bone_attach:attachElementToBone(objs[ped][this], ped, 13, -0.06, 0.05, 0, 0, -90, 90)
elseif wep == 4 then
exports.bone_attach:attachElementToBone(objs[ped][this], ped, 13, -0.035, -0.1, 0.3, 0, 0, 90)
elseif wep == 27 or wep == 26 or wep == 25 then
if walkingstyle == 131 or walkingstyle == 132 or walkingstyle == 133 or walkingstyle == 129 or walkingstyle == 126 or walkingstyle == 121 or walkingstyle == 122 or walkingstyle == 124 then
exports.bone_attach:attachElementToBone(objs[ped][this], ped, 5, 0.16, 0, 0.1, 190, 30, -90)
elseif walkingstyle == 125 then
exports.bone_attach:attachElementToBone(objs[ped][ped][this], ped, 5, 0.16, 0, 0.1, 190, 30, -105)
else
exports.bone_attach:attachElementToBone(objs[ped][this], ped, 5, 0.16, 0, 0.1, 190, 20, -110)
end
elseif wep == 33 or wep == 34 then
if walkingstyle == 131 or walkingstyle == 132 or walkingstyle == 133 or walkingstyle == 129 or walkingstyle == 126 or walkingstyle == 121 or walkingstyle == 122 or walkingstyle == 124 then
exports.bone_attach:attachElementToBone(objs[ped][this], ped, 5, 0.16, 0, 0.1, 190, 30, -90)
elseif walkingstyle == 125 then
exports.bone_attach:attachElementToBone(objs[ped][ped][this], ped, 5, 0.16, 0, 0.1, 190, 30, -105)
else
exports.bone_attach:attachElementToBone(objs[ped][this], ped, 5, 0.16, 0, 0.1, 190, 20, -110)
end
elseif wep == 30 then
if walkingstyle == 131 or walkingstyle == 132 or walkingstyle == 133 or walkingstyle == 129 or walkingstyle == 126 or walkingstyle == 121 or walkingstyle == 122 or walkingstyle == 124 then
exports.bone_attach:attachElementToBone(objs[ped][this], ped, 6, -0.08, -0.1, 0.2, 10, 165, 82)
elseif walkingstyle == 125 then
exports.bone_attach:attachElementToBone(objs[ped][this], ped, 6, -0.08, -0.1, 0.2, 10, 165, 92)
else
exports.bone_attach:attachElementToBone(objs[ped][this], ped, 6, -0.05, -0.1, 0.2, 10, 165, 95)
end
elseif wep == 31 then
if walkingstyle == 131 or walkingstyle == 132 or walkingstyle == 133 or walkingstyle == 129 or walkingstyle == 126 or walkingstyle == 121 or walkingstyle == 122 or walkingstyle == 124 then
exports.bone_attach:attachElementToBone(objs[ped][this], ped, 6, -0.15, -0.1, -0.2, 185, 145, 82)
elseif walkingstyle == 125 then
exports.bone_attach:attachElementToBone(objs[ped][this], ped, 6, -0.15, -0.1, -0.2, 185, 145, 92)
else
exports.bone_attach:attachElementToBone(objs[ped][this], ped, 6, -0.12, -0.1, -0.2, 185, 145, 95)
end
elseif wep >= 2 and wep <= 8 and wep ~= 4 then
if walkingstyle == 131 or walkingstyle == 132 or walkingstyle == 133 or walkingstyle == 129 or walkingstyle == 126 or walkingstyle == 121 or walkingstyle == 122 or walkingstyle == 124 then
exports.bone_attach:attachElementToBone(objs[ped][this], ped, 6, -0.08, 0, -0.02, 0, -90, 82)
elseif walkingstyle == 125 then
exports.bone_attach:attachElementToBone(objs[ped][this], ped, 6, -0.08, 0, -0.02, 10, -90, 92)
else
exports.bone_attach:attachElementToBone(objs[ped][this], ped, 6, -0.08, 0, -0.02, 10, -90, 100)
end
end
end
end
addEvent(\"attachWeaponToBody\", true)
addEventHandler(\"attachWeaponToBody\", root, function(player, wep)
if not playerCache[player] then
playerCache[player] = {}
end
if not playerCache[player][wep] then
playerCache[player][wep] = true
end
if isElementStreamedIn(player) then
if not isInTable(player, wep) then
attachWeaponToBone(player, wep, getPedWalkingStyle(player))
addWep(player, wep)
end
end
end)
addEvent(\"removeWeaponFromBone\", true)
addEventHandler(\"removeWeaponFromBone\", root, function(player, wep)
if playerCache[player] then
if playerCache[player][wep] then
local tbl, key = isInTable(player, wep)
if tbl then
pedWeapons[player][key] = nil
end
if attachedRootCache[player] then
for k, v in pairs(attachedRootCache[player]) do
if v[1] == wep and isElement(v[2]) then
exports.bone_attach:detachElementFromBone(v[2])
destroyElement(v[2])
attachedRootCache[player][k] = nil
end
end
end
playerCache[player][wep] = nil
end
end
end)
addEventHandler(\"onClientElementDataChange\", root, function(dataName)
if source and dataName == \"char:adminduty\" then
if getElementData(source, dataName) == 1 then
if getElementType(source) == \"player\" then
if objs[source] then
for k, v in ipairs(objs[source]) do
if isElement(v) then
destroyElement(v)
exports.bone_attach:detachElementFromBone(v)
end
end
end
objs[source] = {}
pedWeapons[source] = {}
end
else
if getElementType(source) == \"player\" then
if playerCache[source] then
for wep, _ in pairs(playerCache[source]) do
if not isInTable(player, wep) then
attachWeaponToBone(source, wep, getPedWalkingStyle(source))
addWep(source, wep)
end
end
end
end
end
end
end)
--if getElementData(value, \"char:weaponInHand\")[1] or -1 > 0 then
--if getWeaponModel(items[getElementData(value, \"char:weaponInHand\")[1] ][5]) ~= getElementModel(weapon) then
addEventHandler(\"onClientElementDataChange\", root, function(dataName)
if source and dataName == \"char:weaponInHand\" then
local weapon = getElementData(source, dataName)[3] or -1
if weapon > 0 then
if objs[source] then
for k, v in ipairs(objs[source]) do
if isElement(v) and getElementModel(v) == weaponModels[weapon] then
setElementAlpha(v, 0)
end
end
end
else
if objs[source] then
for k, v in ipairs(objs[source]) do
if isElement(v) and getElementAlpha(v) == 0 then
setElementAlpha(v, 255)
end
end
end
end
end
end)
addEvent(\"updateWeapons\", true)
addEventHandler(\"updateWeapons\", root, function(player)
if getElementType(player) == \"player\" then
if objs[player] then
for k, v in ipairs(objs[player]) do
if isElement(v) then
destroyElement(v)
exports.bone_attach:detachElementFromBone(v)
end
end
end
objs[player] = {}
pedWeapons[player] = {}
if playerCache[player] then
for wep, _ in pairs(playerCache[player]) do
if not isInTable(player, wep) then
attachWeaponToBone(player, wep, getPedWalkingStyle(player))
addWep(player, wep)
end
end
end
end
end)
addEventHandler(\"onClientElementStreamIn\", root, function()
if getElementType(source) == \"player\" then
if playerCache[source] then
for wep, _ in pairs(playerCache[source]) do
if not isInTable(player, wep) then
attachWeaponToBone(source, wep, getPedWalkingStyle(source))
addWep(source, wep)
end
end
end
end
end)
addEventHandler(\"onClientElementStreamOut\", root, function()
if getElementType(source) == \"player\" then
if objs[source] then
for k, v in ipairs(objs[source]) do
if isElement(v) then
destroyElement(v)
exports.bone_attach:detachElementFromBone(v)
end
end
end
objs[source] = {}
pedWeapons[source] = {}
end
end)
addEvent(\"getPlayerInventory\", true)
addEventHandler(\"getPlayerInventory\", root, function(table)
currentInventory = {}
currentInventory = table
end)
function updatePlayerWeapons()
triggerServerEvent(\"getPlayerItems\", localPlayer, localPlayer)
setTimer(function()
for k, v in pairs(currentInventory) do
local item = v[1]
local weaponID = getWeaponID(item) or 0
if weaponID > 0 and not isInTable(localPlayer, weaponID) then
triggerServerEvent(\"attachWeapon\", localPlayer, localPlayer, weaponID)
end
end
end, 300, 1)
end
addEventHandler(\"onClientResourceStart\", resourceRoot, function()
if getElementData(localPlayer, \"loggedin\") then
updatePlayerWeapons()
end
triggerServerEvent(\"getAllWeaponCache\", localPlayer)
end)
addEvent(\"receiveWeaponCache\", true)
addEventHandler(\"receiveWeaponCache\", root, function(data)
for k, v in pairs(data) do
if isElement(k) and k ~= localPlayer then
playerCache[v] = {}
for wep,_ in pairs(v) do
playerCache[v][wep] = true
if isElementStreamedIn(k) then
if not isInTable(k, wep) then
attachWeaponToBone(k, wep, getPedWalkingStyle(k))
addWep(k, wep)
end
end
end
end
end
end)
addEventHandler(\"onClientPlayerQuit\", getRootElement(), function()
if objs[source] then
for k, v in ipairs(objs[source]) do
if isElement(v) then
destroyElement(v)
exports.bone_attach:detachElementFromBone(v)
end
end
end
playerCache[source] = nil
pedWeapons[source] = nil
objs[source] = nil
end)