Jump to content

[HELP] BAD ARGUMENT : ADDEVENTHANDLER


Scyrix

Recommended Posts

Posted
function cursorPosition(x, y, w, h) 
    if (not isCursorShowing()) then 
    return false 
    end 
    local mx, my = getCursorPosition() 
    local fullx, fully = guiGetScreenSize() 
    cursorx, cursory = mx*fullx, my*fully 
    if cursorx > x and cursorx < x + w and cursory > y and cursory < y + h then 
    return true 
    else 
    return false 
    end 
    end 

local screenW, screenH = guiGetScreenSize()
guipracka = false
function guiPraca ()
    dxDrawLine((screenW * 0.3792) - 1, (screenH * 0.2833) - 1, (screenW * 0.3792) - 1, screenH * 0.7167, tocolor(0, 0, 0, 255), 1, false)
    dxDrawLine(screenW * 0.6208, (screenH * 0.2833) - 1, (screenW * 0.3792) - 1, (screenH * 0.2833) - 1, tocolor(0, 0, 0, 255), 1, false)
    dxDrawLine((screenW * 0.3792) - 1, screenH * 0.7167, screenW * 0.6208, screenH * 0.7167, tocolor(0, 0, 0, 255), 1, false)
    dxDrawLine(screenW * 0.6208, screenH * 0.7167, screenW * 0.6208, (screenH * 0.2833) - 1, tocolor(0, 0, 0, 255), 1, false)
    dxDrawRectangle(screenW * 0.3792, screenH * 0.2833, screenW * 0.2417, screenH * 0.4333, tocolor(0, 24, 254, 15), false)
    dxDrawText("Praca Rybaka", screenW * 0.4193, screenH * 0.3120, screenW * 0.5776, screenH * 0.3639, tocolor(255, 255, 255, 255), 2.00, "default", "center", "top", false, false, false, false, false)
    dxDrawRectangle(screenW * 0.4193, screenH * 0.5167, screenW * 0.1646, screenH * 0.0500, tocolor(126, 126, 127, 224), false)
    dxDrawRectangle(screenW * 0.4193, screenH * 0.5759, screenW * 0.1646, screenH * 0.0500, tocolor(126, 126, 127, 224), false)
    dxDrawText("Rozpocznij prace", screenW * 0.4375, screenH * 0.5231, screenW * 0.5646, screenH * 0.5574, tocolor(255, 255, 255, 255), 1.00, "default", "center", "top", false, false, false, false, false)
    dxDrawText("Anuluj", screenW * 0.4380, screenH * 0.5824, screenW * 0.5651, screenH * 0.6167, tocolor(255, 255, 255, 255), 1.00, "default", "center", "top", false, false, false, false, false)
end
local markerStartRybak = createMarker(1629.55, 582.18, 1.76-1,"cylinder",1.5,255,0,0,255)

addEventHandler("onClientMarkerHit",markerStartRybak,function()
    if guipracka == false then 
        if isElementWithinMarker(localPlayer, markerStartRybak) then
        pokazOkno()
        guipracka = true
        setElementData(localPlayer,"gui:showed",true)
        showCursor(true)
        end
    end

end)



function pokazOkno()
    addEventHandler("onClientRender",root,guiPraca)
end

function zamknijOkno()
    removeEventHandler("onClientRender",root,guiPraca)
end

addEventHandler("onClientClick",getRootElement(),function(button, state)
    if button == "left" and state == "down" and guipracka == true then
        if getElementData(localPlayer,"gui:showed") then
        if cursorPosition(screenW * 0.4193, screenH * 0.5759, screenW * 0.1646, screenH * 0.0500) then
            removeEventHandler("onClientRender",root,guiPraca)
            guipracka = false
            setElementData(localPlayer,"gui:showed",false)
            showCursor(false)
        end
        end
    end
end)


addEventHandler("onClientClick",getRootElement(),function(button, state)
    if button == "left" and state == "down" and guipracka == true then
        if getElementData(localPlayer,"gui:showed",true) then
        if cursorPosition(screenW * 0.4193, screenH * 0.5167, screenW * 0.1646, screenH * 0.0500) then
        removeEventHandler("onClientRender",root,guiPraca)
        showCursor(false)
        setElementData(localPlayer,"player:working",true)
        setElementData(localPlayer,"gui:showed",false)
        end
    end
    end
end)


