Jump to content

createMarker retornando erro attemp to index upvalue 'Random_Pos' <a number value>


Recommended Posts

marker_aleatoriosS = {
    1872.08, -1308.8, 18.147,
    1893.097, -1314.732, 23.151,
    1892.831, -1316.274, 28.152,
    1872.101, -1317.594, 33.147,
    1876.034, -1321.604, 38.147,
    1876.088, -1309.743, 43.147,
    1873.865, -1322.412, 48.069,
    --Para não pegar repetido 
    1872.08, -1308.8, 18.147,
    1893.097, -1314.732, 23.151,
    1892.831, -1316.274, 28.152,
    1872.101, -1317.594, 33.147,
    1876.034, -1321.604, 38.147,
    1876.088, -1309.743, 43.147,
    1873.865, -1322.412, 48.069,
}

Object_ferro = {}
marker_EntregarS = {}
--ID do objeto barra de ferro 2960
function pegarFerroS(player,cmd)
    local x, y, z = getElementPosition(marker_ferro)
    local Random_Pos = math.random(#marker_aleatoriosS)
        if not isPedInVehicle(player) then 
            if isElementWithinMarker(player, marker_ferro) then
            if getElementData(player, "Ferro") == false then
                if getElementData(player, "Pedreiro") == true then
                    setPedAnimation(player, "CARRY", "liftup", 1.0, false)
                    setTimer(function()
                        if isElement(Object_ferro[player]) then destroyElement(Object_ferro[player]) end
                        if isElement(marker_EntregarS[player]) then destroyElement(marker_EntregarS) end
                        setElementData(player, "Recompensa", 0)
                        setPedAnimation(player, nil)
                        setElementData(player, "Ferro", true)
                        toggleControl(player, "jump", false)
                        toggleControl(player, "fire", false)
                        toggleControl(player, "aim_weapon", false)
                        setPedAnimation( player, "CARRY", "crry_prtial", 4.1, true, true, true )
                        marker_EntregarS[player] = createMarker ( marker_aleatoriosS[Random_Pos][1], marker_aleatoriosS[Random_Pos][2], marker_aleatoriosS[Random_Pos][3] -2.2, "cylinder", 2.5, 16, 111, 231, 50)
                        setElementVisibleTo(marker_EntregarS, root, false)
                        setElementVisibleTo(marker_EntregarS, player, true)
                        addEventHandler("onMarkerHit", marker_EntregarS[player], fim_Emprego)
                        Object_ferro[player] = createObject(2960, x, y, z)
                        exports.bone_attach:attachElementToBone(Object_ferro[player], player, 4, 0, 0.4, - 0.6, -90, 0, 0 )
                    end, 1000,1)
                end
            end
        end
    end
end
addCommandHandler("ferro", pegarFerroS)

Essa função está retornando erro no createMarker attemp to index upvalue 'Random_Pos' <a number value> não encontrei aonde está meu erro.

Link to post
marker_aleatoriosS = {
    {1872.08, -1308.8, 18.147},
    {1893.097, -1314.732, 23.151},
    {1892.831, -1316.274, 28.152},
    {1872.101, -1317.594, 33.147},
    {1876.034, -1321.604, 38.147},
    {1876.088, -1309.743, 43.147},
    {1873.865, -1322.412, 48.069},
    --Para não pegar repetido 
    {1872.08, -1308.8, 18.147},
    {1893.097, -1314.732, 23.151},
    {1892.831, -1316.274, 28.152},
    {1872.101, -1317.594, 33.147},
    {1876.034, -1321.604, 38.147},
    {1876.088, -1309.743, 43.147},
    {1873.865, -1322.412, 48.069},
}

Object_ferro = {}
marker_EntregarS = {}
--ID do objeto barra de ferro 2960

	
function pegarFerroS(player,cmd)
    local x, y, z = getElementPosition(marker_ferro)
    local Random_Pos = math.random(#marker_aleatoriosS)
        if not isPedInVehicle(player) then 
            if isElementWithinMarker(player, marker_ferro) then
            if getElementData(player, "Ferro") == false then
                if getElementData(player, "Pedreiro") == true then
                    setPedAnimation(player, "CARRY", "liftup", 1.0, false)
                    setTimer(function()
                        if isElement(Object_ferro[player]) then destroyElement(Object_ferro[player]) end
                        if isElement(marker_EntregarS[player]) then destroyElement(marker_EntregarS) end
                        setElementData(player, "Recompensa", 0)
                        setPedAnimation(player, nil)
                        setElementData(player, "Ferro", true)
                        toggleControl(player, "jump", false)
                        toggleControl(player, "fire", false)
                        toggleControl(player, "aim_weapon", false)
                        setPedAnimation( player, "CARRY", "crry_prtial", 4.1, true, true, true )
                        marker_EntregarS[player] = createMarker ( marker_aleatoriosS[Random_Pos][1], marker_aleatoriosS[Random_Pos][2], marker_aleatoriosS[Random_Pos][3] -2.2, "cylinder", 2.5, 16, 111, 231, 50)
                        setElementVisibleTo(marker_EntregarS, root, false)
                        setElementVisibleTo(marker_EntregarS, player, true)
                        addEventHandler("onMarkerHit", marker_EntregarS[player], fim_Emprego)
                        Object_ferro[player] = createObject(2960, x, y, z)
                        exports.bone_attach:attachElementToBone(Object_ferro[player], player, 4, 0, 0.4, - 0.6, -90, 0, 0 )
                    end, 1000,1)
                end
            end
        end
    end
end
addCommandHandler("ferro", pegarFerroS)

Sua maneira de tabela estava incorreta, estava pegando a index de uma tabela como essa.

 

{1872.08, -1308.8, 18.147,1893.097, -1314.732, 23.151}

 

  • Thanks 1
Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...