JuniorMelo Posted November 15, 2013 Share Posted November 15, 2013 Hello, I have a problem in this script has an error function ResourceStart() executeSQLCreateTable("VColors", "serial STRING,Col1 INT,Col2 INT,Col3 INT") end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), ResourceStart) addEvent ( "GetColor2", true ) addEventHandler ( "GetColor2", root, function ( r, g, b, PVeh ) triggerClientEvent ( root, "GetColor", root, r, g, b ) local serial = getPlayerSerial(source) setVehicleColor ( PVeh, r, g, b) outputChatBox("Settings Updated!",source,0,255,0) executeSQLUpdate ( "VColors", "Col1 = '"..r.."'","serial = '" .. serial .. "'") executeSQLUpdate ( "VColors", "Col2 = '"..g.."'","serial = '" .. serial .. "'") executeSQLUpdate ( "VColors", "Col3 = '"..b.."'","serial = '" .. serial .. "'") end ) function vehColor2() local players = getElementsByType ( "player" ) for k,v in ipairs(players) do local PVeh = getPedOccupiedVehicle(v) local serial = getPlayerSerial(v) local Col1 = executeSQLSelect ( "VColors", "Col1","serial = '" .. serial .. "'") local Col2 = executeSQLSelect ( "VColors", "Col2","serial = '" .. serial .. "'") local Col3 = executeSQLSelect ( "VColors", "Col3","serial = '" .. serial .. "'") setVehicleColor(PVeh,tonumber(Col1[1]["Col1"]),tonumber(Col2[1]["Col2"]),tonumber(Col3[1]["Col3"]) ) end end function timer() setTimer(vehColor2,3000,1) end function timer2() setTimer(vehColor2,tonumber(respawntime)+1000,1) end addEventHandler("onMapStarting",getRootElement(),timer) line 373: setVehicleColor(PVeh,tonumber(Col1[1]["Col1"]),tonumber(Col2[1]["Col2"]),tonumber(Col3[1]["Col3"]) ) Link to comment
Castillo Posted November 15, 2013 Share Posted November 15, 2013 One of these "Col*" is returning nil. Link to comment
tosfera Posted November 15, 2013 Share Posted November 15, 2013 You should create an output to see what Col1[1] returns. Cause you're getting a table back and you're using a unknown index field ( it doesn't exist in your table ). I think the ["Col1"] is the biggest problem right now Link to comment
JuniorMelo Posted November 15, 2013 Author Share Posted November 15, 2013 changed the error may be in client file ?? addEventHandler ( "onClientGUIClick", root, function ( VehColor,r, g, b,PVeh) if ( guiGetText ( r2 ) ~= "" ) and ( guiGetText ( g2 ) ~= "" ) and ( guiGetText ( b2 ) ~= "" ) then if ( source == ExecuteColor ) then local PVeh = getPedOccupiedVehicle(getLocalPlayer()) triggerServerEvent ( "GetColor2", localPlayer, guiGetText ( r2 ), guiGetText ( g2 ), guiGetText ( b2 ), PVeh ) elseif ( source == colorPicker ) then openPicker ( 59553532, "#000000", "Cor do Veiculo" ) end end end ) SERVER function ResourceStart() executeSQLCreateTable("VColors", "serial STRING,Col1 INT,Col2 INT,Col3 INT") end addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), ResourceStart) addEvent ( "GetColor2", true ) addEventHandler ( "GetColor2", root, function ( r, g, b, PVeh ) triggerClientEvent ( root, "GetColor", root, r, g, b ) local serial = getPlayerSerial(source) setVehicleColor ( PVeh, r, g, b) outputChatBox("Settings Updated!",source,0,255,0) executeSQLUpdate ( "VColors", "Col1 = '"..r.."'","serial = '" .. serial .. "'") executeSQLUpdate ( "VColors", "Col2 = '"..g.."'","serial = '" .. serial .. "'") executeSQLUpdate ( "VColors", "Col3 = '"..b.."'","serial = '" .. serial .. "'") end ) function vehColor2() local players = getElementsByType ( "player" ) for k,v in ipairs(players) do local PVeh = getPedOccupiedVehicle(v) local serial = getPlayerSerial(v) local Col1 = executeSQLSelect ( "VColors", "Col1","serial = '" .. serial .. "'") local Col2 = executeSQLSelect ( "VColors", "Col2","serial = '" .. serial .. "'") local Col3 = executeSQLSelect ( "VColors", "Col3","serial = '" .. serial .. "'") setVehicleColor(PVeh,tonumber(Col1[1]["Col1"]),tonumber(Col2[1]["Col2"]),tonumber(Col3[1]["Col3"]) ) end end function timer() setTimer(vehColor2,3000,1) end function timer2() setTimer(vehColor2,tonumber(respawntime)+1000,1) end addEventHandler("onMapStarting",getRootElement(),timer) Link to comment
tosfera Posted November 15, 2013 Share Posted November 15, 2013 Give us the output what col1, col2 and col3 is. ( outputDebugString ), if it's a table value then add [1] to it. Link to comment
JuniorMelo Posted November 15, 2013 Author Share Posted November 15, 2013 Give us the output what col1, col2 and col3 is. ( outputDebugString ), if it's a table value then add [1] to it. well? local Col1[1] = executeSQLSelect ( "VColors", "Col1","serial = '" .. serial .. "'") local Col2[1] = executeSQLSelect ( "VColors", "Col2","serial = '" .. serial .. "'") local Col3[1] = executeSQLSelect ( "VColors", "Col3","serial = '" .. serial .. "'") Link to comment
tosfera Posted November 15, 2013 Share Posted November 15, 2013 You don't get it, after those 3 lines place this; outputDebugString ( tostring ( Col1[1] ) .." -- ".. tostring ( Col2[1] ) .." -- " .. tostring ( Col3[1] ) ); tell us what you see in /debugscript 3 Link to comment
JuniorMelo Posted November 16, 2013 Author Share Posted November 16, 2013 You don't get it, after those 3 lines place this; outputDebugString ( tostring ( Col1[1] ) .." -- ".. tostring ( Col2[1] ) .." -- " .. tostring ( Col3[1] ) ); tell us what you see in /debugscript 3 Link to comment
Tete omar Posted November 16, 2013 Share Posted November 16, 2013 This function is deprecated. This means that its use is discouraged and that it might not exist in future versions.Please use executeSQLQuery instead. See the examples at executeSQLQuery for equivalent SELECT usage You should have used executeSQLQuery Link to comment
JuniorMelo Posted November 16, 2013 Author Share Posted November 16, 2013 This function is deprecated. This means that its use is discouraged and that it might not exist in future versions.Please use executeSQLQuery instead. See the examples at executeSQLQuery for equivalent SELECT usage You should have used executeSQLQuery Could you give me an example this function? Link to comment
tosfera Posted November 16, 2013 Share Posted November 16, 2013 executeSQLQuery("SELECT score,health FROM players WHERE name=?", playerName ) executeSQLQuery("SELECT `score`,`health` FROM `players` WHERE `name`=?", playerName ) https://wiki.multitheftauto.com/wiki/ExecuteSQLQuery Link to comment
JuniorMelo Posted November 16, 2013 Author Share Posted November 16, 2013 executeSQLQuery("SELECT score,health FROM players WHERE name=?", playerName ) executeSQLQuery("SELECT `score`,`health` FROM `players` WHERE `name`=?", playerName ) https://wiki.multitheftauto.com/wiki/ExecuteSQLQuery this function that you sent me, * health * Saves the health of player ? Link to comment
Tete omar Posted November 16, 2013 Share Posted November 16, 2013 No this retrieves the health and the score from a database, if you want to save/update something then use INSERT syntax to store something or use UPDATE syntax to update a stored data. Examples of INSERT and UPDATE syntaxes: executeSQLQuery("INSERT INTO players(name,color,sound) VALUES(?,?,?)", playerName, colorName, soundName ) executeSQLQuery("INSERT INTO `players`(`name`,`color`,`sound`) VALUES(?,?,?)", playerName, colorName, soundName ) executeSQLQuery("UPDATE players SET color='green',sound='somehead' WHERE name=?", playerName ) executeSQLQuery("UPDATE players SET color=?,sound=? WHERE name=?", colorName, soundName, playerName ) executeSQLQuery("UPDATE `players` SET `color`=?,`sound`=? WHERE `name`=?", colorName, soundName, playerName Link to comment
JuniorMelo Posted November 16, 2013 Author Share Posted November 16, 2013 (edited) deleted Edited November 16, 2013 by Guest Link to comment
JuniorMelo Posted November 16, 2013 Author Share Posted November 16, 2013 New function, no working function buyCarColor(thePlayer,red,green,blue) local account = getPlayerAccount(thePlayer) if not (isGuestAccount(account)) then setAccountData(account,"firstRed",red) setAccountData(account,"firstGreen",green) setAccountData(account,"firstBlue",blue) outputChatBox("#00ff00[sHOP] #ffffff---!",thePlayer,255,255,255,true) local PVeh = getPedOccupiedVehicle(thePlayer) setVehicleColor(PVeh,red,green,blue) end end function callClientFunction(client, funcname, ...) local arg = { ... } if (arg[1]) then for key, value in next, arg do if (type(value) == "number") then arg[key] = tostring(value) end end end -- If the clientside event handler is not in the same resource, replace 'resourceRoot' with the appropriate element triggerClientEvent(client, "onServerCallsClientFunction", resourceRoot, funcname, unpack(arg or {})) end function callServerFunction(funcname, ...) local arg = { ... } if (arg[1]) then for key, value in next, arg do arg[key] = tonumber(value) or value end end loadstring("return "..funcname)()(unpack(arg)) end addEvent("onClientCallsServerFunction", true) addEventHandler("onClientCallsServerFunction", resourceRoot , callServerFunction) function updatePlayerLogin(thePlayer) local account = getPlayerAccount(thePlayer) red = getAccountData(account,"firstRed") green = getAccountData(account,"firstGreen") blue = getAccountData(account,"firstBlue") local PVeh = getPedOccupiedVehicle(thePlayer) setVehicleColor(PVeh,red,green,blue) end addEventHandler("onPlayerLogin", getRootElement(),updatePlayerLogin) Debugscript 3 Link to comment
Castillo Posted November 16, 2013 Share Posted November 16, 2013 function buyCarColor(thePlayer,red,green,blue) local account = getPlayerAccount(thePlayer) if not (isGuestAccount(account)) then setAccountData(account,"firstRed",red) setAccountData(account,"firstGreen",green) setAccountData(account,"firstBlue",blue) outputChatBox("#00ff00[sHOP] #ffffff---!",thePlayer,255,255,255,true) local PVeh = getPedOccupiedVehicle(thePlayer) setVehicleColor(PVeh,red,green,blue) end end function callClientFunction(client, funcname, ...) local arg = { ... } if (arg[1]) then for key, value in next, arg do if (type(value) == "number") then arg[key] = tostring(value) end end end -- If the clientside event handler is not in the same resource, replace 'resourceRoot' with the appropriate element triggerClientEvent(client, "onServerCallsClientFunction", resourceRoot, funcname, unpack(arg or {})) end function callServerFunction(funcname, ...) local arg = { ... } if (arg[1]) then for key, value in next, arg do arg[key] = tonumber(value) or value end end loadstring("return "..funcname)()(unpack(arg)) end addEvent("onClientCallsServerFunction", true) addEventHandler("onClientCallsServerFunction", resourceRoot , callServerFunction) function updatePlayerLogin( ) local account = getPlayerAccount( source ) red = getAccountData(account,"firstRed") green = getAccountData(account,"firstGreen") blue = getAccountData(account,"firstBlue") local PVeh = getPedOccupiedVehicle(source) setVehicleColor(PVeh,red,green,blue) end addEventHandler("onPlayerLogin", getRootElement(),updatePlayerLogin) Link to comment
JuniorMelo Posted November 16, 2013 Author Share Posted November 16, 2013 (edited) function buyCarColor(thePlayer,red,green,blue) local account = getPlayerAccount(thePlayer) if not (isGuestAccount(account)) then setAccountData(account,"firstRed",red) setAccountData(account,"firstGreen",green) setAccountData(account,"firstBlue",blue) outputChatBox("#00ff00[sHOP] #ffffff---!",thePlayer,255,255,255,true) local PVeh = getPedOccupiedVehicle(thePlayer) setVehicleColor(PVeh,red,green,blue) end end function callClientFunction(client, funcname, ...) local arg = { ... } if (arg[1]) then for key, value in next, arg do if (type(value) == "number") then arg[key] = tostring(value) end end end -- If the clientside event handler is not in the same resource, replace 'resourceRoot' with the appropriate element triggerClientEvent(client, "onServerCallsClientFunction", resourceRoot, funcname, unpack(arg or {})) end function callServerFunction(funcname, ...) local arg = { ... } if (arg[1]) then for key, value in next, arg do arg[key] = tonumber(value) or value end end loadstring("return "..funcname)()(unpack(arg)) end addEvent("onClientCallsServerFunction", true) addEventHandler("onClientCallsServerFunction", resourceRoot , callServerFunction) function updatePlayerLogin( ) local account = getPlayerAccount( source ) red = getAccountData(account,"firstRed") green = getAccountData(account,"firstGreen") blue = getAccountData(account,"firstBlue") local PVeh = getPedOccupiedVehicle(source) setVehicleColor(PVeh,red,green,blue) end addEventHandler("onPlayerLogin", getRootElement(),updatePlayerLogin) OHHHHHHHhhhhhhhhhhhhhhhhhhhhhhh Castillo thank you, thank you even needed that!!! Edited November 16, 2013 by Guest Link to comment
JuniorMelo Posted November 16, 2013 Author Share Posted November 16, 2013 is possible to use the event addEventHandler("onMapStarting", getRootElement(),updatePlayerLogin) Link to comment
Castillo Posted November 16, 2013 Share Posted November 16, 2013 Not alone, because it doesn't have a player element. Link to comment
JuniorMelo Posted November 16, 2013 Author Share Posted November 16, 2013 ok, I'll find another way 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