local markery = {
    
    {1633.33, 589.55, 1.76-1},
    {1622.88, 583.13, 1.76-1},

}

for _,v in ipairs(markery) do
    if getElementData(localPlayer,"player:working") == true then
    markerpraca = createMarker(v[1],v[2],v[3],"cylinder",2.0,255,255,255)
    end
end
addEventHandler("onClientMarkerHit",markerpraca,function(hitElement)
    if getElementData(localPlayer,"player:working") == true then
        setElementData(localPlayer,"player:working", false) 
        setElementData(localPlayer,"player:fishing",true)
        setElementFrozen(hitElement,true)
        triggerServerEvent("Lowienie",localPlayer,localPlayer)
    end
    setTimer(function()
            rnd = math.random(10,20)
            triggerServerEvent("givePlayerMoney",localPlayer,rnd)
            outputChatBox("Otrzymujesz"..rnd.. "PLN za zlowiona rybke",0,255,0)
            setElementFrozen(hitElement,false)
            triggerServerEvent("StopLowienie",localPlayer,localPlayer)
            setElementData(localPlayer,"player:fishing",false)
     end ,5000,1)
end)

WARNING : Bad argument addEventHandler : Expected element at argument 2 got nil

(WARNING LINE : 93 ) at the bottom

So my idea was to create a fishing job. I wanted the to make dxGui on which client clicks it shows randomly 2 markers that are in the table

 "markery" and after hitting that marker the player starts fishing ( Animation , and the timer starts ) but it does'nt really work the way i wanted to work as it shows the warning and the markers are showing after i click on the "rozpocznij prace " and then restart the script. Please help I'm starting with Lua and i went straight into it too fast. 

 

Posted
function cursorPosition(x, y, w, h) 
    if (not isCursorShowing()) then 
    return false 
    end 
    local mx, my = getCursorPosition() 
    local fullx, fully = guiGetScreenSize() 
    cursorx, cursory = mx*fullx, my*fully 
    if cursorx > x and cursorx < x + w and cursory > y and cursory < y + h then 
    return true 
    else 
    return false 
    end 
    end 

local screenW, screenH = guiGetScreenSize()
guipracka = false
function guiPraca ()
    dxDrawLine((screenW * 0.3792) - 1, (screenH * 0.2833) - 1, (screenW * 0.3792) - 1, screenH * 0.7167, tocolor(0, 0, 0, 255), 1, false)
    dxDrawLine(screenW * 0.6208, (screenH * 0.2833) - 1, (screenW * 0.3792) - 1, (screenH * 0.2833) - 1, tocolor(0, 0, 0, 255), 1, false)
    dxDrawLine((screenW * 0.3792) - 1, screenH * 0.7167, screenW * 0.6208, screenH * 0.7167, tocolor(0, 0, 0, 255), 1, false)
    dxDrawLine(screenW * 0.6208, screenH * 0.7167, screenW * 0.6208, (screenH * 0.2833) - 1, tocolor(0, 0, 0, 255), 1, false)
    dxDrawRectangle(screenW * 0.3792, screenH * 0.2833, screenW * 0.2417, screenH * 0.4333, tocolor(0, 24, 254, 15), false)
    dxDrawText("Praca Rybaka", screenW * 0.4193, screenH * 0.3120, screenW * 0.5776, screenH * 0.3639, tocolor(255, 255, 255, 255), 2.00, "default", "center", "top", false, false, false, false, false)
    dxDrawRectangle(screenW * 0.4193, screenH * 0.5167, screenW * 0.1646, screenH * 0.0500, tocolor(126, 126, 127, 224), false)
    dxDrawRectangle(screenW * 0.4193, screenH * 0.5759, screenW * 0.1646, screenH * 0.0500, tocolor(126, 126, 127, 224), false)
    dxDrawText("Rozpocznij prace", screenW * 0.4375, screenH * 0.5231, screenW * 0.5646, screenH * 0.5574, tocolor(255, 255, 255, 255), 1.00, "default", "center", "top", false, false, false, false, false)
    dxDrawText("Anuluj", screenW * 0.4380, screenH * 0.5824, screenW * 0.5651, screenH * 0.6167, tocolor(255, 255, 255, 255), 1.00, "default", "center", "top", false, false, false, false, false)
