Jump to content

Trobule with SQL


xUltimate

Recommended Posts

I wanted to make a impound system, but I get the "Critical Error" in my system.

addCommandHandler( "impound", 
    function( player, commandName ) 
        local vehicle = getPedOccupiedVehicle( player ) 
        if vehicle then 
            local data = vehicles[ vehicle ] 
            if data then 
                if exports.sql:query_free( "SELECT * FROM  `vehicles`, impounded = 0 WHERE vehicleID =" .. data.vehicleID ) then 
                    if data.vehicleID < 0 then 
                        outputChatBox( "Your temporary vehicle " .. data.vehicleID .. " (" .. getVehicleName( vehicle ) .. ") can't be impounded.", player, 255, 0, 0 ) 
                    elseif ( data.characterID > 0 and exports.factions:isPlayerInFaction( player, 4 ) or exports.factions:isPlayerInFaction( player, 1 ) or hasObjectPermissionTo( player, "command.createvehicle", false )) then 
                        local x, y, z = getElementPosition( vehicle ) 
                        local rx, ry, rz = getVehicleRotation( vehicle ) 
                        local success, error = exports.sql:query_free( "UPDATE vehicles SET respawnPosX = " .. x .. ", respawnPosY = " .. y .. ", respawnPosZ = " .. z .. ", respawnRotX = " .. rx .. ", respawnRotY = " .. ry .. ", respawnRotZ = " .. rz .. ", respawnInterior = " .. getElementInterior( vehicle ) .. ", respawnDimension = " .. getElementDimension( vehicle ) .. ", impounded = 1 WHERE vehicleID = " .. data.vehicleID ) 
                        if success then 
                            setVehicleFrozen(vehicle, true) 
                            setVehicleRespawnPosition( vehicle, x, y, z, rx, ry, rz ) 
                            data.respawnInterior = getElementInterior( vehicle ) 
                            data.respawnDimension = getElementDimension( vehicle ) 
                            saveVehicle( vehicle ) 
                            outputChatBox( "Vehicle " .. data.vehicleID .. " (" .. getVehicleName( vehicle ) .. ") has been impounded.", player, 0, 255, 0 ) 
                        else 
                            outputChatBox( "Impounding Vehicle failed.", player, 255, 0, 0 ) 
                        end 
                    else 
                        outputChatBox( "You cannot impound vehicles.", player, 255, 0, 0 ) 
                    end 
                elseif exports.sql:query_free( "SELECT * FROM  `vehicles`, impounded = 1 WHERE vehicleID =" .. data.vehicleID ) then 
                    if data.vehicleID < 0 then 
                        outputChatBox( "Your temporary vehicle " .. data.vehicleID .. " (" .. getVehicleName( vehicle ) .. ") can't be impounded.", player, 255, 0, 0 ) 
                    elseif ( data.characterID > 0 and exports.factions:isPlayerInFaction( player, 4 ) or exports.factions:isPlayerInFaction( player, 1 ) or hasObjectPermissionTo( player, "command.createvehicle", false ) ) then 
                        local success, error = exports.sql:query_free( "UPDATE vehicles SET impounded = 0 WHERE vehicleID = " .. data.vehicleID ) 
                        if success then 
                            setVehicleFrozen(vehicle, false) 
                            outputChatBox( "Vehicle " .. data.vehicleID .. " (" .. getVehicleName( vehicle ) .. ") has been unimpounded.", player, 0, 255, 0 ) 
                        else 
                            outputChatBox( "Unimpounding vehicle failed.", player, 0, 255, 0 ) 
                        end 
                    else 
                        outputChatBox( "You cannot unimpound vehicles.", player, 255, 0, 0 ) 
                    end 
                else 
                    outputChatBox( "Critical Error.", player, 255, 0, 0 ) 
                end 
            end 
        else 
            outputChatBox( "You are not driving a vehicle.", player, 255, 0, 0 ) 
        end 
    end 
) 

Apparently I did something wrong on the "if export.sql:query_free( "SELCT * FROM"" area.

Much appreciated if you can help me.

Link to comment

Ye well my localhost Phpmyadmin says: "SELECT *

FROM `wcf1_group`

ORDER BY `wcf1_group`.`groupID` ASC

LIMIT 0 , 30"

and i saw this

""UPDATE vehicles SET impounded = 0 WHERE vehicleID = " .. data.vehicleID"

