Jump to content

setVehicleColor #ERROR#


JuniorMelo

Recommended Posts

Hello, I have a problem in this script

has an error :|

mta-screen_2013-11-15_18-34-45.png

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

:?:?:?:?

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

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

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

mta-screen_2013-11-16_14-42-07.png

Link to comment
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
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 by Guest
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...