end
local markerStartRybak = createMarker(1629.55, 582.18, 1.76-1,"cylinder",1.5,255,0,0,255)

addEventHandler("onClientMarkerHit",markerStartRybak,function()
    if guipracka == false then 
        if isElementWithinMarker(localPlayer, markerStartRybak) then
        pokazOkno()
        guipracka = true
        setElementData(localPlayer,"gui:showed",true)
        showCursor(true)
        end
    end

end)



function pokazOkno()
    addEventHandler("onClientRender",root,guiPraca)
end

function zamknijOkno()
    removeEventHandler("onClientRender",root,guiPraca)
end

addEventHandler("onClientClick",getRootElement(),function(button, state)
    if button == "left" and state == "down" and guipracka == true then
        if getElementData(localPlayer,"gui:showed") then
        if cursorPosition(screenW * 0.4193, screenH * 0.5759, screenW * 0.1646, screenH * 0.0500) then
            removeEventHandler("onClientRender",root,guiPraca)
            guipracka = false
            setElementData(localPlayer,"gui:showed",false)
            showCursor(false)
        end
        end
    end
end)


addEventHandler("onClientClick",getRootElement(),function(button, state)
    if button == "left" and state == "down" and guipracka == true then
        if getElementData(localPlayer,"gui:showed",true) then
        if cursorPosition(screenW * 0.4193, screenH * 0.5167, screenW * 0.1646, screenH * 0.0500) then
        removeEventHandler("onClientRender",root,guiPraca)
        showCursor(false)
        setElementData(localPlayer,"player:working",true)
        setElementData(localPlayer,"gui:showed",false)
        end
    end
    end
end)


local markery = {
    
    {1633.33, 589.55, 1.76-1},
    {1622.88, 583.13, 1.76-1},

}

for _,v in ipairs(markery) do
    if getElementData(localPlayer,"player:working") == true then
    markerpraca = createMarker(v[1],v[2],v[3],"cylinder",2.0,255,255,255)
    	addEventHandler("onClientMarkerHit",markerpraca,HitFunction)
    end
end

function HitFunction (hitElement)
  if ( hitElement ~= localPlayer ) then return end 
    if getElementData(localPlayer,"player:working") == true then
        setElementData(localPlayer,"player:working", false) 
        setElementData(localPlayer,"player:fishing",true)
        setElementFrozen(hitElement,true)
        triggerServerEvent("Lowienie",localPlayer,localPlayer)
    end
    setTimer(function()
            rnd = math.random(10,20)
            triggerServerEvent("givePlayerMoney",localPlayer,rnd)
            outputChatBox("Otrzymujesz"..rnd.. "PLN za zlowiona rybke",0,255,0)
            setElementFrozen(hitElement,false)
            triggerServerEvent("StopLowienie",localPlayer,localPlayer)
            setElementData(localPlayer,"player:fishing",false)
     end ,5000,1)
end

or you can cahange hitting marker event - argument 2 -> resourceRoot :-) 

Posted (edited)

@Infinity-War

