Jump to content

Again, Lua Issue


Recommended Posts

local drivethru = {
    {2376.21, -1908.87, 13.11},
    {2409.42, -1488.03, 23.56},
    {789.30, -1619.01, 13.11}
}

for k,v in ipairs(drivethru) do
    m_dthru = createMarker(v[1], v[2], v[3]-1, "cylinder", 2.0, 255, 255, 0, 200)
    createBlipAttachedTo(m_dthru, 17, 1, r, g, b, a, 0, 300)
    addEventHandler("onMarkerLeave", m_dthru, usunGui, false)
    addEventHandler("onMarkerHit", m_dthru, triggerujKupno, false)
end

function usunGui()
    outputChatBox("test2")
end

function triggerujKupno()
    outputChatBox("test")
end

 

That's error:

Bad argument @ 'addEventHandler' [Expected function at argument 3, got nil]

Please help to me!

Link to comment
1 hour ago, IIYAMA said:

Przesuń linię 14 do 20.

Do linii 6.

 

Przyczyną błędu jest to, że niektóre funkcje nie są jeszcze załadowane przed ich użyciem.

Thanks, it works.  But I have next question - when I enter the marker the text appears twice, and when I go on foot it is ok, how can I deal with it?

Edited by NoviceWithManyProblems
Link to comment

Try this,

local drivethru = {
    {2376.21, -1908.87, 13.11},
    {2409.42, -1488.03, 23.56},
    {789.30, -1619.01, 13.11}
}

function usunGui()
    outputChatBox("test2")
end

function triggerujKupno()
    outputChatBox("test")
end

local index = 1;
local m_dthru = {};

for k,v in ipairs(drivethru) do
    m_dthru[index] = createMarker(v[1], v[2], v[3]-1, "cylinder", 2.0, 255, 255, 0, 200)
    createBlipAttachedTo(m_dthru, 17, 1, r, g, b, a, 0, 300)
    addEventHandler("onMarkerLeave", m_dthru[index], usunGui, false)
    addEventHandler("onMarkerHit", m_dthru[index], triggerujKupno, false)
    index = index + 1;
end

 

Link to comment

Check if this works.

local drivethru = {
    {2376.21, -1908.87, 13.11},
    {2409.42, -1488.03, 23.56},
    {789.30, -1619.01, 13.11}
}

function usunGui()
    outputChatBox("test2")
end

function triggerujKupno()
    outputChatBox("test")
end

local index = 1;
local m_dthru = {};

for k,v in ipairs(drivethru) do
    m_dthru[index] = createMarker(v[1], v[2], v[3]-1, "cylinder", 2.0, 255, 255, 0, 200)
    createBlipAttachedTo(m_dthru, 17, 1, r, g, b, a, 0, 300)
    index = index + 1;
end

addEventHandler("onMarkerHit", root,
    function(hitElement, matchingDimension)
        if (source == m_dthru) then
            if ((getElementType(hitElement) == "vehicle") and matchingDimension) then
                triggerujKupno()
            end
        end
    end
)

addEventHandler("onMarkerLeave", root,
    function(leaveElement, matchingDimension)
        if (source == m_dthru) then
            if ((getElementType(leaveElement) == "vehicle") and matchingDimension) then
            usunGui()
            end
        end
    end
)

 

Link to comment

Line 20: Replace m_dthru with m_dthru[index]. You may also want to make sure that r, g, b, and a are defined, and for the sake of testing, remove -1 from third arg of createMarker, just to make sure that isn't causing any problem.

If it still does not work, try running the script server side. (Don't forget to change the outputChatBox arguments in this case)

Edited by Bilal135
Link to comment

 

10 hours ago, Bilal135 said:

Line 20: Replace m_dthru with m_dthru[index]. You may also want to make sure that r, g, b, and a are defined, and for the sake of testing, remove -1 from third arg of createMarker, just to make sure that isn't causing any problem.

If it still does not work, try running the script server side. (Don't forget to change the outputChatBox arguments in this case)

It doesn't cause any problem, I just did something like that.

    createBlip(v[1], v[2], v[3], 17, 1, r, g, b, a, 0, 320)

Script is on server (before client) side, and still doesn't work.

Blip it is being created right.

Current code:

local drivethru = {
    {2376.21, -1908.87, 13.11},
    {2409.42, -1488.03, 23.56},
    {789.30, -1619.01, 13.11}
}

function usunGui()
    outputChatBox("test2")
end

function triggerujKupno()
    outputChatBox("test")
end

local index = 1;
local m_dthru = {};

for k,v in ipairs(drivethru) do
    m_dthru[index] = createMarker(v[1], v[2], v[3]-1, "cylinder", 4.0, 255, 255, 0, 200)
    createBlip(v[1], v[2], v[3], 17, 1, r, g, b, a, 0, 320)
    index = index + 1;
end

addEventHandler("onMarkerHit", root,
    function(hitElement, matchingDimension)
        if (source == m_dthru) then
            if ((getElementType(hitElement) == "vehicle") and matchingDimension) then
                triggerujKupno()
            end
        end
    end
)

addEventHandler("onMarkerLeave", root,
    function(leaveElement, matchingDimension)
        if (source == m_dthru) then
            if ((getElementType(leaveElement) == "vehicle") and matchingDimension) then
            usunGui()
            end
        end
    end
)

Result in game: https://i.imgur.com/SDJVerr.mp4

Edited by NoviceWithManyProblems
Link to comment

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...