-misterX- Posted May 4, 2013 Share Posted May 4, 2013 the debug reports error to compare a boolean with a number line 147... any help? server 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("تم شراء السيارة وتم حفظها = ".. 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("لديك مثل هذه السيارة لا يمكنك الحصول على 2",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("تم اظهار سيارتك",source,0,255,0) end ) addEvent("lockCar",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("نم فتح قفل سيارتك",source,0,255,0) else setVehicleLocked ( getElementData(source,"Car"), true ) outputChatBox("تم قفل سيارتك",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("هذه ليست السيارة التي اظهرتها",source,255,0,0) end else outputChatBox("انت لم تستخدم سيارة !!",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
mjau Posted May 4, 2013 Share Posted May 4, 2013 local vch = getElementHealth ( getElementData(player,"Car") Returns false. Im not sure what you are trying to do but getElementData returns a string with data. while getElementHealth needs a vehicle element to work. Link to comment
DiSaMe Posted May 4, 2013 Share Posted May 4, 2013 getElementData returns whatever was set, not necessarily a string. If it returns a boolean, it means either a boolean was set or there was no value set at all. 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