Expected function at argument 3 :( LINE 91 

Markers are not showing after clicking the button .. Have to restart the resoursce for markers to show after clicking that button 

 

Edited by Scyrix
Posted
function cursorPosition(x, y, w, h) 
    if (not isCursorShowing()) then 
    return false 
    end 
    local mx, my = getCursorPosition() 
    local fullx, fully = guiGetScreenSize() 
    cursorx, cursory = mx*fullx, my*fully 
    if cursorx > x and cursorx < x + w and cursory > y and cursory < y + h then 
    return true 
    else 
    return false 
    end 
    end 

local screenW, screenH = guiGetScreenSize()
guipracka = false
function guiPraca ()
    dxDrawLine((screenW * 0.3792) - 1, (screenH * 0.2833) - 1, (screenW * 0.3792) - 1, screenH * 0.7167, tocolor(0, 0, 0, 255), 1, false)
    dxDrawLine(screenW * 0.6208, (screenH * 0.2833) - 1, (screenW * 0.3792) - 1, (screenH * 0.2833) - 1, tocolor(0, 0, 0, 255), 1, false)
    dxDrawLine((screenW * 0.3792) - 1, screenH * 0.7167, screenW * 0.6208, screenH * 0.7167, tocolor(0, 0, 0, 255), 1, false)
    dxDrawLine(screenW * 0.6208, screenH * 0.7167, screenW * 0.6208, (screenH * 0.2833) - 1, tocolor(0, 0, 0, 255), 1, false)
    dxDrawRectangle(screenW * 0.3792, screenH * 0.2833, screenW * 0.2417, screenH * 0.4333, tocolor(0, 24, 254, 15), false)
    dxDrawText("Praca Rybaka", screenW * 0.4193, screenH * 0.3120, screenW * 0.5776, screenH * 0.3639, tocolor(255, 255, 255, 255), 2.00, "default", "center", "top", false, false, false, false, false)
    dxDrawRectangle(screenW * 0.4193, screenH * 0.5167, screenW * 0.1646, screenH * 0.0500, tocolor(126, 126, 127, 224), false)
    dxDrawRectangle(screenW * 0.4193, screenH * 0.5759, screenW * 0.1646, screenH * 0.0500, tocolor(126, 126, 127, 224), false)
    dxDrawText("Rozpocznij prace", screenW * 0.4375, screenH * 0.5231, screenW * 0.5646, screenH * 0.5574, tocolor(255, 255, 255, 255), 1.00, "default", "center", "top", false, false, false, false, false)
    dxDrawText("Anuluj", screenW * 0.4380, screenH * 0.5824, screenW * 0.5651, screenH * 0.6167, tocolor(255, 255, 255, 255), 1.00, "default", "center", "top", false, false, false, false, false)
end
local markerStartRybak = createMarker(1629.55, 582.18, 1.76-1,"cylinder",1.5,255,0,0,255)

addEventHandler("onClientMarkerHit",markerStartRybak,function()
    if guipracka == false then 
        if isElementWithinMarker(localPlayer, markerStartRybak) then
        pokazOkno()
        guipracka = true
        setElementData(localPlayer,"gui:showed",true)
        showCursor(true)
        end
    end

end)



function pokazOkno()
    addEventHandler("onClientRender",root,guiPraca)
end

function zamknijOkno()
    removeEventHandler("onClientRender",root,guiPraca)
end

addEventHandler("onClientClick",getRootElement(),function(button, state)
    if button == "left" and state == "down" and guipracka == true then
        if getElementData(localPlayer,"gui:showed") then
        if cursorPosition(screenW * 0.4193, screenH * 0.5759, screenW * 0.1646, screenH * 0.0500) then
            removeEventHandler("onClientRender",root,guiPraca)
            guipracka = false
            setElementData(localPlayer,"gui:showed",false)
            showCursor(false)
        end
        end
    end
end)


addEventHandler("onClientClick",getRootElement(),function(button, state)
    if button == "left" and state == "down" and guipracka == true then
        if getElementData(localPlayer,"gui:showed",true) then
        if cursorPosition(screenW * 0.4193, screenH * 0.5167, screenW * 0.1646, screenH * 0.0500) then
        removeEventHandler("onClientRender",root,guiPraca)
        showCursor(false)
        setElementData(localPlayer,"player:working",true)
        setElementData(localPlayer,"gui:showed",false)
        end
    end
    end
end)


local markery = {
    
    {1633.33, 589.55, 1.76-1},
    {1622.88, 583.13, 1.76-1},

}



function HitFunction (hitElement)
  if ( hitElement ~= localPlayer ) then return end 
    if getElementData(localPlayer,"player:working") == true then
        setElementData(localPlayer,"player:working", false) 
        setElementData(localPlayer,"player:fishing",true)
        setElementFrozen(hitElement,true)
        triggerServerEvent("Lowienie",localPlayer,localPlayer)
    end
    setTimer(function()
            rnd = math.random(10,20)
            triggerServerEvent("givePlayerMoney",localPlayer,rnd)
            outputChatBox("Otrzymujesz"..rnd.. "PLN za zlowiona rybke",0,255,0)
            setElementFrozen(hitElement,false)
            triggerServerEvent("StopLowienie",localPlayer,localPlayer)
            setElementData(localPlayer,"player:fishing",false)
     end ,5000,1)
end

for _,v in ipairs(markery) do
    if getElementData(localPlayer,"player:working") == true then
    markerpraca = createMarker(v[1],v[2],v[3],"cylinder",2.0,255,255,255)
    	addEventHandler("onClientMarkerHit",markerpraca,HitFunction)
    end
end

 

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