Szerző Téma: Fegyver attach a hátra  (Megtekintve 1505 alkalommal)

Fegyver attach a hátra
« Dátum: 2017. Április 17. - 14:56:24 »
0
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)

 
 

Fegyver attach a hátra
« Válasz #1 Dátum: 2017. Április 17. - 15:07:37 »
0
Telorol vok, de hiányol egy táblát.

Fegyver attach a hátra
« Válasz #2 Dátum: 2017. Április 17. - 15:17:29 »
0
Ahol az errort írta hozzáírtam egy ilyet:
 

function updatePlayerWeapons()
    triggerServerEvent(\"getPlayerItems\", localPlayer, localPlayer)
    setTimer(function()
        for k, v in pairs(exports[\'mta_item\']:getPlayeritems(localPlayer)) do <--- itt írta a hibát
            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

 
Az errort már nem írja viszont nem látszik a fegyver a háton
« Utoljára szerkesztve: 2017. Április 17. - 15:18:10 írta Chad12341 »

Fegyver attach a hátra
« Válasz #3 Dátum: 2017. Április 17. - 15:22:12 »
0
Oda valami currentInvertory kell, de igy telorol nem tudok sokat segiteni.

Fegyver attach a hátra
« Válasz #4 Dátum: 2017. Április 17. - 15:24:08 »
0
A currentInventory-val írta ki az errort

Fegyver attach a hátra
« Válasz #5 Dátum: 2017. Április 17. - 15:55:14 »
+1
External. Mit vársz?

Fegyver attach a hátra
« Válasz #6 Dátum: 2017. Április 17. - 15:56:24 »
0
A Double MTA is ugyan ilyen rendszerrel használja csak nem az inventoryba van beleépítve hanem külön resource-ba és exportálja az item-systemet, de viszont ha úgy próbálom meg akkor sem látszik a hátán a fegyver.

Fegyver attach a hátra
« Válasz #7 Dátum: 2017. Április 17. - 16:00:35 »
0
Mert a double \"rendszere\" a HL-é. 

Fegyver attach a hátra
« Válasz #8 Dátum: 2017. Április 17. - 16:07:30 »
0
...és a HL verzió ami kint van az nagyon, nagyon buggos, de ezt már @Xenius is sokszor leírta.

Fegyver attach a hátra
« Válasz #9 Dátum: 2017. Április 17. - 16:11:07 »
+1
De még mindig jobb bug-osan, mint az External. :D

Fegyver attach a hátra
« Válasz #10 Dátum: 2017. Április 17. - 16:46:57 »
0
Semelyik se jobb :D

Fegyver attach a hátra
« Válasz #11 Dátum: 2017. Április 17. - 17:29:26 »
0
És azzal mit lehet kezdeni hogy látszódjon a háton? hogyha már nem errorozik

Nem elérhető Eduka

  • 214
    • Profil megtekintése
Fegyver attach a hátra
« Válasz #12 Dátum: 2017. Április 18. - 16:10:38 »
0
Mondjuk írd meg magadnak? Akkor te magad tudod az egésznek a felépítését és nem lesz ilyen problémád.

Nem elérhető Xenius

  • 668
    • Profil megtekintése
Fegyver attach a hátra
« Válasz #13 Dátum: 2017. Április 21. - 20:11:38 »
0
Ez most really? Ez az én HL-es scriptem amit még 2014-ben írtam. Pofátlan tolvaj banda, még a copyrightot is kiszedték az elejéből.
« Utoljára szerkesztve: 2017. Április 21. - 20:12:24 írta Xenius »

Fegyver attach a hátra
« Válasz #14 Dátum: 2017. Április 21. - 20:16:22 »
+2
@Xenius Ezt írtam, a Double vallhalla és HL keverék...

 

SimplePortal 2.3.7 © 2008-2024, SimplePortal