Jump to content

Element Within Marker = Bad Argument


lolek123

Recommended Posts

Client Side:

function training(localPlayer, command) 
    if (isElementWithinMarker(localPlayer, myMarker) == true) then 
        local x,y,z = getPedBonePosition(localPlayer, 25) 
        attachElements( object(2916), localPlayer, x,y,z) 
    elseif (isElementWithinMarker(localPlayer, myMarker) == false) then 
        outputChatBox("nope", localPlayer) 
    end 
end 
addCommandHandler("train", training) 

Server Side:

function CheckMyObject(res) 
    if res==getThisResource() then 
        for _,object in ipairs(getElementsByType("object")) do 
            if getElementModel(object)==2916 then 
                local x,y,z=getElementPosition(object) 
                local int=getElementInterior(object) 
                local dim=getElementDimension(object) 
                myMarker = createMarker(x,y,z,"cylinder",2.0,255,0,0,125) 
                setElementInterior(myMarker,int) 
                setElementDimension(myMarker,dim)            
            end 
        end 
    end 
end 
addEventHandler("onResourceStart",getRootElement(),CheckMyObject) 

I'm getting bad argument error each time I type in the command, can someone tell me if I have to export "myMarker" somehow from script.lua to client.lua or what?

Link to comment

Client-side:

addEventHandler( 'onClientResourceStart', resourceRoot, 
    function( pRes ) 
        for i,v in ipairs( getElementsByType( 'object' ) ) do 
            if( getElementModel( v ) == 2916 ) then 
                local iX, iY, iZ = getElementPosition( v ) 
                local iInt = getElementInterior( v ) 
                local iDim = getElementDimension( v ) 
                myMarker = createMarker( iX, iY, iZ, 'cylinder', 2.0, 255, 0, 0, 125 ) 
                setElementInterior( myMarker, iInt ) 
                setElementDimension( myMarker, iDim ) 
            end 
        end 
    end 
) 
  
addCommandHandler( 'train', 
    function( c ) 
        local p = localPlayer 
        if( isElementWithinMarker( p, myMarker ) ) then 
            local iX, iY, iZ = getPedBonePosition( p, 25 ) 
            attachElements( 2916, p, iX, iY, iZ ) 
        else 
            outputChatBox( 'Nope.', p ) 
        end 
    end 
) 

Not tested.

Link to comment

Could you also make it actually pick up the object, it has a bad argument on "attachElements" and I dont know how to specify the object that he has to pick up. Maybe I need to give each of the elements with model ID 2916 their own ID with setElementID?

Link to comment
addEventHandler( 'onClientResourceStart', resourceRoot, 
    function( pRes ) 
        for i,v in ipairs( getElementsByType( 'object' ) ) do 
            if( getElementModel( v ) == 2916 ) then 
                local iX, iY, iZ = getElementPosition( v ) 
                local iInt = getElementInterior( v ) 
                local iDim = getElementDimension( v ) 
                myMarker = createMarker( iX, iY, iZ, 'cylinder', 2.0, 255, 0, 0, 125 ) 
                setElementInterior( myMarker, iInt ) 
                setElementDimension( myMarker, iDim ) 
            end 
        end 
    end 
) 
  
addCommandHandler( 'train', 
    function( c ) 
        local p = localPlayer 
        if( isElementWithinMarker( p, myMarker ) ) then 
            local iX, iY, iZ = getPedBonePosition( p, 25 ) 
            object = createObject ( 2916, iX, iY, iZ ) 
            attachElements( object, p, iX, iY, iZ ) 
        else 
            outputChatBox( 'Nope.', p ) 
        end 
    end 
) 

Link to comment
addEventHandler( 'onClientResourceStart', resourceRoot, 
    function( pRes ) 
        for i,v in ipairs( getElementsByType( 'object' ) ) do 
            if( getElementModel( v ) == 2916 ) then 
                local iX, iY, iZ = getElementPosition( v ) 
                local iInt = getElementInterior( v ) 
                local iDim = getElementDimension( v ) 
                myMarker = createMarker( iX, iY, iZ, 'cylinder', 2.0, 255, 0, 0, 125 ) 
                setElementInterior( myMarker, iInt ) 
                setElementDimension( myMarker, iDim ) 
            end 
        end 
    end 
) 
  
addCommandHandler( 'train', 
    function( c ) 
        local p = localPlayer 
        if( isElementWithinMarker( p, myMarker ) ) then 
            local iX, iY, iZ = getPedBonePosition( p, 25 ) 
            object = createObject ( 2916, iX, iY, iZ ) 
            attachElements( object, p, iX, iY, iZ ) 
        else 
            outputChatBox( 'Nope.', p ) 
        end 
    end 
) 

And if I wanted it to pick up the object that is there on the map, instead of creating a new one, would that be doable?

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