PARKAH Posted August 2, 2013 Share Posted August 2, 2013 Here I have a script, it is used for a car panel and shop, of course with other scripts that is. But I'm pretty sure this is the script used to save and load the car you have bought, and for some reason you load it it doesn't save the colour or tuning upgrades, what needs to be added and where? If you could copy this script, edit it and paste it with a reply on this thread it would be greatly appreciated thanks! function dxDrawColorText(str, ax, ay, bx, by, color, scale, font, alignX, alignY) bx, by, color, scale, font = bx or ax, by or ay, color or tocolor(255,255,255,255), scale or 1, font or "default" if alignX then if alignX == "center" then ax = ax + (bx - ax - callClientFunction(source, "dxGetTextWidth", str:gsub("#%x%x%x%x%x%x",""), scale, font))/2 elseif alignX == "right" then ax = bx - callClientFunction(source, "dxGetTextWidth", str:gsub("#%x%x%x%x%x%x",""), scale, font) end end if alignY then if alignY == "center" then ay = ay + (by - ay - callClientFunction(source, "dxGetFontHeight", scale, font))/2 elseif alignY == "bottom" then ay = by - callClientFunction(source, "dxGetFontHeight", scale, font) end end local alpha = string.format("%08X", color):sub(1,2) local pat = "(.-)#(%x%x%x%x%x%x)" local s, e, cap, col = str:find(pat, 1) local last = 1 while s do if cap == "" and col then color = tocolor(getColorFromString("#"..col..alpha)) end if s ~= 1 or cap ~= "" then local w = dxGetTextWidth(cap, scale, font) dxDrawText(cap, ax, ay, ax + w, by, color, scale, font) ax = ax + w color = tocolor(getColorFromString("#"..col..alpha)) end last = e + 1 s, e, cap, col = str:find(pat, last) end if last <= #str then cap = str:sub(last) callClientFunction(source, "dxDrawText", cap, ax, ay, ax + callClientFunction(source, "dxGetTextWidth", cap, scale, font ), by, color, scale, font ) end end addEventHandler ( "onResourceStart", resourceRoot, function ( ) for i,player in ipairs (getElementsByType("player")) do setElementData(player,"showCar",false) end executeSQLQuery ( "CREATE TABLE IF NOT EXISTS cars (accountName TEXT, CarName TEXT, Health TEXT)" ) outputDebugString ( "Successfully connected to DataBase" ) local markers = getElementsByType ( "marker", getResourceRootElement() ) for theKey,theMarkers in ipairs(markers) do local x,y,z = getElementPosition( theMarkers ) createBlip ( x, y, z, 55, 0, 0, 0, 255 ) end end ) addEventHandler("onPlayerJoin",root, function() setElementData(source,"showCar",false) end) addEventHandler ( "onPlayerLogin", root, function ( _, account ) triggerEvent("UpdateCarLists",source,source) for index, cars in ipairs ( getAccountCars ( source ) ) do triggerClientEvent("updateCarListc",source,source,cars["CarName"],cars["Health"],index) end end ) function doesCarExist ( player,Car ) local account = getPlayerAccount ( player ) local accountName = getAccountName ( account ) local result = executeSQLQuery ( "SELECT * FROM cars WHERE accountName = ? AND CarName = ?", tostring ( accountName ), tostring ( Car ) ) if ( type ( result ) == "table" and #result == 0 or not result ) then return false, "This Car does not exists." else return true end end function addCarToDatabase ( player,Car ) local account = getPlayerAccount ( player ) local accountName = getAccountName ( account ) if ( doesCarExist ( player,Car ) ) then return false, "A Car with this name already exist." end if ( executeSQLQuery( "INSERT INTO `cars` (`accountName`, `CarName`, `Health`) VALUES ('".. tostring ( accountName ) .."', '".. tostring ( Car ) .."', '1000');" ) ) then else return false, "Unable to create Car." end end function setCarHealth ( player,Car,He ) local Health = math.ceil ( He ) local account = getPlayerAccount ( player ) local accountName = getAccountName ( account ) if ( not doesCarExist ( player,Car ) ) then return false, "This Car does not exists." end return executeSQLQuery( "UPDATE `cars` SET `Health` = '".. tostring (Health) .."' WHERE `accountName` = '" .. tostring ( accountName ) .."' AND CarName = '".. tostring ( Car ) .."'" ) end function removeCarFromDatabase ( player,Car ) local account = getPlayerAccount ( player ) local accountName = getAccountName ( account ) if ( not doesCarExist ( player,Car ) ) then return false, "A Car with this name already exist." end if ( executeSQLQuery("DELETE FROM `cars` WHERE `accountName` = '" .. tostring ( accountName ) .. "' AND CarName = '".. tostring ( Car ) .."'" ) ) then else return false, "Unable to create Car." end end function getAccountCars ( player ) local account = getPlayerAccount ( player ) local accountName = getAccountName ( account ) local result = executeSQLQuery ( "SELECT * FROM cars WHERE accountName = ?", tostring ( accountName ) ) if ( type ( result ) == "table" and #result == 0 or not result ) then return { } else return result end end function getCarHealth ( player,Car ) local account = getPlayerAccount ( player ) local accountName = getAccountName ( account ) local result = executeSQLQuery ( "SELECT * FROM cars WHERE accountName = ? AND CarName = ?", tostring ( accountName ), tostring ( Car ) ) if ( type ( result ) == "table" and #result == 0 or not result ) then return "None" else return result[ 1 ][ "Health" ] end end ---------- Tirger addEvent("BuyVc",true) addEventHandler("BuyVc",root, function (vcName,vcPrize) if not doesCarExist ( source,vcName ) then takePlayerMoney ( source, tonumber(vcPrize) ) addCarToDatabase(source,vcName) outputChatBox("The car was purchased, Car Panel = ".. getElementData(source,"bin"),source,0,255,0) for index, cars in ipairs ( getAccountCars ( source ) ) do triggerClientEvent("updateCarListc",source,source,cars["CarName"],cars["Health"],index) end else outputChatBox("You already have one of these cars!",source,255,0,0) end end ) addEvent("UpdateCarLists",true) addEventHandler("UpdateCarLists",root, function (player) if getElementData(player,"showCar") == true then local vch = getElementHealth ( getElementData(player,"Car") ) if vch < 300 then removeCarFromDatabase(player,getElementData(player,"CarName")) setElementData(player,"showCar",false) destroyElement(getElementData(player,"Car")) removeElementData(player,"Car") end if vch > 1000 then setCarHealth(player,vcName,1000) else setCarHealth(player,vcName,vch) end end for index, cars in ipairs ( getAccountCars ( player ) ) do triggerClientEvent("updateCarListc",player,player,cars["CarName"],cars["Health"],index) end end ) addEvent("useCar",true) addEventHandler("useCar",root, function (vcName,vcHealth) if getElementData(source,"showCar") == true then local vch = getElementHealth ( getElementData(source,"Car") ) if vch < 300 then removeCarFromDatabase(source,getElementData(source,"CarName")) setElementData(source,"showCar",false) destroyElement(getElementData(source,"Car")) removeElementData(source,"Car") end destroyElement(getElementData(source,"Car")) end local x, y, z = getElementPosition ( source ) local vc = createVehicle ( getVehicleModelFromName ( vcName ), x + 1, y, z + 1 ) setElementData(vc,"CarF1",true) setElementData(vc,"CarF1Player",source) setElementHealth ( vc, getCarHealth(source,vcName) ) setElementData(source,"Car",vc) setElementData(source,"showCar",true) setElementData(source,"CarName",vcName) outputChatBox("You have spawned your car",source,0,255,0) end ) addEvent("You have locked your car",true) addEventHandler("lockCar",root, function (vcName) if getElementData(source,"showCar") == true then if getElementData(source,"CarName") == vcName then if isVehicleLocked ( getElementData(source,"Car") ) then setVehicleLocked ( getElementData(source,"Car"), false ) outputChatBox("unlock",source,0,255,0) else setVehicleLocked ( getElementData(source,"Car"), true ) outputChatBox("You have locked your car",source,255,0,0) end end end end ) addEvent("DestroyCar",true) addEventHandler("DestroyCar",root, function (vcName) if getElementData(source,"showCar") == true then if getElementData(source,"CarName") == vcName then local vch = getElementHealth ( getElementData(source,"Car") ) if vch < 300 then removeCarFromDatabase(source,getElementData(source,"CarName")) setElementData(source,"showCar",false) destroyElement(getElementData(source,"Car")) removeElementData(source,"Car") end if vch > 1000 then setCarHealth(source,vcName,1000) else setCarHealth(source,vcName,vch) end destroyElement(getElementData(source,"Car")) setElementData(source,"showCar",false) else outputChatBox("notacar",source,255,0,0) end else outputChatBox("Your car is currently invisible, click use to spawn it",source,255,0,0) end end ) function VehicleLoss(loss) if (getElementData(source,"CarF1") == true) then local vch = getElementHealth ( source ) if vch < 300 then removeCarFromDatabase(getElementData(source,"CarF1Player"),getVehicleName ( source )) setElementData(getElementData(source,"CarF1Player"),"showCar",false) destroyElement(source) removeElementData(getElementData(source,"CarF1Player"),"Car") removeElementData(source,"CarF1Player") setElementData(source,"CarF1",false) end setCarHealth(getElementData(source,"CarF1Player"),getVehicleName ( source ),vch-loss) end end addEventHandler("onVehicleDamage", getRootElement(), VehicleLoss) addEvent("onPlayerGarageEnter", true) addEventHandler("onResourceStart", getResourceRootElement(), function (resource) for i=0,49 do Link to comment
Castillo Posted August 2, 2013 Share Posted August 2, 2013 Where did you get the script? Link to comment
PARKAH Posted August 3, 2013 Author Share Posted August 3, 2013 Somewhere on a MTA resource website, but you probably don't to help me now. Link to comment
EstrategiaGTA Posted August 3, 2013 Share Posted August 3, 2013 Long script but are you sure that's the wrong script? And are your triggered events in the client? Link to comment
PARKAH Posted August 4, 2013 Author Share Posted August 4, 2013 I'm not sure but isn't the save and load there? 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