so i figured that would work... but i am 100% new to MySQL so lol.

Link to comment

Just edited it and I think this should work but somewhere else I am messing up, it still skips to "Critical Error"

addCommandHandler( "impound", 
    function( player, commandName ) 
        local vehicle = getPedOccupiedVehicle( player ) 
        if vehicle then 
            local data = vehicles[ vehicle ] 
            if data then 
                if data.impounded == 0 then 
                    if data.vehicleID < 0 then 
                        outputChatBox( "Your temporary vehicle " .. data.vehicleID .. " (" .. getVehicleName( vehicle ) .. ") can't be impounded.", player, 255, 0, 0 ) 
                    elseif ( data.characterID > 0 and exports.factions:isPlayerInFaction( player, 4 ) or exports.factions:isPlayerInFaction( player, 1 ) or hasObjectPermissionTo( player, "command.createvehicle", false )) then 
                        local x, y, z = getElementPosition( vehicle ) 
                        local rx, ry, rz = getVehicleRotation( vehicle ) 
                        local success, error = exports.sql:query_free( "UPDATE vehicles SET respawnPosX = " .. x .. ", respawnPosY = " .. y .. ", respawnPosZ = " .. z .. ", respawnRotX = " .. rx .. ", respawnRotY = " .. ry .. ", respawnRotZ = " .. rz .. ", respawnInterior = " .. getElementInterior( vehicle ) .. ", respawnDimension = " .. getElementDimension( vehicle ) .. ", impounded = 1 WHERE vehicleID = " .. data.vehicleID ) 
                        if success then 
                            setVehicleFrozen(vehicle, true) 
                            setVehicleRespawnPosition( vehicle, x, y, z, rx, ry, rz ) 
                            data.respawnInterior = getElementInterior( vehicle ) 
                            data.respawnDimension = getElementDimension( vehicle ) 
                            saveVehicle( vehicle ) 
                            outputChatBox( "Vehicle " .. data.vehicleID .. " (" .. getVehicleName( vehicle ) .. ") has been impounded.", player, 0, 255, 0 ) 
                        else 
                            outputChatBox( "Impounding Vehicle failed.", player, 255, 0, 0 ) 
                        end 
                    else 
                        outputChatBox( "You cannot impound vehicles.", player, 255, 0, 0 ) 
                    end 
                elseif data.impounded == 1 then 
                    if data.vehicleID < 0 then 
                        outputChatBox( "Your temporary vehicle " .. data.vehicleID .. " (" .. getVehicleName( vehicle ) .. ") can't be impounded.", player, 255, 0, 0 ) 
                    elseif ( data.characterID > 0 and exports.factions:isPlayerInFaction( player, 4 ) or exports.factions:isPlayerInFaction( player, 1 ) or hasObjectPermissionTo( player, "command.createvehicle", false ) ) then 
                        local success, error = exports.sql:query_free( "UPDATE vehicles SET impounded = 0 WHERE vehicleID = " .. data.vehicleID ) 
                        if success then 
                            setVehicleFrozen(vehicle, false) 
                            outputChatBox( "Vehicle " .. data.vehicleID .. " (" .. getVehicleName( vehicle ) .. ") has been unimpounded.", player, 0, 255, 0 ) 
                        else 
                            outputChatBox( "Unimpounding vehicle failed.", player, 0, 255, 0 ) 
                        end 
                    else 
                        outputChatBox( "You cannot unimpound vehicles.", player, 255, 0, 0 ) 
                    end 
                else 
                    outputChatBox( "Critical Error.", player, 255, 0, 0 ) 
                end 
            end 
        else 
            outputChatBox( "You are not driving a vehicle.", player, 255, 0, 0 ) 
        end 
    end 
) 

Link to comment
  
-- it have nothing to do with sql anymore 
        local vehicle = getPedOccupiedVehicle( player ) 
        if vehicle then 
            local data = vehicles[ vehicle ] 
            if data then 
                if data.impounded == 0 then 
                elseif data.impounded == 1 then 
                else 
                     -- error 
            end 
        end 
  

i dont know what is in your vehicles variable.

it's very hard to find errors in your code with only part of it, and when it's so big, and we can't test it anyway.

i need to spend sometimes 10 minutes trying to understand what it should do.

maybe it's time to learn debugging?

it will help you many times. it's much faster to do a little debug than waiting days for reply that can't even come at all..

read especially 3.2 and 3.3 part of that wiki page.

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