Jump to content

[solved]help Bad argument !


Sora

Recommended Posts

hello guys , i created an resource and i created marker and blip in a funiction with global variables

and tried to destroy them with another funiction but says bad argument destroyElement(..) .. got nil :shock:

addEvent("cb",true) 
addEventHandler("cb",getRootElement(),ct) 
function ct(player,x,y,z) 
finishblip = createBlip ( x, y, z, 42, 0, 0, 0, 255, 255,1, 99999,player) 
finishM = createMarker (x,y,z, "checkpoint", 3, 255, 255, 0, 170,player) 
addEventHandler("onMarkerHit", finishM,destroy) 
end 
function destroy(hitElement) 
-- some not needed codes was here 
destroyElement(finishblip) 
destroyElement(finishM) 
end 
  

my question is , why the script (or the funiction) can't get variables and they are global variables :?::!:

Edited by Guest
Link to comment
function ct(player,x,y,z) 
    finishblip = createBlip(x, y, z, 42, 0, 0, 0, 255, 255, 1, 99999, player) 
    finishM = createMarker(x, y, z, "checkpoint", 3, 255, 255, 0, 170, player) 
    addEventHandler("onMarkerHit", finishM, destroy) 
end 
addEvent("cb",true) 
addEventHandler("cb", root, ct) 
  
function destroy(hitElement) 
    -- some not needed codes was here 
    destroyElement(finishblip) 
    destroyElement(finishM) 
end 

Function must be before addEvent/Handler.

Edited by Guest
Link to comment
  • MTA Team

Events must have functions, your function wasn't created when the server checked the event, so it didn't work.

EDIT: _Dark_ was first, but here's a simple fix.

addEvent("cb", true) 
addEventHandler("cb", root, 
    function(player, x, y, z) 
        finishM = createMarker(x, y, z, "checkpoint", 3, 255, 255, 0, 170, player) 
        finishblip = createBlipAttachedTo(finishM, 42, 0, 0, 0, 255, 255, 1, 99999, player) 
        addEventHandler("onMarkerHit", finishM, destroy) 
    end 
) 
  
addEvent("cb", true) 
addEventHandler("cb", root, 
    function(player, x, y, z) 
        finishM = createMarker(x, y, z, "checkpoint", 3, 255, 255, 0, 170, player) 
        finishblip = createBlipAttachedTo(finishM, 42, 0, 0, 0, 255, 255, 1, 99999, player) 
        addEventHandler("onMarkerHit", finishM, destroy) 
    end 
) 
  
function destroy(hitElement, matchingDimension) 
    if matchingDimension then 
        destroyElement(finishblip) 
        destroyElement(finishM) 
    end 
end 

Link to comment

If problem not solved try this:

    addEvent("cb", true) 
    addEventHandler("cb", root, 
        function(player, x, y, z) 
            finishM = createMarker(x, y, z, "checkpoint", 3, 255, 255, 0, 170, player) 
            finishblip = createBlipAttachedTo(finishM, 42, 0, 0, 0, 255, 255, 1, 99999, player) 
            outputChatBox(getElementType(finishM), player) 
            outputChatBox(getElementType(finishblip), player) 
            addEventHandler("onMarkerHit", finishM, destroy) 
        end 
    ) 
      
    function destroy(hitElement, matchingDimension) 
        if matchingDimension then 
            if isElement(finishM) and isElement(finishblip) then 
                destroyElement(finishblip) 
                destroyElement(finishM) 
            else 
                outputDebugString("'finishM' and/or 'finishblip' are not elements, perhaps not created?") 
            end 
        end 
    end 

This should output in chatbox Marker and Blip.

Edited by Guest
Link to comment
  • MTA Team
Are you sure that you called event cb?

Try this:

    addEvent("cb", true) 
    addEventHandler("cb", root, 
        function(player, x, y, z) 
            finishM = createMarker(x, y, z, "checkpoint", 3, 255, 255, 0, 170, player) 
            finishblip = createBlipAttachedTo(finishM, 42, 0, 0, 0, 255, 255, 1, 99999, player) 
            outputChatBox(getElementType(finishM), player) 
            outputChatBox(getElementType(finishblip), player) 
            addEventHandler("onMarkerHit", finishM, destroy) 
        end 
    ) 
      
    function destroy(hitElement, matchingDimension) 
        if matchingDimension then 
            if isElement(finishM) and isElement(finishblip) then 
                destroyElement(finishblip) 
                destroyElement(finishM) 
            else 
                outputDebugString("'finishM' and/or 'finishblip' are not elements, perhaps not created?") 
            end 
        end 
    end 

This should output in chatbox Marker and Blip.

I am not sora, you can just delete your message because he haven't tried it yet.

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