1
0

vehicles.inc 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  1. /*
  2. _____ _ _ _ _
  3. |_ _| | | | | | | (_)
  4. | | _ __ | |_ _ __ ___ __| |_ _ ___| |_ _ ___ _ __
  5. | | | '_ \| __| '__/ _ \ / _` | | | |/ __| __| |/ _ \| '_ \
  6. _| |_| | | | |_| | | (_) | (_| | |_| | (__| |_| | (_) | | | |
  7. |_____|_| |_|\__|_| \___/ \__,_|\__,_|\___|\__|_|\___/|_| |_|
  8. This is the system for player owned vehicles.
  9. Related files are in /gamemodes/inc/vehicles.
  10. -> commands.inc ~ has all player owned vehicle commands.
  11. command related variables are here too!
  12. -> impounds.inc ~ is the impound system.
  13. It's important to note: only the player's spawned vehicle will be saved.
  14. What's in this file?:
  15. Structure,
  16. • definitions & variables
  17. Saving,
  18. • savePlayerVehicle( index )
  19. • savePlayerVehicles()
  20. Loading,
  21. • loadPlayerVehicles()
  22. • setupPlayerVehicles()
  23. Spawning,
  24. • spawnPlayerVehicle( index )
  25. Despawning,
  26. • destroyPlayerVehicle( index )
  27. Creating,
  28. • createPlayerVehicle( playerid, slot, model, x, y, z, rz )
  29. Useful functions
  30. • SetVehicleAlarmState ( vehicleid ), SetVehicleEngineState( vehicleid ), SetVehicleLockState( vehicleid )
  31. */
  32. /*
  33. ===================================================
  34. _____ _ _
  35. / ____| | | |
  36. | (___ | |_ _ __ _ _ ___| |_ _ _ _ __ ___
  37. \___ \| __| '__| | | |/ __| __| | | | '__/ _ \
  38. ____) | |_| | | |_| | (__| |_| |_| | | | __/
  39. |_____/ \__|_| \__,_|\___|\__|\__,_|_| \___|
  40. Definitions & variables
  41. ===================================================
  42. */
  43. #define MAX_OWNED_VEHICLES 4000
  44. //custom color for new systems
  45. #define COLOR_VEHICLES 0xFFB76FFF
  46. #define MAX_SPAWNED_VEHICLES 1
  47. //Structure of each vehicle.
  48. enum pvehicleDatav {
  49. pvID, //Array index
  50. pvplayerID,
  51. pvspawned, //Vehicles can be loaded, but not spawned
  52. pvSQLID, //SQL ID of the vehicle in the DB.
  53. pvpID, //Related player SQL ID.
  54. pvmodel,
  55. Float:pvx,
  56. Float:pvy,
  57. Float:pvz,
  58. Float:pvrz,
  59. pvcolor1,
  60. pvcolor2,
  61. pvpaintjob,
  62. pvlocked,
  63. pvgas,
  64. Float:pvdamage,
  65. //parking & towing
  66. Float:pvparkx,
  67. Float:pvparky,
  68. Float:pvparkz,
  69. Float:pvparkrz,
  70. //impound system
  71. pvimpounded,
  72. //upgrades
  73. pvgps,
  74. pvalarm,
  75. pvinsurance,
  76. pvsparekey,
  77. pvplate[9],
  78. //trunk stuff
  79. pvGun1,
  80. pvGun2,
  81. pvPot,
  82. pvCrack,
  83. Float:pvArmor,
  84. pvtow, //add towbar too!
  85. //damage
  86. pvdpanels,
  87. pvddoors,
  88. pvdlights,
  89. pvdtires,
  90. //mod shop stuff
  91. pvcomponents[14],
  92. pvvw
  93. }
  94. //Stores all vehicle data.
  95. new PlayerVehicles[MAX_PLAYERS][MAX_VEHICLE_SLOTS][pvehicleDatav]
  96. //Stores the number of vehicle in the DB.
  97. new pVehiclePool
  98. //Stores the last SQL ID (auto increment)
  99. new lastvehSQLID
  100. //stores current spawned vehicle
  101. new playerSpawnedVehicle[MAX_PLAYERS] = {-1,...}
  102. //vupgrade misc
  103. new spareKeys[MAX_PLAYERS] = -1
  104. new spareKeysSlot[MAX_PLAYERS] = -1
  105. new hasgivenKey[MAX_PLAYERS]
  106. /*
  107. ======================================================
  108. _ _ _
  109. | | | (_)
  110. | | ___ __ _ __| |_ _ __ __ _
  111. | | / _ \ / _` |/ _` | | '_ \ / _` |
  112. | |___| (_) | (_| | (_| | | | | | (_| |
  113. |______\___/ \__,_|\__,_|_|_| |_|\__, |
  114. __/ |
  115. |___/
  116. Loads all vehicle data at once.
  117. =====================================================
  118. */
  119. //Request the data
  120. loadPlayerVehicles( playerid ) {
  121. new query[130];
  122. mysql_format( sqlGameConnection, query, sizeof(query), "SELECT * FROM playervehicles WHERE pID = %d", PlayerInfo[playerid][pID] )
  123. mysql_pquery( sqlGameConnection, query, "setupPlayerVehicles", "i", playerid )
  124. return 1
  125. }
  126. //Collect & process the data
  127. forward setupPlayerVehicles(playerid)
  128. public setupPlayerVehicles(playerid) {
  129. if( cache_get_row_count() < 1 ) {
  130. return 1
  131. }
  132. for( new slot; slot < cache_get_row_count(); slot++ ) {
  133. if( slot >= PlayerInfo[playerid][pMaxCarSlots] ) {
  134. break
  135. }
  136. #define veh(%1) PlayerVehicles[playerid][slot][pv%1]
  137. veh(SQLID) = cache_get_field_content_int( slot, "ID" )
  138. PlayerInfo[playerid][pCarID][slot] = veh(SQLID)
  139. veh(pID) = cache_get_field_content_int( slot, "pID" )
  140. veh(model) = cache_get_field_content_int( slot, "model" )
  141. veh(x) = cache_get_field_content_float( slot, "x" )
  142. veh(y) = cache_get_field_content_float( slot, "y" )
  143. veh(z) = cache_get_field_content_float( slot, "z" )
  144. veh(rz) = cache_get_field_content_float( slot, "rz" )
  145. veh(locked) = cache_get_field_content_int( slot, "locked" )
  146. veh(color1) = cache_get_field_content_int( slot, "color1" )
  147. veh(color2) = cache_get_field_content_int( slot, "color2" )
  148. veh(paintjob) = cache_get_field_content_int( slot, "paintjob" )
  149. veh(gas) = cache_get_field_content_int( slot, "gas" )
  150. veh(damage) = cache_get_field_content_float( slot, "damage" )
  151. //parking & towing
  152. veh(parkx) = cache_get_field_content_float( slot, "parkx" )
  153. veh(parky) = cache_get_field_content_float( slot, "parky" )
  154. veh(parkz) = cache_get_field_content_float( slot, "parkz" )
  155. veh(parkrz) = cache_get_field_content_float( slot, "parkrz" )
  156. //upgrades
  157. veh(gps) = cache_get_field_content_int( slot, "gps" )
  158. veh(insurance) = cache_get_field_content_int( slot, "insurance" )
  159. veh(alarm) = cache_get_field_content_int( slot, "alarm" )
  160. veh(sparekey) = cache_get_field_content_int( slot, "sparekey" )
  161. cache_get_field_content( slot, "plate", veh(plate), sqlGameConnection, 9 )
  162. //trunk
  163. veh(Gun1) = cache_get_field_content_int( slot, "Gun1" )
  164. veh(Gun2) = cache_get_field_content_int( slot, "Gun2" )
  165. veh(Pot) = cache_get_field_content_int( slot, "Pot" )
  166. veh(Crack) = cache_get_field_content_int( slot, "Crack" )
  167. veh(Armor) = cache_get_field_content_int( slot, "Armor" )
  168. veh(dpanels) = cache_get_field_content_int( slot, "dpanels" )
  169. veh(ddoors) = cache_get_field_content_int( slot, "ddoors" )
  170. veh(dlights) = cache_get_field_content_int( slot, "dlights" )
  171. veh(dtires) = cache_get_field_content_int( slot, "dtires" )
  172. veh(impounded) = cache_get_field_content_int( slot, "impounded" )
  173. //get vehicle component data
  174. new compstr[50];
  175. for( new c; c < 14; c++ ) {
  176. format( compstr, 50, "component%d", c );
  177. veh(components)[c] = cache_get_field_content_int( slot, compstr );
  178. }
  179. lastvehSQLID = veh(SQLID)
  180. pVehiclePool++
  181. //spawn the last vehicle the player had
  182. if( PlayerInfo[playerid][lastCarID] > -1 ) {
  183. if( PlayerInfo[playerid][lastCarID] == veh(SQLID) ) {
  184. spawnPlayerVehicle( playerid, slot, 1 ) //1: spawns in last position, than last parked
  185. }
  186. }
  187. #undef veh
  188. }
  189. printf( "DEBUG: loaded playerid's %d owned vehicles, vehicle pool is: %d.", playerid, pVehiclePool )
  190. return 1
  191. }
  192. /*
  193. ====================================
  194. _____ _
  195. / ____| (_)
  196. | (___ __ ___ ___ _ __ __ _
  197. \___ \ / _` \ \ / / | '_ \ / _` |
  198. ____) | (_| |\ V /| | | | | (_| |
  199. |_____/ \__,_| \_/ |_|_| |_|\__, |
  200. __/ |
  201. |___/
  202. Save all vehicles, or save one vehicle.
  203. =====================================
  204. */
  205. //Save all vehicles
  206. /*savePlayerVehicles() {
  207. new query[450]
  208. for( new i; i <= GetPlayerPoolSize(); i++ ) {
  209. for( new slot; slot < MAX_VEHICLE_SLOTS; slot++ ) {
  210. #define veh(%1) PlayerVehicles[i][slot][pv%1]
  211. if( PlayerInfo[i][pCarID][slot] < 1 ) continue
  212. GetVehicleHealth( veh(ID), veh(damage) )
  213. GetVehiclePos( veh(ID), veh(x), veh(y), veh(z) )
  214. GetVehicleZAngle( veh(ID), veh(rz) )
  215. veh(vw) = GetVehicleVirtualWorld( veh(ID) )
  216. //get trunk data to save
  217. if( veh(spawned) ) {
  218. veh(Gun1) = TrunkInfo[veh(ID)][cGun1]
  219. veh(Gun2) = TrunkInfo[veh(ID)][cGun2]
  220. veh(Pot) = TrunkInfo[veh(ID)][cPot]
  221. veh(Crack) = TrunkInfo[veh(ID)][cCrack]
  222. veh(Armor) = TrunkInfo[veh(ID)][cArmor]
  223. }
  224. GetVehicleDamageStatus( veh(ID), veh(dpanels), veh(ddoors), veh(dlights), veh(dtires) )
  225. mysql_format( sqlGameConnection, query, sizeof( query ), "UPDATE playervehicles SET pID = %d, model = %d, x = %f, y = %f, z = %f, rz = %f, locked = %d,",
  226. veh(pID), veh(model), veh(x), veh(y), veh(z), veh(rz), veh(locked) )
  227. mysql_format( sqlGameConnection, query, sizeof( query ), "%s color1 = %d, color2 = %d, paintjob = %d, gas = %d, damage = %f, gps = %d, alarm = %d, sparekey = %d, plate = '%e',",
  228. query, veh(color1), veh(color2), veh(paintjob), Gas[veh(ID)], veh(damage), veh(gps), veh(alarm), veh(sparekey), veh(plate) )
  229. mysql_format( sqlGameConnection, query, sizeof( query ), "%s Gun1 = %d, Gun2 = %d, Pot = %d, Crack = %d, Armor = %f, parkx = %f, parky = %f, parkz = %f, parkrz = %f,",
  230. query, veh(Gun1), veh(Gun2), veh(Pot), veh(Crack), veh(Armor), veh(parkx), veh(parky), veh(parkz), veh(parkrz) )
  231. mysql_format( sqlGameConnection, query, sizeof( query ), "%s dpanels = %d, ddoors = %d, dlights = %d, dtires = %d, vw = %d, ",
  232. query, veh(dpanels), veh(ddoors), veh(dlights), veh(dtires), veh(vw) )
  233. //get vehicle component data
  234. new compstr[50];
  235. for( new c; c < 14; c++ ) {
  236. veh(components)[c] = GetVehicleComponentInSlot( veh(ID), c );
  237. format( compstr, 50, "component%d, ", c );
  238. mysql_format( sqlGameConnection, query, sizeof( query ), "%s %s = %d", query, compstr, veh(components)[c] );
  239. }
  240. mysql_format( sqlGameConnection, query, sizeof( query ), "%s WHERE ID = %d;", query, veh(SQLID) );
  241. mysql_pquery( sqlGameConnection, query ) //Want to save this in the main thread before the client closes connection
  242. #undef veh
  243. }
  244. }
  245. return 1
  246. }*/
  247. //Save a single vehicle
  248. savePlayerVehicle( playerid, slot ) {
  249. new query[1000]
  250. #define veh(%1) PlayerVehicles[playerid][slot][pv%1]
  251. //if( PlayerInfo[playerid][pCarID][slot] != veh(pID) ) return 1
  252. if( !veh(spawned) ) return 1; //else negative arrays
  253. //get trunk data to save
  254. GetVehicleHealth( veh(ID), veh(damage) )
  255. GetVehiclePos( veh(ID), veh(x), veh(y), veh(z) )
  256. GetVehicleZAngle( veh(ID), veh(rz) )
  257. veh(vw) = GetVehicleVirtualWorld( veh(ID) )
  258. veh(Gun1) = TrunkInfo[veh(ID)][cGun1]
  259. veh(Gun2) = TrunkInfo[veh(ID)][cGun2]
  260. veh(Pot) = TrunkInfo[veh(ID)][cPot]
  261. veh(Crack) = TrunkInfo[veh(ID)][cCrack]
  262. veh(Armor) = TrunkInfo[veh(ID)][cArmor]
  263. GetVehicleDamageStatus( veh(ID), veh(dpanels), veh(ddoors), veh(dlights), veh(dtires) )
  264. veh(gas) = Gas[veh(ID)]
  265. mysql_format( sqlGameConnection, query, sizeof( query ), "UPDATE playervehicles SET pID = %d, model = %d, x = %f, y = %f, z = %f, rz = %f, locked = %d,",
  266. veh(pID), veh(model), veh(x), veh(y), veh(z), veh(rz), veh(locked) )
  267. mysql_format( sqlGameConnection, query, sizeof( query ), "%s color1 = %d, color2 = %d, paintjob = %d, gas = %d, damage = %f, gps = %d, alarm = %d, sparekey = %d, plate = '%e',",
  268. query, veh(color1), veh(color2), veh(paintjob), veh(gas), veh(damage), veh(gps), veh(alarm), veh(sparekey), veh(plate) )
  269. mysql_format( sqlGameConnection, query, sizeof( query ), "%s Gun1 = %d, Gun2 = %d, Pot = %d, Crack = %d, Armor = %f, parkx = %f, parky = %f, parkz = %f, parkrz = %f,",
  270. query, veh(Gun1), veh(Gun2), veh(Pot), veh(Crack), veh(Armor), veh(parkx), veh(parky), veh(parkz), veh(parkrz) )
  271. mysql_format( sqlGameConnection, query, sizeof( query ), "%s dpanels = %d, ddoors = %d, dlights = %d, dtires = %d, vw = %d, impounded = %d",
  272. query, veh(dpanels), veh(ddoors), veh(dlights), veh(dtires), veh(vw), veh(impounded) )
  273. //get vehicle component data
  274. for( new c; c < 14; c++ ) {
  275. PlayerVehicles[playerid][slot][pvcomponents][c] = GetVehicleComponentInSlot( veh(ID), c );
  276. mysql_format( sqlGameConnection, query, sizeof( query ), "%s, component%d = %d", query, c, PlayerVehicles[playerid][slot][pvcomponents][c] );
  277. }
  278. mysql_format( sqlGameConnection, query, sizeof( query ), "%s WHERE ID = %d;", query, veh(SQLID) );
  279. mysql_pquery( sqlGameConnection, query ) //Want to save this in the main thread before the client closes connection
  280. #undef veh
  281. return 1
  282. }
  283. /*
  284. ====================================================
  285. _____ _
  286. / ____| (_)
  287. | (___ _ __ __ ___ ___ __ _ _ __ __ _
  288. \___ \| '_ \ / _` \ \ /\ / / '_ \| | '_ \ / _` |
  289. ____) | |_) | (_| |\ V V /| | | | | | | | (_| |
  290. |_____/| .__/ \__,_| \_/\_/ |_| |_|_|_| |_|\__, |
  291. | | __/ |
  292. |_| |___/
  293. Spawn both of the player's vehicle, or spawn one
  294. based on its ~index~.
  295. ====================================================
  296. */
  297. //Spawn a single player vehicle
  298. spawnPlayerVehicle( playerid, slot, lastpos = 0 ) {
  299. #define veh(%1) PlayerVehicles[playerid][slot][pv%1] //This is just a marco to reduce repetition!
  300. if( PlayerInfo[playerid][pCarID][slot] < 1 ) return 1;
  301. //If it hasn't already been spawned...
  302. if( !veh(spawned) && !veh(impounded) ) {
  303. playerSpawnedVehicle[playerid] = slot
  304. if( !lastpos ) {
  305. veh(ID) = CreateVehicle( veh(model), veh(parkx), veh(parky), veh(parkz), veh(parkrz), veh(color1), veh(color2), -1 )
  306. }
  307. else {
  308. veh(ID) = CreateVehicle( veh(model), veh(x), veh(y), veh(z), veh(rz), veh(color1), veh(color2), -1 )
  309. }
  310. SetVehicleVirtualWorld( veh(ID), veh(vw) )
  311. SetVehicleNumberPlate( veh(ID), veh(plate) )
  312. SetVehicleLockState( veh(ID), veh(locked) )
  313. engineOn[veh(ID)] = 0 //set engine vars off
  314. playerDisabledEngine[veh(ID)] = 1
  315. //set the trunk items
  316. TrunkInfo[veh(ID)][cGun1] = veh(Gun1)
  317. TrunkInfo[veh(ID)][cGun2] = veh(Gun2)
  318. TrunkInfo[veh(ID)][cPot] = veh(Pot)
  319. TrunkInfo[veh(ID)][cCrack] = veh(Crack)
  320. TrunkInfo[veh(ID)][cArmor] = veh(Armor)
  321. //set component info
  322. //get vehicle component data
  323. for( new c; c < 14; c++ ) {
  324. if( veh(components)[c] ) {
  325. AddVehicleComponent( veh(ID), veh(components)[c] );
  326. }
  327. }
  328. veh(playerID) = playerid
  329. veh(spawned) = 1
  330. //totalled state
  331. if( veh(damage) < 300.0 ) {
  332. veh(damage) = 305.0
  333. }
  334. //set the damage/gas
  335. UpdateVehicleDamageStatus( veh(ID), veh(dpanels), veh(ddoors), veh(dlights), veh(dtires) )
  336. SetVehicleHealth( veh(ID), veh(damage) )
  337. Gas[veh(ID)] = veh(gas)
  338. printf("DEBUG: Spawned playerid's %d vehicle at last position: %f, %f, %f.", playerid, veh(x), veh(y), veh(z) )
  339. }
  340. #undef veh
  341. return 1
  342. }
  343. /*
  344. ==============================================================
  345. _____ _
  346. | __ \ (_)
  347. | | | | ___ ___ _ __ __ ___ ___ __ _ _ __ __ _
  348. | | | |/ _ \/ __| '_ \ / _` \ \ /\ / / '_ \| | '_ \ / _` |
  349. | |__| | __/\__ \ |_) | (_| |\ V V /| | | | | | | | (_| |
  350. |_____/ \___||___/ .__/ \__,_| \_/\_/ |_| |_|_|_| |_|\__, |
  351. | | __/ |
  352. |_| |___/
  353. Saves, resets trunk data for the vehicle ID,
  354. and destroys the vehicle.
  355. ==============================================================
  356. */
  357. destroyPlayerVehicle( playerid, slot ) {
  358. #define veh(%1) PlayerVehicles[playerid][slot][pv%1]
  359. if( veh(spawned) ) {
  360. savePlayerVehicle( playerid, slot )
  361. TrunkInfo[veh(ID)][cGun1] = 0
  362. TrunkInfo[veh(ID)][cGun2] = 0
  363. TrunkInfo[veh(ID)][cPot] = 0
  364. TrunkInfo[veh(ID)][cCrack] = 0
  365. TrunkInfo[veh(ID)][cArmor] = 0
  366. veh(spawned) = 0
  367. //veh(playerID) = INVALID_PLAYER_ID
  368. //get damage states
  369. GetVehicleDamageStatus( veh(ID), veh(dpanels), veh(ddoors), veh(dlights), veh(dtires) )
  370. //Get last position
  371. GetVehiclePos( veh(ID), veh(x), veh(y), veh(z) )
  372. GetVehicleZAngle( veh(ID), veh(rz) )
  373. //reset params for this vehicle ID
  374. SetVehicleParamsEx( veh(ID), 0, 0, 0, 0, 0, 0, 0 )
  375. DestroyVehicle( veh(ID) )
  376. for( new i; i < GetPlayerPoolSize(); i++ ) {
  377. if( spareKeys[i] == playerid ) {
  378. spareKeys[i] = -1
  379. spareKeysSlot[i] = -1
  380. }
  381. }
  382. hasgivenKey[playerid] = 0
  383. veh(ID) = INVALID_VEHICLE_ID
  384. playerSpawnedVehicle[playerid] = -1
  385. return 1
  386. }
  387. #undef veh
  388. return 0
  389. }
  390. /*
  391. ========================================================
  392. _____ _ _
  393. / ____| | | (_)
  394. | | _ __ ___ __ _| |_ _ _ __ __ _
  395. | | | '__/ _ \/ _` | __| | '_ \ / _` |
  396. | |____| | | __/ (_| | |_| | | | | (_| |
  397. \_____|_| \___|\__,_|\__|_|_| |_|\__, |
  398. __/ |
  399. |___/
  400. Creates a vehicle given the player it's being
  401. created for, and the player's vehicle slot (
  402. given the vehicle slot is free).
  403. =======================================================
  404. */
  405. //Give the player a vehicle.
  406. createPlayerVehicle( playerid, slot, model, Float:x, Float:y, Float:z, Float:rz ) {
  407. if( pVehiclePool == MAX_OWNED_VEHICLES-1 ) return 1
  408. lastvehSQLID++
  409. pVehiclePool++ //increase this after - start at index 0
  410. #define veh(%1) PlayerVehicles[playerid][slot][pv%1]
  411. veh(pID) = PlayerInfo[playerid][pID]
  412. veh(model) = model
  413. veh(parkx) = x
  414. veh(parky) = y
  415. veh(parkz) = z
  416. veh(parkrz) = rz
  417. veh(SQLID) = lastvehSQLID
  418. veh(gas) = 100
  419. veh(gps) = 0
  420. veh(sparekey) = 0
  421. veh(insurance) = 0
  422. veh(alarm) = 0
  423. veh(damage) = 1000
  424. veh(playerID) = playerid
  425. veh(color1) = random(255);
  426. veh(color2) = random(255);
  427. GenerateRandomPlate( playerid, slot )
  428. PlayerInfo[playerid][pCarID][slot] = veh(SQLID)
  429. //Don't spawn it, it'll show in /myvehicles
  430. new query[500]
  431. mysql_format( sqlGameConnection, query, sizeof( query ), "INSERT INTO playervehicles SET pID = %d, model = %d, parkx = %f, parky = %f, parkz = %f, parkrz = %f, locked = 0, color1 = 0, color2 = 0, damage=1000, gas=100, plate = '%e'", PlayerInfo[playerid][pID], model, x, y, z, rz, veh(plate) )
  432. mysql_pquery( sqlGameConnection, query )
  433. #undef veh
  434. return 1
  435. }
  436. /*
  437. ========================================
  438. _ _ __ _
  439. | | | | / _| | |
  440. | | | |___ ___| |_ _ _| |
  441. | | | / __|/ _ \ _| | | | |
  442. | |__| \__ \ __/ | | |_| | |
  443. \____/|___/\___|_| \__,_|_|
  444. • getVehicleIndex returns the array index
  445. of PlayerVehicles[][], the more information
  446. that is given, the quicker it runs.
  447. • SetVehicleLockState, SetVehicleAlarmState,
  448. SetVehicleEngineState - toggles the vehicle's x,
  449. given the vehicleid.
  450. =========================================
  451. */
  452. GetPlayerFreeCarslot( playerid ) {
  453. for( new i; i < PlayerInfo[playerid][pMaxCarSlots]; i++ ) {
  454. if( PlayerInfo[playerid][pCarID][i] < 1 ) {
  455. return i
  456. }
  457. }
  458. return -1
  459. }
  460. IsVehicleOccupied( vehicleid ) {
  461. for( new p; p <= GetPlayerPoolSize(); p++ ) {
  462. if( IsPlayerConnected( p ) ) {
  463. new pstate = GetPlayerState( p )
  464. if( pstate == PLAYER_STATE_DRIVER || pstate == PLAYER_STATE_PASSENGER ) {
  465. if( GetPlayerVehicleID( p ) == vehicleid ) {
  466. return 1
  467. }
  468. }
  469. }
  470. }
  471. return 0
  472. }
  473. RandomChars( characters[], size = sizeof( characters ) ) {
  474. new const charset[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  475. for( new c; c < size; c++ ) {
  476. characters[c] = charset[random(sizeof(charset) - 1)];
  477. }
  478. return 1;
  479. }
  480. GenerateRandomPlate( playerid, slot ) {
  481. RandomChars( PlayerVehicles[playerid][slot][pvplate], 9 );
  482. return 1
  483. }
  484. SetVehicleLockState( vehicleid, lockstate ) {
  485. new engine, lights, alarm, doors, bonnet, boot, objective;
  486. GetVehicleParamsEx( vehicleid, engine, lights, alarm, doors, bonnet, boot, objective )
  487. SetVehicleParamsEx( vehicleid, engine, lights, alarm, lockstate, bonnet, boot, objective )
  488. gCarLock[vehicleid] = lockstate
  489. return 1
  490. }
  491. new vehAlarm[MAX_VEHICLES]
  492. SetVehicleAlarmState( vehicleid, toggle = 1 ) {
  493. if( toggle == 0 ) {
  494. vehAlarm[vehicleid] = 0;
  495. return 1;
  496. }
  497. vehAlarm[vehicleid] = gettime();
  498. return 1
  499. }
  500. new vehicleLights[MAX_VEHICLES]
  501. SetVehicleLightsState( vehicleid, lightstate ) {
  502. new engine, lights, alarm, doors, bonnet, boot, objective;
  503. GetVehicleParamsEx( vehicleid, engine, lights, alarm, doors, bonnet, boot, objective )
  504. SetVehicleParamsEx( vehicleid, engine, lightstate, alarm, doors, bonnet, boot, objective )
  505. vehicleLights[vehicleid] = lightstate
  506. return 1
  507. }
  508. SetVehicleEngineState( vehicleid, enginestate ) {
  509. new engine, lights, alarm, doors, bonnet, boot, objective;
  510. GetVehicleParamsEx( vehicleid, engine, lights, alarm, doors, bonnet, boot, objective )
  511. SetVehicleParamsEx( vehicleid, enginestate, lights, alarm, doors, bonnet, boot, objective )
  512. engineOn[vehicleid] = enginestate
  513. return 1
  514. }
  515. public OnVehiclePaintjob( playerid, vehicleid, paintjobid ) {
  516. new pvid = playerSpawnedVehicle[playerid]
  517. if( pvid > -1 ) {
  518. if( PlayerVehicles[playerid][pvid][pvID] == vehicleid ) {
  519. printf("paintjobtest");
  520. PlayerVehicles[playerid][pvid][pvpaintjob] = paintjobid;
  521. }
  522. }
  523. return 1;
  524. }
  525. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  526. {
  527. for( new i; i <= GetPlayerPoolSize(); i++ ) {
  528. new slot = playerSpawnedVehicle[i]
  529. if( PlayerVehicles[i][slot][pvID] == vehicleid ) {
  530. PlayerVehicles[i][slot][pvcolor1] = color1
  531. PlayerVehicles[i][slot][pvcolor2] = color2
  532. break
  533. }
  534. }
  535. return 1
  536. }
  537. enum ca_Info
  538. {
  539. c_ID,
  540. c_Model,
  541. Float:c_ParkPos[4],
  542. Float:c_LastPos[4],
  543. c_Component[14],
  544. c_Color[2],
  545. c_PaintJob,
  546. c_Alarm,
  547. c_Insurance,
  548. c_Plate[10],
  549. c_GPS,
  550. c_Tow,
  551. c_Keys,
  552. c_Lock,
  553. c_Price,
  554. c_Trunk,
  555. c_Gun[2],
  556. c_Pot,
  557. c_Crack,
  558. Float:c_Armor,
  559. c_VW,
  560. c_Impounded
  561. };
  562. /*CheckVehicleTable() {
  563. mysql_pquery( sqlGameConnection, "SELECT ID FROM playervehicles;", "GetPlayerOldvehicleDatav", "" );
  564. return 1;
  565. }
  566. forward GetPlayerOldvehicleDatav();
  567. public GetPlayerOldvehicleDatav() {
  568. if( cache_get_row_count() ) return 1; //don't convert if there already exists vehicles
  569. mysql_pquery( sqlGameConnection, "SELECT CKey1, CKey2, Name, ID FROM players;", "ConvertPlayerVehicles", "" );
  570. return 1;
  571. }
  572. //vehicle data
  573. new vehicleDatav[ca_Info];
  574. forward ConvertPlayerVehicles();
  575. public ConvertPlayerVehicles() {
  576. new rows, fields;
  577. cache_get_data( rows, fields );
  578. printf( "Converting %d player vehicle rows." );
  579. if( !rows ) return 1;
  580. new key[2], Name[MAX_PLAYER_NAME+1], id;
  581. for( new i; i < rows; i++ ) {
  582. id = cache_get_field_content_int( i, "ID" );
  583. key[0] = cache_get_field_content_int( i, "CKey1" );
  584. key[1] = cache_get_field_content_int( i, "CKey2" );
  585. cache_get_field_content( i, "Name", Name, sqlGameConnection, MAX_PLAYER_NAME+1 );
  586. new query[1000];
  587. for( new d; d < sizeof( key ); d++ ) {
  588. if( key[d] ) {
  589. new strFile[48];
  590. format(strFile, sizeof(strFile), "cars/%d.ini", key[d] );
  591. if(!fexist(strFile)) {
  592. printf("ConvertPlayerVehicles(SQL;%d) > Car %d file doesn't exist (carkeyID: %d)", id, d, key[d]);
  593. continue;
  594. }
  595. new File:fCar = fopen(strFile, io_read);
  596. new strData[128], strKey[128];
  597. while(fread(fCar, strData, sizeof(strData)))
  598. {
  599. strKey = ini_GetKey(strData);
  600. if(strcmp(strKey, "Model") == 0) vehicleDatav[c_Model] = strvalEx(ini_GetValue(strData));
  601. else if(strcmp(strKey, "X") == 0) vehicleDatav[c_ParkPos][0] = floatstr(ini_GetValue(strData));
  602. else if(strcmp(strKey, "Y") == 0) vehicleDatav[c_ParkPos][1] = floatstr(ini_GetValue(strData));
  603. else if(strcmp(strKey, "Z") == 0) vehicleDatav[c_ParkPos][2] = floatstr(ini_GetValue(strData));
  604. else if(strcmp(strKey, "A") == 0) vehicleDatav[c_ParkPos][3] = floatstr(ini_GetValue(strData));
  605. else if(strcmp(strKey, "LX") == 0) vehicleDatav[c_LastPos][0] = floatstr(ini_GetValue(strData));
  606. else if(strcmp(strKey, "LY") == 0) vehicleDatav[c_LastPos][1] = floatstr(ini_GetValue(strData));
  607. else if(strcmp(strKey, "LZ") == 0) vehicleDatav[c_LastPos][2] = floatstr(ini_GetValue(strData));
  608. else if(strcmp(strKey, "LA") == 0) vehicleDatav[c_LastPos][3] = floatstr(ini_GetValue(strData));
  609. else if(strcmp(strKey, "C1") == 0) vehicleDatav[c_Color][0] = strvalEx(ini_GetValue(strData));
  610. else if(strcmp(strKey, "C2") == 0) vehicleDatav[c_Color][1] = strvalEx(ini_GetValue(strData));
  611. else if(strcmp(strKey, "PJ") == 0) vehicleDatav[c_PaintJob] = strvalEx(ini_GetValue(strData));
  612. else if(strcmp(strKey, "comp0") == 0) vehicleDatav[c_Component][0] = strvalEx(ini_GetValue(strData));
  613. else if(strcmp(strKey, "comp1") == 0) vehicleDatav[c_Component][1] = strvalEx(ini_GetValue(strData));
  614. else if(strcmp(strKey, "comp2") == 0) vehicleDatav[c_Component][2] = strvalEx(ini_GetValue(strData));
  615. else if(strcmp(strKey, "comp3") == 0) vehicleDatav[c_Component][3] = strvalEx(ini_GetValue(strData));
  616. else if(strcmp(strKey, "comp4") == 0) vehicleDatav[c_Component][4] = strvalEx(ini_GetValue(strData));
  617. else if(strcmp(strKey, "comp5") == 0) vehicleDatav[c_Component][5] = strvalEx(ini_GetValue(strData));
  618. else if(strcmp(strKey, "comp6") == 0) vehicleDatav[c_Component][6] = strvalEx(ini_GetValue(strData));
  619. else if(strcmp(strKey, "comp7") == 0) vehicleDatav[c_Component][7] = strvalEx(ini_GetValue(strData));
  620. else if(strcmp(strKey, "comp8") == 0) vehicleDatav[c_Component][8] = strvalEx(ini_GetValue(strData));
  621. else if(strcmp(strKey, "comp9") == 0) vehicleDatav[c_Component][9] = strvalEx(ini_GetValue(strData));
  622. else if(strcmp(strKey, "comp10") == 0) vehicleDatav[c_Component][10] = strvalEx(ini_GetValue(strData));
  623. else if(strcmp(strKey, "comp11") == 0) vehicleDatav[c_Component][11] = strvalEx(ini_GetValue(strData));
  624. else if(strcmp(strKey, "comp12") == 0) vehicleDatav[c_Component][12] = strvalEx(ini_GetValue(strData));
  625. else if(strcmp(strKey, "comp13") == 0) vehicleDatav[c_Component][13] = strvalEx(ini_GetValue(strData));
  626. else if(strcmp(strKey, "alarm") == 0) vehicleDatav[c_Alarm] = strvalEx(ini_GetValue(strData));
  627. else if(strcmp(strKey, "ins") == 0) vehicleDatav[c_Insurance] = strvalEx(ini_GetValue(strData));
  628. else if(strcmp(strKey, "plate") == 0) format(vehicleDatav[c_Plate], 10, ini_GetValue(strData));
  629. else if(strcmp(strKey, "gps") == 0) vehicleDatav[c_GPS] = strvalEx(ini_GetValue(strData));
  630. else if(strcmp(strKey, "tow") == 0) vehicleDatav[c_Tow] = strvalEx(ini_GetValue(strData));
  631. else if(strcmp(strKey, "keys") == 0) vehicleDatav[c_Keys] = strvalEx(ini_GetValue(strData));
  632. else if(strcmp(strKey, "lock") == 0) vehicleDatav[c_Lock] = strvalEx(ini_GetValue(strData));
  633. else if(strcmp(strKey, "price") == 0) vehicleDatav[c_Price] = strvalEx(ini_GetValue(strData));
  634. else if(strcmp(strKey, "virtualworld") == 0) vehicleDatav[c_VW] = strvalEx(ini_GetValue(strData));
  635. else if(strcmp(strKey, "trunk_opened") == 0) vehicleDatav[c_Trunk] = strvalEx(ini_GetValue(strData));
  636. else if(strcmp(strKey, "trunk_gun1") == 0) vehicleDatav[c_Gun][0] = strvalEx(ini_GetValue(strData));
  637. else if(strcmp(strKey, "trunk_gun2") == 0) vehicleDatav[c_Gun][1] = strvalEx(ini_GetValue(strData));
  638. else if(strcmp(strKey, "trunk_pot") == 0) vehicleDatav[c_Pot] = strvalEx(ini_GetValue(strData));
  639. else if(strcmp(strKey, "trunk_crack") == 0) vehicleDatav[c_Crack] = strvalEx(ini_GetValue(strData));
  640. else if(strcmp(strKey, "trunk_armor") == 0) vehicleDatav[c_Armor] = floatstr(ini_GetValue(strData));
  641. else if(strcmp(strKey, "impounded") == 0) vehicleDatav[c_Impounded] = strvalEx(ini_GetValue(strData));
  642. }
  643. fclose(fCar);
  644. if( vehicleDatav[c_Model] < 0 ) {
  645. printf("Unable to convert player: %s's vehicle, model: %d", Name, vehicleDatav[c_Model] );
  646. continue;
  647. }
  648. if( vehicleDatav[c_Alarm] < 0 ) vehicleDatav[c_Alarm] = 0;
  649. if( vehicleDatav[c_GPS] < 0 ) vehicleDatav[c_GPS] = 0;
  650. if( vehicleDatav[c_Insurance] < 0 ) vehicleDatav[c_Insurance] = 0;
  651. if( vehicleDatav[c_Keys] < 0 ) vehicleDatav[c_Keys] = 0;
  652. if( vehicleDatav[c_Lock] < 0 ) vehicleDatav[c_Lock] = 0;
  653. if( vehicleDatav[c_Gun][0] < 0 ) vehicleDatav[c_Gun][0] = 0;
  654. if( vehicleDatav[c_Gun][1] < 0 ) vehicleDatav[c_Gun][1] = 0;
  655. if( vehicleDatav[c_Pot] < 0 ) vehicleDatav[c_Pot] = 0;
  656. if( vehicleDatav[c_Crack] < 0 ) vehicleDatav[c_Crack] = 0;
  657. if( vehicleDatav[c_Armor] < 0.0 ) vehicleDatav[c_Armor] = 0.0;
  658. if( vehicleDatav[c_Color][0] < 0 ) vehicleDatav[c_Color][0] = 0;
  659. if( vehicleDatav[c_Color][1] < 0 ) vehicleDatav[c_Color][1] = 0;
  660. if( vehicleDatav[c_PaintJob] < 0 ) vehicleDatav[c_PaintJob] = 0;
  661. if( vehicleDatav[c_VW] < 0 ) vehicleDatav[c_VW] = 0;
  662. if( strlen( vehicleDatav[c_Plate] ) < 2 ) {
  663. RandomChars( vehicleDatav[c_Plate] );
  664. }
  665. mysql_format( sqlGameConnection, query, sizeof( query ), "INSERT INTO playervehicles SET pID = %d, model = %d, parkx = %f, parky = %f, parkz = %f, parkrz = %f,",
  666. id, vehicleDatav[c_Model], vehicleDatav[c_ParkPos][0], vehicleDatav[c_ParkPos][1], vehicleDatav[c_ParkPos][2], vehicleDatav[c_ParkPos][3] );
  667. mysql_format( sqlGameConnection, query, sizeof( query ), "%s alarm = %d, gps = %d, plate = '%e', insurance = %d, sparekey = %d,",
  668. query, vehicleDatav[c_Alarm], vehicleDatav[c_GPS], vehicleDatav[c_Plate], vehicleDatav[c_Insurance], vehicleDatav[c_Keys] );
  669. mysql_format( sqlGameConnection, query, sizeof( query ), "%s locked = %d, Gun1 = %d, Gun2 = %d, Pot = %d, Crack = %d, Armor = %f,",
  670. query, vehicleDatav[c_Lock], vehicleDatav[c_Gun][0], vehicleDatav[c_Gun][1], vehicleDatav[c_Pot], vehicleDatav[c_Crack], vehicleDatav[c_Armor] );
  671. mysql_format( sqlGameConnection, query, sizeof( query ), "%s impounded = 0, color1 = %d, color2 = %d, paintjob = %d, vw = %d, damage=1000, gas=100",
  672. query, vehicleDatav[c_Color][0], vehicleDatav[c_Color][1], vehicleDatav[c_PaintJob], vehicleDatav[c_VW] );
  673. new compstr[100];
  674. for( new c; c < 14; c++ ) {
  675. if( vehicleDatav[c_Component][c] ) {
  676. format( compstr, 100, " component%d", c );
  677. mysql_format( sqlGameConnection, query, sizeof( query ), "%s, %s = %d", query, compstr, vehicleDatav[c_Component][c] );
  678. }
  679. }
  680. mysql_format( sqlGameConnection, query, sizeof( query ), "%s;", query );
  681. mysql_pquery( sqlGameConnection, query );
  682. printf("Converting %s's cars::%s", Name, query );
  683. mysql_format( sqlGameConnection, query, sizeof( query), "SELECT ID FROM playervehicles WHERE pID = %d;", id );
  684. mysql_pquery( sqlGameConnection, query, "CheckPlayerCars", "i", id );
  685. }
  686. }
  687. }
  688. mysql_pquery( sqlGameConnection, "UPDATE players SET maxcarslots = 3;" );
  689. printf( "Vehicle conversion finished." )
  690. return 1;
  691. }
  692. forward CheckPlayerCars( id );
  693. public CheckPlayerCars( id ) {
  694. new rows, fields;
  695. cache_get_data( rows, fields );
  696. if( !rows ) {
  697. printf("Couldn't insert converted player vehicle player SQL ID %d", id );
  698. return 1;
  699. }
  700. return 1;
  701. }*/
  702. #include "inc\vehicles\commands.inc"
  703. #include "inc\vehicles\impounds.inc"
  704. #include "inc\vehicles\hooks.inc"
  705. //#include "../gamemodes/inc/trunk.inc"