Jump to content

Unable to create point


xUltimate

Recommended Posts

I'm trying to make it to where I can create a delivery point, It creates the point and adds it in the SQL but the job is unable to find the location.

Job part

function addDropOff( dimension ) 
    if getResourceState( getResourceFromName( "deliverypoints" ) ) == "running" then 
        markedToAdd[ dimension ] = nil 
        for k, v in ipairs( dropOffs ) do 
            if v.dimension == dimension then 
                return 
            end 
        end 
         
        local interior = exports.deliverypoints:getDeliverypoint( dimension ) 
        if interior then 
            if getElementDimension( interior.outside ) == 0 then 
                local x, y, z 
                if interior.dropoff then 
                    x, y, z = unpack( interior.dropoff ) 
                else 
                    x, y, z = getElementPosition( interior.outside ) 
                     
                    local cx, cy, cz = exports['vehicle-nodes']:findClosest( x, y, z ) 
                    if cx then 
                        x = ( 1.3 * x + cx ) / 2.3 
                        y = ( 1.3 * y + cy ) / 2.3 
                        z = ( 1.3 * z + cz ) / 2.3 
                        z = ( 1.3 * z + cz ) / 2.3 
                    end 
                end 
                table.insert( dropOffs, { x = x, y = y, z = z, dimension = dimension, name = interior.name } ) 
            end 
        end 
    else 
        markedToAdd[ dimension ] = true 
    end 
end 

Delivery lua

local addCommandHandler_ = addCommandHandler 
      addCommandHandler  = function( commandName, fn, restricted, caseSensitive ) 
    -- add the default command handlers 
    if type( commandName ) ~= "table" then 
        commandName = { commandName } 
    end 
    for key, value in ipairs( commandName ) do 
        if key == 1 then 
            addCommandHandler_( value, fn, restricted, caseSensitive ) 
        else 
            addCommandHandler_( value, 
                function( player, ... ) 
                    -- check if he has permissions to execute the command, default is not restricted (aka if the command is restricted - will default to no permission; otherwise okay) 
                    if hasObjectPermissionTo( player, "command." .. commandName[ 1 ], not restricted ) then 
                        fn( player, ... ) 
                    end 
                end 
            ) 
        end 
    end 
     
    -- check for alternative handlers, such as createinterior = createint 
    for k, v in ipairs( commandName ) do 
        if v:find( "deliverypoint" ) then 
            for key, value in pairs( { "dp" } ) do 
                local newCommand = v:gsub( "deliverypoint", value ) 
                if newCommand ~= v then 
                    -- add a second (replaced) command handler 
                    addCommandHandler_( newCommand, 
                        function( player, ... ) 
                            -- check if he has permissions to execute the command, default is not restricted (aka if the command is restricted - will default to no permission; otherwise okay) 
                            if hasObjectPermissionTo( player, "command." .. commandName[ 1 ], not restricted ) then 
                                fn( player, ... ) 
                            end 
                        end 
                    ) 
                end 
            end 
        end 
    end 
end 
  
-- 
  
local dpoints = { } 
  
addEventHandler( "onResourceStart", resourceRoot, 
    function( ) 
        if not exports.sql:create_table( 'deliverypoints', 
            { 
                { name = 'dpointID', type = 'int(10) unsigned', auto_increment = true, primary_key = true }, 
                { name = 'x', type = 'float' }, 
                { name = 'y', type = 'float' }, 
                { name = 'z', type = 'float' }, 
                { name = 'name', type = 'varchar(255)' }, 
            } ) then cancelEvent( ) return end 
         
        -- 
    end 
) 
  
-- 
  
addCommandHandler( "getdeliverypoint", 
    function( player, ... ) 
        -- check if he has permissions to see at least one prop 
        local int = dpoints[ getElementDimension( player ) ] 
        if int then 
            if hasObjectPermissionTo( player, "command.createinterior", false ) or hasObjectPermissionTo( player, "command.deleteinterior", false ) or hasObjectPermissionTo( player, "command.setinterior", false ) or hasObjectPermissionTo( player, "command.setinteriorprice", false ) then 
                local interior = getElementInterior( int.inside ) 
                local x, y, z = getElementPosition( int.inside ) 
                -- check if he has permissions to view each of the props 
                outputChatBox( "-- Delivery Point " .. getElementDimension( player ) .. " --", player, 255, 255, 255 ) 
                 
                if hasObjectPermissionTo( player, "command.createinterior", false ) or hasObjectPermissionTo( player, "command.deleteinterior", false ) or hasObjectPermissionTo( player, "command.setinterior", false ) then 
                    outputChatBox( "id: " .. name, player, 255, 255, 255 ) 
                end 
                 
                if hasObjectPermissionTo( player, "command.createinterior", false ) or hasObjectPermissionTo( player, "command.setinteriorname", false ) then 
                    outputChatBox( "name: " .. int.name, player, 255, 255, 255 ) 
                end 
            else 
                outputChatBox( "Your Delivery Point: " .. getElementDimension( player ), player ,255, 255, 255 ) 
            end 
        else 
            outputChatBox( "You are not in an interior.", player, 255, 0, 0 ) 
        end 
    end 
) 
  
addCommandHandler( "createdeliverypoint", 
    function( player, commandName, ...) 
        if ( ... ) then 
            local name = table.concat( { ... }, " " ) 
            local x, y, z = getElementPosition( player ) 
            x = math.ceil( x * 100 ) / 100 
            y = math.ceil( y * 100 ) / 100 
            z = math.ceil( z * 100 ) / 100 
            local insertid, e = exports.sql:query_insertid( "INSERT INTO deliverypoints (`x`, `y`, `z`, `name`) VALUES (" .. table.concat( { x, y, z, '"%s"' }, ", " ) .. ")", name ) 
            if insertid then 
                outputChatBox( "Delivery Point created. (ID " .. insertid .. ")", player, 0, 255, 0 ) 
                -- delete the marked position 
            else 
                outputChatBox( "MySQL-Query failed.", player, 255, 0, 0 ) 
            end 
        else 
            outputChatBox("Error Occured", player, 255, 0, 0) 
        end 
    end, 
    true 
) 
  
addCommandHandler( { "deletedeliverypoint", "deldeliverypoint" }, 
    function( player, commandName, dpointID ) 
        dpointID = tonumber( dpointID ) 
        if teleportID then 
            local dpoint = dpoints[ dpointID ] 
            if teleport then 
                if exports.sql:query_free( "DELETE FROM deliverypoints WHERE ID = " .. dpointID ) then 
                    outputChatBox( "You deleted Delivery Point " .. dpointID .. ".", player, 0, 255, 153 ) 
                else 
                    outputChatBox( "MySQL-Query failed.", player, 255, 0, 0 ) 
                end 
            else 
                outputChatBox( "Delivery Point not found.", player, 255, 0, 0 ) 
            end 
        else 
            outputChatBox( "Syntax: /" .. commandName .. " [id]", player, 255, 255, 255 ) 
        end 
    end, 
    true 
) 

Edited by Guest
Link to comment
I don't really understand the problem, what do you mean by 'the job is unable to find the location'?

do you actually have a function called getDeliverypoint?

where is the 'dpoints' table filled with data?

In the console it says "Unable to find drop-off point, leaving player-name with nothing to do"

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