xUltimate Posted January 14, 2011 Share Posted January 14, 2011 I was attempting to make a togwindow command but apparently it does not want to comply. The cmd: addCommandHandler( "togwindows", function ( player, vehicle ) if exports.players:isLoggedIn( player ) then if isPedInVehicle ( player ) then local data = vehicles[ source ] if data then if data.vehicleID > 0 then if data.windows == 0 then local success, error = exports.sql:query_free( "UPDATE vehicles SET windows = 1 WHERE vehicleID = " .. data.vehicleID ) if success then exports.chat:me( source, "rolls the windows up.") end if error then outputChatBox( "My-SQL Error.", source, 255, 0, 0 ) end elseif data.windows == 1 then local success, error = exports.sql:query_free( "UPDATE vehicles SET windows = 0 WHERE vehicleID = " .. data.vehicleID ) if success then exports.chat:me( source, "rolls the windows down.") end if error then outputChatBox( "My-SQL Error.", source, 255, 0, 0 ) end end else outputChatBox( "You cant do this with a temporary vehicle. (SQL Error)", source, 255, 0, 0 ) end end else outputChatBox( "You are not in a vehicle.", player, 255, 0, 0 ) end end end ) When I do /togwindows it shows no errors, warnings or anything it just does nothing. Link to comment
12p Posted January 14, 2011 Share Posted January 14, 2011 one EPIC problem. Too many "if then, if then", replace with some "and". I don't get the error (use debugging!) but I simplified a bit your code. Check out: addCommandHandler( "togwindows", function ( player, vehicle ) if exports.players:isLoggedIn( player ) then if isPedInVehicle ( player ) then local data = vehicles[ source ] if data and data.vehicleID > 0 and data.windows == 0 then local success, error = exports.sql:query_free( "UPDATE vehicles SET windows = 1 WHERE vehicleID = " .. data.vehicleID ) if success then exports.chat:me( source, "rolls the windows up.") end if error then outputChatBox( "My-SQL Error.", source, 255, 0, 0 ) end elseif data.windows == 1 then local success, error = exports.sql:query_free( "UPDATE vehicles SET windows = 0 WHERE vehicleID = " .. data.vehicleID ) if success then exports.chat:me( source, "rolls the windows down.") end if error then outputChatBox( "My-SQL Error.", source, 255, 0, 0 ) else outputChatBox( "You can't do this with a temporary vehicle. (SQL Error)", source, 255, 0, 0 ) end end else outputChatBox( "You are not in a vehicle.", player, 255, 0, 0 ) end end end ) When I do /togwindows it shows no errors, warnings or anything it just does nothing. Link to comment
xUltimate Posted January 14, 2011 Author Share Posted January 14, 2011 Ewww... i know thats simplified but i like looking at codes organized lol. Link to comment
SDK Posted January 14, 2011 Share Posted January 14, 2011 That many if's do make the code look complicated, since you'll go pretty 'deep' and have many end's. Instead, use elseif and return. About the code, addCommandHandler needs different arguments, but I can't really help you since I don't know how the rest of the script looks like. (The sql part seems weird tho) function togwindows ( player, command ) -- first the checks if the player has everything needed: if not exports.players:isLoggedIn( player ) then return false -- not logged in, stop code elseif not isPedInVehicle ( player ) then outputChatBox( "You are not in a vehicle.", player, 255, 0, 0 ) return false -- no vehicle, stop code end -- then the actual code, which I don't know how to fix, sql seems weird local vehicle = getPedOccupiedVehicle(player) local data = vehicles[ vehicle ] if data and data.vehicleID > 0 and data.windows == 0 then local success, error = exports.sql:query_free( "UPDATE vehicles SET windows = 1 WHERE vehicleID = " .. data.vehicleID ) if success then exports.chat:me( source, "rolls the windows up.") end if error then outputChatBox( "My-SQL Error.", source, 255, 0, 0 ) end elseif data.windows == 1 then local success, error = exports.sql:query_free( "UPDATE vehicles SET windows = 0 WHERE vehicleID = " .. data.vehicleID ) if success then exports.chat:me( source, "rolls the windows down.") end if error then outputChatBox( "My-SQL Error.", source, 255, 0, 0 ) else outputChatBox( "You can't do this with a temporary vehicle. (SQL Error)", source, 255, 0, 0 ) end end end addCommandHandler( "togwindows", togwindows) Link to comment
xUltimate Posted January 14, 2011 Author Share Posted January 14, 2011 What do you mean? Whats wrong with the SQL? Link to comment
SDK Posted January 14, 2011 Share Posted January 14, 2011 I don't know, I just wasn't sure if it would work, you're nowhere referring to the player. And what is that vehicles table? Link to comment
xUltimate Posted January 15, 2011 Author Share Posted January 15, 2011 I don't know, I just wasn't sure if it would work, you're nowhere referring to the player.And what is that vehicles table? vehicles[ source ] == Call the SQL to lookup the vehicleid the person is in vehicles[ vehicle ] == Call the SQL to lookup all cars in the database so I use vehicles[ source ] 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