xUltimate Posted October 29, 2010 Share Posted October 29, 2010 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
dzek (varez) Posted October 29, 2010 Share Posted October 29, 2010 this is wrong FROM `vehicles`, impounded = 0 what that impounded thing should do for you ? you should read general mysql tutorial or just manual page for SELECT. also it's better to take your values on WHERE conditions into single quotes EVEN if the column is integer Link to comment
xUltimate Posted October 30, 2010 Author Share Posted October 30, 2010 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
dzek (varez) Posted October 30, 2010 Share Posted October 30, 2010 and you mixed them both? well, thats incorrect.. Link to comment
xUltimate Posted October 30, 2010 Author Share Posted October 30, 2010 Heh ya I noticed Link to comment
xUltimate Posted November 3, 2010 Author Share Posted November 3, 2010 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
dzek (varez) Posted November 5, 2010 Share Posted November 5, 2010 -- 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
xUltimate Posted November 6, 2010 Author Share Posted November 6, 2010 Ok for the final time, I have debugged all my scripts, and it does nothing. Link to comment
dzek (varez) Posted November 6, 2010 Share Posted November 6, 2010 what does nothing. show us full code (with debug code) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now