Franky Posted October 12, 2008 Share Posted October 12, 2008 function setDataOnStart ( ) for key, value in ipairs(getElementsByType("vehicle")) do local blockState = getElementData ( theVehicle, "engine.block" ) if ( blockState ) == false or ( blockState ) == nil then setElementData ( theVehicle, "engine.block", 100 ) end local battState = getElementData ( theVehicle, "engine.battery" ) if ( battState ) == false or ( battState ) == nil then setElementData ( theVehicle, "engine.battery", 100 ) end local generatorState = getElementData ( theVehicle, "engine.generator" ) if ( generatorState ) == false or ( generatorState ) == nil then setElementData ( theVehicle, "engine.generator", 100 ) end local radiState = getElementData ( theVehicle, "engine.radiator" ) if ( radiState ) == false or ( radiState ) == nil then setElementData ( theVehicle, "engine.radiator", 100 ) end local hosesState = getElementData ( theVehicle, "engine.hoses" ) if ( hosesState ) == false or ( hosesState ) == nil then setElementData ( theVehicle, "engine.hoses", 100 ) end local pistonState = getElementData ( theVehicle, "engine.pistons" ) if ( pistonState ) == false or ( pistonState ) == nil then setElementData ( theVehicle, "engine.pistons", 100 ) end local beltState = getElementData ( theVehicle, "engine.belts" ) if ( beltState ) == false or ( beltState ) == nil then setElementData ( theVehicle, "engine.belts", 100 ) end local gearboxState = getElementData ( theVehicle, "engine.gearbox" ) if ( gearboxState ) == false or ( gearboxState ) == nil then setElementData ( theVehicle, "engine.gearbox", 100 ) end local oilpanState = getElementData ( theVehicle, "engine.oilpan" ) if ( oilpanState ) == false or ( oilpanState ) == nil then setElementData ( theVehicle, "engine.oilpan", 100 ) end local starterState = getElementData ( theVehicle, "engine.starter" ) if ( starterState ) == false or ( starterState ) == nil then setElementData ( theVehicle, "engine.starter", 100 ) end end end addEventHandler ( "onResourceStart", getRootElement ( ), setDataOnStart ) function testing ( source ) local theVehicle = getPlayerOccupiedVehicle ( source ) if ( theVehicle ) == false then else local engBlock = getElementData ( theVehicle, "engine.block" ) local engBattery = getElementData ( theVehicle, "engine.battery" ) local engGenerator = getElementData ( theVehicle, "engine.generator" ) local engRadiator = getElementData ( theVehicle, "engine.radiator" ) local engHoses = getElementData ( theVehicle, "engine.hoses" ) local engPistons = getElementData ( theVehicle, "engine.pistons" ) local engBelts = getElementData ( theVehicle, "engine.belts" ) local engGearbox = getElementData ( theVehicle, "engine.gearbox" ) local engOilpan = getElementData ( theVehicle, "engine.oilpan" ) local engStarter = getElementData ( theVehicle, "engine.starter" ) outputChatBox ( "Engine block state is" .. engBlock .. "%", source, 250, 1, 1 ) outputChatBox ( "Battery state is" .. engBattery .. "%", source, 250, 1, 1 ) outputChatBox ( "Generator state is" .. engGenerator .. "%", source, 250, 1, 1 ) outputChatBox ( "Radiator state is" .. engRadiator .. "%", source, 250, 1, 1 ) outputChatBox ( "Hoses state is" .. engHoses .. "%", source, 250, 1, 1 ) outputChatBox ( "Pistons state is" .. engPistons .. "%", source, 250, 1, 1 ) outputChatBox ( "Belts state is" .. engBelts .. "%", source, 250, 1, 1 ) outputChatBox ( "Gearbox state is" .. engGearbox .. "%", source, 250, 1, 1 ) outputChatBox ( "Oilpan state is" .. engOilpan .. "%", source, 250, 1, 1 ) outputChatBox ( "Starter state is" .. engStarter .. "%", source, 250, 1, 1 ) end end addCommandHandler ( "test", testing ) Im getting bad argument errors on lines 51-60 can anyone help.. i don't understand whats wrong.. and in case you need to know its a server side script Link to comment
Remp Posted October 12, 2008 Share Posted October 12, 2008 the variable theVehicle doesnt exist in setDataOnStart, use value (when you loop through a table using ipairs the second variable you define [value] will be the element from the table [in this case the vehicle element] and the first [key] will be the index) function setDataOnStart ( ) for key, value in ipairs(getElementsByType("vehicle")) do local blockState = getElementData ( value, "engine.block" ) if ( blockState ) == false or ( blockState ) == nil then setElementData ( value, "engine.block", 100 ) end local battState = getElementData ( value, "engine.battery" ) ... Link to comment
Recommended Posts