player.inc 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  1. static carstr[128]; //for user output, static: only works in this file.
  2. static str[128];
  3. /*
  4. ***************** DIALOGS ***************
  5. DEFINITION & VARIABLES
  6. See hooks.inc for OnDialogResponse
  7. ===================================================
  8. */
  9. //Using an enumerator in this case would be less efficient.
  10. #define DIALOG_VEHICLES_UP 9000
  11. #define DIALOG_VEHICLES_UP2 9001
  12. #define DIALOG_CUSTOM_PLATE 9002
  13. #define DIALOG_MYVEHICLES 9003
  14. //the car being upgraded through /vupgrade
  15. new vupgrading[MAX_PLAYERS] = -1;
  16. CMD:carhelp(playerid, params[])
  17. {
  18. SendClientMessage(playerid, COLOR_YELLOW, "____________________________________________");
  19. SendClientMessage(playerid, COLOR_WHITE, "COMMANDS: /v, /breakin, /dealerships, /clearallmods, /clearmods, /windows");
  20. SendClientMessage( playerid, COLOR_WHITE, "COMMANDS: /purchasecar, /spraycar, /lock, /engine, /trunk, /hood, /lights");
  21. return 1;
  22. }
  23. CMD:vehhelp( playerid, params[] ) {
  24. return cmd_carhelp( playerid, params );
  25. }
  26. /*
  27. ******** Player Vehicle Commands *********
  28. ===================================================
  29. */
  30. #define VCMD:%0(%1) cmdveh_%0(%1)
  31. CMD:v( playerid, params[] ) {
  32. new option[20], optional[80];
  33. if( sscanf( params, "s[20]S()[80]", option, optional ) ) {
  34. SendClientMessage( playerid, COLOR_GREY, "{00BFFF}Usage:{FFFFFF} /v [option]" );
  35. SendClientMessage( playerid, COLOR_GREY, "Available options: /v cars, /v spawn, /v park, /v sell, /v dump" );
  36. SendClientMessage( playerid, COLOR_GREY, "Available options: /v upgrade, /v track, /v givekeys");
  37. return 1;
  38. }
  39. //Commands that do not require the player to have a spawned car
  40. if( strcmp( option, "cars", true ) == 0 ) { return cmdveh_cars( playerid ); }
  41. if( strcmp( option, "spawn", true ) == 0 ) { return cmdveh_spawn( playerid, optional ); }
  42. //Commands that do require a spawned car
  43. new slot = GetPlayerSpawnedVehicleSlot( playerid );
  44. if( slot < 0 || slot > PlayerInfo[playerid][pMaxCarSlots] ) return SendClientMessage( playerid, COLOR_GREY, "You do not have any cars spawned. Use '/v spawn' to spawn one." );
  45. new model[80];
  46. format( model, 80, GetVehicleFriendlyNameFromModel( PlayerVehicles[playerid][slot][pvmodel] ) );
  47. if( strcmp( option, "track", true ) == 0 ) { return VCMD:track( playerid, slot, model ); }
  48. if( strcmp( option, "givekeys", true ) == 0 ) { return VCMD:givekeys( playerid, optional, slot, model );}
  49. if( strcmp( option, "park", true ) == 0 ) { return VCMD:park( playerid, slot, model ); }
  50. if( strcmp( option, "upgrade", true ) == 0 ) { return VCMD:upgrade( playerid, slot, model ); }
  51. if( strcmp( option, "sell", true ) == 0 ) { return VCMD:sell( playerid, optional, slot, model ); }
  52. if( strcmp( option, "dump", true ) == 0 ) { return VCMD:dump( playerid, optional, slot, model ); }
  53. return 1;
  54. }
  55. VCMD:dump( playerid, params[], slot, model[] ) {
  56. #define veh(%0) PlayerVehicles[playerid][slot][pv%0]
  57. new cartext[128];
  58. if( GetPlayerVehicleID( playerid ) != veh(ID) ) {
  59. format( cartext, sizeof( cartext ), "You must be inside your %s in order to dump it at the dump.", model );
  60. return SendClientMessage( playerid, COLOR_GREY, cartext );
  61. }
  62. if( !IsPlayerInRangeOfPoint( playerid, 5.0, 134.0741,-256.5139,1.3052 ) ) {
  63. SetPlayerCheckpointEx( playerid, 134.0522,-256.3802,1.3052, 5.0 );
  64. CP[playerid] = CHECKPOINT_CAR_DUMP;
  65. return SendClientMessage( playerid, COLOR_GREY, "You must be at the dump. A red marker has been marked on your map showing you the way." );
  66. }
  67. new moneyback = 0;
  68. if( veh(gps) ) moneyback += 300000;
  69. if( veh(insurance) ) moneyback += 200000;
  70. if( veh(alarm) ) moneyback += 100000;
  71. if( veh(sparekey) ) moneyback += 200000;
  72. new car_str[128];
  73. if( sscanf( params, "s[128]", car_str ) ) {
  74. format( car_str, 128, "You will get a total of $%d for dumping your %s. Are you sure you want to permanently destroy this vehicle?", moneyback, model );
  75. SendClientMessage( playerid, COLOR_WHITE, car_str );
  76. SendClientMessage( playerid, COLOR_GREY, "/v dump [confirm], to proceed." );
  77. return 1;
  78. }
  79. ResetPlayerVehicleSlot( playerid, slot );
  80. format( car_str, 128, "You have dumped for %s for $%d.", model, moneyback );
  81. SendClientMessage( playerid, COLOR_GREY, car_str );
  82. GiveMoney( playerid, moneyback );
  83. #undef veh
  84. return 1;
  85. }
  86. new playeridcarOffered[MAX_PLAYERS] = {-1, ...};
  87. new carOfferedSlot[MAX_PLAYERS] = {-1, ...};
  88. new carOfferedPrice[MAX_PLAYERS] = {-1, ...};
  89. VCMD:sell( playerid, params[], slot, model[] ) {
  90. new player, price, cartext[128];
  91. if( sscanf( params, "ui", player, price ) ) {
  92. return SendClientMessage( playerid, COLOR_GREY, "{00BFFF}Usage:{FFFFFF} /v sell [playerid/playerName] [price]" );
  93. }
  94. if( playerid == player ) {
  95. return SendClientMessage( playerid, COLOR_GREY, "You cannot sell this car to yourself, you already own it." );
  96. }
  97. if( price < 0 ) {
  98. return SendClientMessage( playerid, COLOR_GREY, "You must enter a positive number for the price." );
  99. }
  100. #define veh(%1) PlayerVehicles[playerid][slot][pv%1]
  101. new Float:vpos[3];
  102. GetVehiclePos( veh(ID), vpos[0], vpos[1], vpos[2] );
  103. if( !IsPlayerInRangeOfPoint( playerid, 8.0, vpos[0], vpos[1], vpos[2] ) ) {
  104. format( cartext, sizeof( cartext ), "You must be near your %s in order to sell it.", model );
  105. return SendClientMessage( playerid, COLOR_GREY, cartext );
  106. }
  107. if( !IsPlayerConnected( player ) ) {
  108. return SendClientMessage( playerid, COLOR_GREY, "ERROR: That player is not connected." );
  109. }
  110. new Float:ppos[3];
  111. GetPlayerPos( player, ppos[0], ppos[1], ppos[2] );
  112. if( IsPlayerInRangeOfPoint( playerid, 3.0, ppos[0], ppos[1], ppos[2] ) ) {
  113. format( carstr, sizeof( carstr ), "%s has offered you their %s for $%d, type /purchasecar to accept the vehicle.", PlayerICName( playerid ), model, price );
  114. SendClientMessage( player, COLOR_LIGHTBLUE, carstr );
  115. format( carstr, sizeof( carstr ), "You have offered %s your %s for $%d, please wait for the player to accept it.", PlayerICName( player ), model, price );
  116. SendClientMessage( playerid, COLOR_LIGHTBLUE, carstr );
  117. playeridcarOffered[player] = playerid;
  118. carOfferedSlot[player] = slot;
  119. carOfferedPrice[player] = price;
  120. return 1;
  121. }
  122. #undef veh
  123. SendClientMessage( playerid, COLOR_GREY, "You must be near this player in order to sell them this vehicle." );
  124. return 1;
  125. }
  126. CMD:purchasecar( playerid, params[] ) {
  127. if( playeridcarOffered[playerid] > -1 ) {
  128. new player = playeridcarOffered[playerid];
  129. new slot = carOfferedSlot[playerid];
  130. new price = carOfferedPrice[playerid];
  131. if( !IsValidVehicle( PlayerVehicles[player][slot][pvID] ) || PlayerVehicles[player][slot][pvSQLID] < 1 || PlayerVehicles[player][slot][pvspawned] < 1 ) {
  132. playeridcarOffered[playerid] = -1;
  133. carOfferedPrice[playerid] = -1;
  134. carOfferedSlot[playerid] = -1;
  135. return SendClientMessage( playerid, COLOR_GREY, "This player's vehicle is missing." );
  136. }
  137. if( PlayerInfo[playerid][pCash] < carOfferedPrice[playerid] ) {
  138. return SendClientMessage( playerid, COLOR_GREY, "You cannot afford this." );
  139. }
  140. new freeslot = GetPlayerFreeCarslot( playerid );
  141. if( freeslot == -1 ) {
  142. return SendClientMessage( playerid, COLOR_GREY, "You cannot own anymore vehicles." );
  143. }
  144. playeridcarOffered[playerid] = -1;
  145. carOfferedPrice[playerid] = -1;
  146. carOfferedSlot[playerid] = -1;
  147. GiveMoney( player, price );
  148. GiveMoney( playerid, -price );
  149. //Destroy the player's car if they got one spawned
  150. new isspawned = GetPlayerSpawnedVehicleSlot( playerid );
  151. if( isspawned > -1 ) {
  152. destroyPlayerVehicle( playerid, isspawned );
  153. }
  154. //>>>>[Fetch the seller's car info]<<<<<
  155. #define oldveh(%0) PlayerVehicles[player][slot][pv%0]
  156. //key info
  157. new modelid = oldveh(model), Float:x, Float:y, Float:z,
  158. Float:rz = oldveh(parkrz), vw = GetVehicleVirtualWorld( oldveh(ID) ), paintjob = oldveh(paintjob),
  159. color1 = oldveh(color1), color2 = oldveh(color2);
  160. GetVehiclePos( oldveh(ID), x, y, z );
  161. GetVehicleZAngle( oldveh(ID), rz );
  162. //vehicle trunk
  163. /*new Gun1 = TrunkInfo[oldveh(ID)][cGun1], Gun2 = TrunkInfo[oldveh(ID)][cGun1],
  164. Pot = TrunkInfo[oldveh(ID)][cCannabis], Crack = TrunkInfo[oldveh(ID)][cCocaine], Float:Armor = TrunkInfo[oldveh(ID)][cArmor];*/
  165. //upgrades
  166. new gps = oldveh(gps), alarm = oldveh(alarm), insurance = oldveh(insurance), sparekey = oldveh(sparekey), plate[9];
  167. format( plate, 9, "%s", oldveh(plate) );
  168. //vehicle state
  169. new gas = Gas[oldveh(ID)], dpanels, ddoors, dlights, dtyres, components[14], Float:health;
  170. GetVehicleHealth( oldveh(ID), health );
  171. for( new c; c < 14; c++ ) {
  172. components[c] = GetVehicleComponentInSlot( oldveh(ID), c );
  173. }
  174. GetVehicleDamageStatus( oldveh(ID), dpanels, ddoors, dlights, dtyres );
  175. //destroy the seller's car
  176. ResetPlayerVehicleSlot( player, slot );
  177. #undef oldveh
  178. //>>>>>[Set the buyer's car]<<<<<
  179. //create the player's new vehicle
  180. createPlayerVehicle( playerid, freeslot, modelid, x, y, z, rz, color1, color2 );
  181. #define veh(%0) PlayerVehicles[playerid][freeslot][pv%0]
  182. veh(paintjob) = paintjob;
  183. veh(vw) = vw;
  184. veh(x) = x;
  185. veh(y) = y;
  186. veh(z) = z;
  187. veh(rz) = rz;
  188. veh(gps) = gps;
  189. veh(alarm) = alarm;
  190. veh(insurance) = insurance;
  191. veh(sparekey) = sparekey;
  192. veh(gas) = gas;
  193. veh(ddoors) = ddoors;
  194. veh(dpanels) = dpanels;
  195. veh(dlights) = dlights;
  196. veh(dtires) = dtyres;
  197. veh(damage) = health;
  198. for( new i; i < 14; i++ ) {
  199. veh(components)[i] = components[i];
  200. }
  201. /*veh(Gun1) = Gun1;
  202. veh(Gun2) = Gun2;
  203. veh(Pot) = Pot;
  204. veh(Crack) = Crack;
  205. veh(Armor) = Armor;*/
  206. format( veh(plate), 9, "%s", plate );
  207. //>>>>>[Spawn, save and output success]<<<<<
  208. spawnPlayerVehicle( playerid, freeslot, 1 );
  209. savePlayerVehicle( playerid, freeslot );
  210. printf( "[DEBUG] %s (%d) has sold %s (%d) their %s (%d) for $%d", PlayerICName( player ), PlayerICName( playerid ), GetVehicleFriendlyNameFromModel( veh(model) ), veh(model), price );
  211. format( carstr, sizeof( carstr ), "You have bought the %s from %s for $%d.", GetVehicleFriendlyNameFromModel( veh(model) ), PlayerICName( player ), price );
  212. SendClientMessage( playerid, COLOR_LIGHTBLUE, carstr );
  213. format( carstr, sizeof( carstr ), "%s has bought the %s from you for $%d.", PlayerICName( playerid ), GetVehicleFriendlyNameFromModel( veh(model) ), price );
  214. SendClientMessage( player, COLOR_LIGHTBLUE, carstr );
  215. #undef veh
  216. }
  217. return 1;
  218. }
  219. VCMD:upgrade( playerid, slot, model[] ) {
  220. if( IsPlayerInRangeOfPoint( playerid, 5.0, 2324.2505,-2012.4784,13.6222 ) ) { //The new garage map
  221. new menuitems[150];
  222. #define veh(%1) PlayerVehicles[playerid][slot][pv%1]
  223. format( menuitems, 150, "GPS\t$350,000\nAlarm\t$200,000\nInsurance\t$250,000\nSpare keys\t$250000\nCustom license plate\t$100000\nAdd another vehicle slot\t$15,000,000" );
  224. vupgrading[playerid] = slot;
  225. new titlestr[100];
  226. format( titlestr, 100, "{FFB76F}Vehicle Upgrades for %s{FFFFFF}", model );
  227. ShowPlayerDialog( playerid, DIALOG_VEHICLES_UP2, DIALOG_STYLE_TABLIST, titlestr, menuitems, "Purchase", "Cancel" );
  228. #undef veh
  229. return 1;
  230. }
  231. SendClientMessage( playerid, COLOR_GREY, "You are not inside the Garage in Willowfield." );
  232. return 1;
  233. }
  234. new vSpawnTimer[MAX_PLAYERS];
  235. VCMD:spawn( playerid, params[] ) {
  236. printf( "call ./vehicles/player.inc, /v spawn ( playerid: %d, params[]: %s )", playerid, params );
  237. if( vSpawnTimer[playerid] != 0 && gettime() < ( vSpawnTimer[playerid] + 120 ) ) {
  238. new _str[120];
  239. format(_str, sizeof(_str), "You must wait %d seconds before spawning your vehicles.", ( vSpawnTimer[playerid] + 120 ) - gettime());
  240. return SendClientMessage( playerid, COLOR_GREY, _str);
  241. }
  242. new cartext[128];
  243. new slot = GetPlayerSpawnedVehicleSlot( playerid );
  244. if( slot > -1 ) {
  245. destroyPlayerVehicle( playerid, slot ); //destroy last spawned car
  246. }
  247. new model[128], carslot, location[MAX_ZONE_NAME + 1];
  248. if( sscanf( params, "d", carslot ) ) {
  249. if( !sscanf( params, "s[128]", model ) ) {
  250. //incase they enter the model name instead
  251. for( new s; s < PlayerInfo[playerid][pMaxCarSlots]; s++ ) {
  252. #define veh(%0) PlayerVehicles[playerid][s][pv%0]
  253. if( strcmp( model, GetVehicleFriendlyNameFromModel( veh(model) ), true ) == 0 && veh(SQLID) > 0 ) {
  254. if( veh(impounded) ) {
  255. return SendClientMessage( playerid, COLOR_GREY, "This vehicle is impounded, visit the impound yard to release it." );
  256. }
  257. vSpawnTimer[playerid] = gettime();
  258. spawnPlayerVehicle( playerid, s );
  259. GetPosition2DZone( location, veh(parkx), veh(parky), MAX_ZONE_NAME );
  260. format( cartext, sizeof( cartext ), "You have spawned your %s in its last parked position in %s.", GetVehicleFriendlyNameFromModel( veh(model) ), location );
  261. SendClientMessage( playerid, COLOR_GREY, cartext );
  262. return 1;
  263. }
  264. #undef veh
  265. }
  266. }
  267. return SendClientMessage( playerid, COLOR_GREY, "{00BFFF}Usage:{FFFFFF} /v spawn [car slot/car name]" );
  268. }
  269. if( carslot > PlayerInfo[playerid][pMaxCarSlots] || carslot < 1 ) {
  270. return SendClientMessage( playerid, COLOR_GREY, "You didn't enter a correct car slot, check /v cars for a correct slot." );
  271. }
  272. carslot--;
  273. #define veh(%0) PlayerVehicles[playerid][carslot][pv%0]
  274. if( veh(SQLID) > 0 ) {
  275. if( veh(impounded) ) {
  276. return SendClientMessage( playerid, COLOR_GREY, "This vehicle is impounded, visit the impound yard to release it." );
  277. }
  278. vSpawnTimer[playerid] = gettime();
  279. spawnPlayerVehicle( playerid, carslot );
  280. GetPosition2DZone( location, veh(parkx), veh(parky), MAX_ZONE_NAME );
  281. format( cartext, sizeof( cartext ), "You have spawned your %s in its last parked position in %s.", GetVehicleFriendlyNameFromModel( veh(model) ), location );
  282. SendClientMessage( playerid, COLOR_GREY, cartext );
  283. return 1;
  284. }
  285. #undef veh
  286. format( cartext, sizeof( cartext ), "You do not own this vehicle, consider looking at /v cars." );
  287. SendClientMessage( playerid, COLOR_GREY, cartext );
  288. return 1;
  289. }
  290. VCMD:park( playerid, slot, model[] ) {
  291. #define veh(%0) PlayerVehicles[playerid][slot][pv%0]
  292. new cartext[128];
  293. if( GetPlayerVehicleID( playerid ) != veh(ID) ) {
  294. format( cartext, sizeof( cartext ), "You must be in your %s in order to park it.", model );
  295. SendClientMessage( playerid, COLOR_GREY, cartext );
  296. return 1;
  297. }
  298. GetVehiclePos( veh(ID), veh(parkx), veh(parky), veh(parkz) );
  299. GetVehicleZAngle( veh(ID), veh(parkrz) );
  300. destroyPlayerVehicle( playerid, slot );
  301. format( cartext, sizeof( cartext ), "You have parked your %s. It will spawn here next time you use /v spawn.", model );
  302. SendClientMessage( playerid, COLOR_LIGHTBLUE, cartext );
  303. #undef veh
  304. return 1;
  305. }
  306. VCMD:givekeys( playerid, params[], slot, model[] ) {
  307. new player, cartext[128];
  308. if( sscanf( params, "u", player ) ) {
  309. return SendClientMessage( playerid, COLOR_GREY, "{00BFFF}Usage:{FFFFFF} /givekeys [playerid/playerName]" );
  310. }
  311. #define veh(%0) PlayerVehicles[playerid][slot][pv%0]
  312. if( !PlayerVehicles[playerid][slot][pvsparekey] ) {
  313. format( cartext, sizeof( cartext ), "You do not have any spare keys for your %s.", model );
  314. return SendClientMessage( playerid, COLOR_GREY, cartext );
  315. }
  316. if( !IsPlayerConnected( playerid ) ) {
  317. return SendClientMessage( playerid, COLOR_GREY, "ERROR: The player you provided is not connected." );
  318. }
  319. new Float:ppos[3];
  320. GetPlayerPos( player, ppos[0], ppos[1], ppos[2] );
  321. if( !IsPlayerInRangeOfPoint( playerid, 3.0, ppos[0], ppos[1], ppos[2] ) ) {
  322. return SendClientMessage( playerid, COLOR_GREY, "ERROR: You are not near the player." );
  323. }
  324. if( spareKeys[player] == playerid && spareKeysSlot[player] == slot ) {
  325. format( cartext, sizeof( cartext ), "You have already given this player your spare key to your %s.", model );
  326. return SendClientMessage( playerid, COLOR_GREY, cartext );
  327. }
  328. spareKeys[player] = playerid;
  329. spareKeysSlot[player] = slot;
  330. hasgivenKey[playerid] = 1;
  331. format( carstr, sizeof( carstr ), "%s has given you their spare key to their %s.", PlayerICName( playerid ), model );
  332. SendClientMessage( player, COLOR_LIGHTBLUE, carstr );
  333. format( carstr, sizeof( carstr ), "You have given %s your spare key to your %s.", PlayerICName( player ), model );
  334. SendClientMessage( playerid, COLOR_LIGHTBLUE, carstr );
  335. #undef veh
  336. return 1;
  337. }
  338. VCMD:track( playerid, slot, model[] ) {
  339. new cartext[128];
  340. #define veh(%1) PlayerVehicles[playerid][slot][pv%1]
  341. if( veh(gps) ) {
  342. GetVehiclePos( veh(ID), veh(x), veh(y), veh(z) );
  343. SetPlayerCheckpointEx( playerid, veh(x), veh(y), veh(z), 5.0 );
  344. CP[playerid] = CHECKPOINT_CAR_TRACK;
  345. format( cartext, sizeof( cartext ), "A marker leading to your %s has been placed on the minimap.", model );
  346. SendClientMessage( playerid, COLOR_LIGHTBLUE, cartext );
  347. }
  348. else {
  349. format( cartext, sizeof( cartext ), "Your %s does not have a GPS, consider buying one at the Garage in Willowfield.", model );
  350. SendClientMessage( playerid, COLOR_GREY, cartext );
  351. }
  352. #undef veh
  353. return 1;
  354. }
  355. VCMD:cars( playerid ) {
  356. new day, month, year, hour, minute, second, headerstr[128];
  357. gettime(hour, minute, second);
  358. getdate(year, month, day);
  359. format(headerstr, sizeof(headerstr), "______________[ %s's vehicles (%s %d %d %d:%d:%d) ]______________", PlayerICName(playerid), GetMonthFromInt(month), day, year, hour, minute, second);
  360. SendClientMessage( playerid, COLOR_LIGHTBLUE, headerstr);
  361. new count;
  362. for( new i; i < PlayerInfo[playerid][pMaxCarSlots]; i++ ) {
  363. #define veh(%1) PlayerVehicles[playerid][i][pv%1]
  364. if( veh(SQLID) < 1 ) continue;
  365. count++;
  366. new outputcars[128], outputupgrades[128];
  367. format( outputcars, sizeof( outputcars ), "Slot %d: %s", i+1, GetVehicleFriendlyNameFromModel( veh(model) ) );
  368. if( veh(alarm) || veh(insurance) || veh(gps) || veh(sparekey) ) {
  369. format( outputupgrades, sizeof( outputupgrades ), "( %s%s%s%s)",
  370. ( veh(gps) == 1 ) ? ( ( "GPS " ) ) : ( "" ), ( veh(alarm) == 1 ) ? ( ( "Alarm " ) ) : ( "" ), ( veh(insurance) == 1 ) ? ( ( "Insurance " ) ) : ( "" ),
  371. ( veh(sparekey) == 1 ) ? ( ( "Spare key " ) ) : ( "" ) );
  372. format( outputcars, sizeof( outputcars ), "%s %s", outputcars, outputupgrades );
  373. SendClientMessage( playerid, COLOR_GREY, outputcars );
  374. continue;
  375. }
  376. else {
  377. format( outputcars, sizeof( outputcars ), "%s (No upgrades)", outputcars );
  378. SendClientMessage( playerid, COLOR_GREY, outputcars );
  379. continue;
  380. }
  381. #undef veh
  382. }
  383. if( count == 0 ) {
  384. SendClientMessage( playerid, COLOR_GREY, "You do not have any owned vehicles." );
  385. }
  386. return 1;
  387. }
  388. CMD:lock( playerid, params[] ) {
  389. new slot = GetPlayerSpawnedVehicleSlot( playerid );
  390. new playermsg[128];
  391. if( slot > -1 ) {
  392. #define veh(%1) PlayerVehicles[playerid][slot][pv%1] //This is just a marco to reduce repetition!
  393. if( veh(SQLID) > 0 && IsValidVehicle( veh(ID) ) ) {
  394. GetVehiclePos( veh(ID), veh(x), veh(y), veh(z) ); //update vehicle coords
  395. if( IsPlayerInRangeOfPoint( playerid, 5.0, veh(x), veh(y), veh(z) ) ) {
  396. if( veh(locked) ) {
  397. format( carstr, sizeof( carstr ), "* %s has unlocked their vehicle.", PlayerICName( playerid ) );
  398. format( playermsg, sizeof( playermsg ), "You've unlocked your vehicle.", PlayerICName( playerid ) );
  399. }
  400. else {
  401. format( carstr, sizeof( carstr ), "* %s has locked their vehicle.", PlayerICName( playerid ) );
  402. format( playermsg, sizeof( playermsg ), "You've locked your vehicle.", PlayerICName( playerid ) );
  403. }
  404. SetPlayerChatBubble(playerid, carstr, COLOR_PURPLE, 20.0, 15000);
  405. displayCenterHUDInfo( playerid, playermsg, 8 );
  406. veh(locked) = !veh(locked);
  407. SetVehicleLockState( veh(ID), veh(locked) );
  408. //SetVehicleAlarmState( veh(ID), 0 )
  409. return 1;
  410. }
  411. }
  412. #undef veh
  413. }
  414. if( spareKeys[playerid] > -1 && spareKeysSlot[playerid] > -1 ) {
  415. new Float: vpos[3];
  416. #define veh(%0) PlayerVehicles[spareKeys[playerid]][spareKeysSlot[playerid]][pv%0]
  417. if( veh(spawned) && IsValidVehicle( veh(ID) ) && veh(SQLID) > 0 ) {
  418. GetVehiclePos( veh(ID), vpos[0], vpos[1], vpos[2] );
  419. if( IsPlayerInRangeOfPoint( playerid, 5.0, vpos[0], vpos[1], vpos[2] ) ) {
  420. if( veh(locked) ) {
  421. format( carstr, sizeof( carstr ), "* %s has unlocked their vehicle.", PlayerICName( playerid ) );
  422. }
  423. else {
  424. format( carstr, sizeof( carstr ), "* %s has locked their vehicle.", PlayerICName( playerid ) );
  425. }
  426. SetPlayerChatBubble(playerid, carstr, COLOR_PURPLE, 20.0, 15000);
  427. veh(locked) = !veh(locked);
  428. SetVehicleLockState( veh(ID), veh(locked) );
  429. //SetVehicleAlarmState( veh(ID), 0 )
  430. return 1;
  431. }
  432. }
  433. #undef veh
  434. }
  435. return 1;
  436. }
  437. //===================[ Player unowned vehicle commands ]=====================
  438. CMD:paintcar( playerid, params[] ) {
  439. SendClientMessage( playerid, COLOR_GREY, "Visit a vehicle modification shop to style the paintjob of a vehicle." );
  440. return 1;
  441. }
  442. //This was just copied and pasted from GM.
  443. CMD:spraycar(playerid, params[])
  444. {
  445. if(PlayerInfo[playerid][pSpraycan] == 0) return SendClientMessage(playerid, COLOR_GREY, "Your spraycan is empty.");
  446. if(IsPlayerInAnyVehicle(playerid))
  447. {
  448. new c1, c2;
  449. if(sscanf(params, "iI(-1)", c1, c2)) return SendClientMessage(playerid, COLOR_GREY, "{00BFFF}Usage:{FFFFFF} /colorcar [0-255] [0-255(optional)]");
  450. {
  451. new veh = GetPlayerVehicleID(playerid);
  452. if(c2 == -1) c2 = c1;
  453. if(c1 < 0 || c1 > 255 || c2 < 0 || c2 > 255) return SendClientMessage(playerid, COLOR_GREY, "The colors are between 0 and 255.");
  454. ChangeVehiclePaintjob(veh, 3);
  455. ChangeVehicleColor(veh, c1, c2);
  456. if(c2 == c1) format(str, sizeof(str), "You have sprayed your vehicle to be %s (%d).", GetVehicleColorName(c1), c1);
  457. else format(str, sizeof(str), "You have sprayed the vehicle to be %s (%d) and %s (%d).", GetVehicleColorName(c1), c1, GetVehicleColorName(c2), c2);
  458. SendClientMessage(playerid, COLOR_GREY, str);
  459. if(c2 == c1)format(str, sizeof(str), "* %s uses a spraycan to spray the %s to be %s. *", PlayerICName(playerid), GetVehicleFriendlyName(veh), GetVehicleColorName(c1));
  460. else format(str, sizeof(str), "* %s uses a spraycan to spray the %s to be %s and %s. *", PlayerICName(playerid), GetVehicleFriendlyName(veh), GetVehicleColorName(c1), GetVehicleColorName(c2));
  461. ProxDetector(30.0, playerid, str, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
  462. PlayerInfo[playerid][pSpraycan]--;
  463. PlayerPlaySound(playerid, 1134, 0.0, 0.0, 0.0);
  464. for( new i; i <= GetPlayerPoolSize(); i++ ) {
  465. for( new slot; slot < MAX_VEHICLE_SLOTS; slot++ ) {
  466. if( PlayerVehicles[i][slot][pvID] == veh && PlayerVehicles[i][slot][pvSQLID] > 0 && PlayerVehicles[i][slot][pvspawned] ) {
  467. PlayerVehicles[i][slot][pvcolor1] = c1;
  468. PlayerVehicles[i][slot][pvcolor2] = c2;
  469. PlayerVehicles[i][slot][pvpaintjob] = 3;
  470. break;
  471. }
  472. }
  473. }
  474. }
  475. } else return SendClientMessage(playerid, COLOR_GREY, "You must be in a vehicle.");
  476. return 1;
  477. }
  478. CMD:colorcar( playerid, params[] ) {
  479. return cmd_spraycar( playerid, params ); //make players happy...
  480. }
  481. //CMD:breakin
  482. new vehiclePickCount[MAX_PLAYERS];
  483. new lastbrokenin[MAX_PLAYERS];
  484. breakinPlayerVehicle( playerid ) {
  485. //restrict usage to 1/per30 seconds
  486. if( gettime() < lastbrokenin[playerid] + 30 ) {
  487. return SendClientMessage( playerid, COLOR_GREY, "You must wait 30 seconds before breaking into another vehicle." );
  488. }
  489. new Float:vpos[3];
  490. for( new i; i < GetPlayerPoolSize()+1; i++ ) {
  491. new slot = GetPlayerSpawnedVehicleSlot( i );
  492. if( slot < 0 ) continue;
  493. #define veh(%1) PlayerVehicles[i][slot][pv%1]
  494. GetVehiclePos( veh(ID), vpos[0], vpos[1], vpos[2] );
  495. if( IsPlayerFacingPoint( playerid, 5.0, vpos[0], vpos[1], vpos[2], 50.0 ) ) {
  496. if( !veh(locked) ) {
  497. return SendClientMessage( playerid, COLOR_GREY, "This vehicle is already unlocked." );
  498. }
  499. //If vehicle has alarm notify owner, set the alarm to go off
  500. if( veh(alarm) ) {
  501. format( carstr, sizeof( carstr ), "SMS: This is an automated message informing you that your %s alarm has been activated.", GetVehicleFriendlyName( veh(ID) ) );
  502. SendClientMessage( i, COLOR_YELLOW, carstr );
  503. //SetVehicleAlarmState( veh(ID) ) //sound the alarm for 35secs
  504. }
  505. LockPickingCar[playerid] = i;
  506. vehiclePickCount[playerid] = 0;
  507. //command usage restriction
  508. lastbrokenin[playerid] = gettime();
  509. SetTimerEx( "OnBreakinExpire", 18*1000, false, "ii", playerid, veh(ID) );
  510. SetPlayerProgressBarValue( playerid, workingProgress[playerid], 1.0 );
  511. ShowPlayerProgressBar( playerid, workingProgress[playerid] );
  512. format( carstr, sizeof( carstr ), "* %s fiddles with the vehicle's lock using their screwdriver. *", PlayerICName( playerid ) );
  513. ProxDetector( 30.0, playerid, carstr, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE );
  514. //LoopingAnim( playerid, "POOL", "POOL_ChalkCue", 4.1, 0, 1, 1, 1, 1 )
  515. ApplyAnimation( playerid, "POOL", "POOL_ChalkCue", 4.1, 0, 1, 1, 1, 1, 1 );
  516. displayCenterHUDInfo( playerid, "TIP: Rapidly tap ~r~Y~w~ to break in", 4);
  517. //SendClientMessage( playerid, COLOR_GREY, "TIP: tap Y rapidly to unlock the vehicle." );
  518. return 1;
  519. }
  520. #undef veh
  521. }
  522. SendClientMessage( playerid, COLOR_GREY, "You are not by any vehicle." );
  523. return 1;
  524. }
  525. //player taking too long to breakin
  526. forward OnBreakinExpire( playerid, vehid );
  527. public OnBreakinExpire( playerid, vehid ) {
  528. if( LockPickingCar[playerid] == -1 ) {
  529. return 1;
  530. }
  531. vehiclePickCount[playerid] = 0;
  532. LockPickingCar[playerid] = -1;
  533. HidePlayerProgressBar( playerid, workingProgress[playerid] );
  534. SendClientMessage( playerid, COLOR_GREY, "You have failed to break into the vehicle." );
  535. ClearAnimations( playerid );
  536. ApplyAnimationEx( playerid, "CARRY", "crry_prtial", 4.0, 0, 0, 0, 0, 0 );
  537. return 1;
  538. }
  539. new lastcheckplate[MAX_PLAYERS];
  540. CMD:checkplate( playerid, params[] ) {
  541. if( gettime() < lastcheckplate[playerid] + 10 ) {
  542. return SendClientMessage( playerid, COLOR_GREY, "You must wait 10 seconds to allow the system to cool down." );
  543. }
  544. if( PlayerInfo[playerid][pMember] != 1 && PlayerInfo[playerid][pMember] != 2 && PlayerInfo[playerid][pMember] != 5 && PlayerInfo[playerid][pMember] != 11) {
  545. return SendClientMessage( playerid, COLOR_GREY, "You do not have access to the correct systems to use this command." );
  546. }
  547. if( IsPlayerInAnyVehicle( playerid ) ) {
  548. if( sVehicleInfo[GetDynamicVehicleID( GetPlayerVehicleID( playerid ) )][v_faction] > 0 ) {
  549. new model[128], plate[128];
  550. if( sscanf( params, "s[128]s[128]", model, plate ) ) {
  551. return SendClientMessage( playerid, COLOR_GREY, "{00BFFF}Usage:{FFFFFF} /checkplates [vehicleName] [plate]" );
  552. }
  553. new modelid = ReturnVehicleModelID( model );
  554. lastcheckplate[playerid] = gettime();
  555. SendClientMessage( playerid, COLOR_LIGHTBLUE, "The following vehicles have matching vehicle plates,");
  556. new count;
  557. for( new i; i <= GetPlayerPoolSize(); i++ ) {
  558. for( new slot; slot < PlayerInfo[i][pMaxCarSlots]; slot++ ) {
  559. if( PlayerVehicles[i][slot][pvmodel] == modelid ) {
  560. if( strcmp( PlayerVehicles[i][slot][pvplate], plate, true ) == 0 ) {
  561. if( strlen( PlayerVehicles[i][slot][pvplate] ) > 1 ) {
  562. format( carstr, sizeof( carstr ), "Owner: %s | Vehicle model: %s | Plate: %s", PlayerICName( i ), GetVehicleFriendlyNameFromModel( modelid ), PlayerVehicles[i][slot][pvplate] );
  563. SendClientMessage( playerid, COLOR_GREY, carstr );
  564. count++;
  565. }
  566. }
  567. }
  568. }
  569. }
  570. if( count == 0 ) {
  571. SendClientMessage( playerid, COLOR_GREY, "There were no results." );
  572. }
  573. return 1;
  574. }
  575. }
  576. SendClientMessage( playerid, COLOR_GREY, "You are not in a faction vehicle." );
  577. return 1;
  578. }
  579. CMD:clearmods(playerid)
  580. {
  581. new slot = playerSpawnedVehicle[playerid];
  582. #define veh(%1) PlayerVehicles[playerid][slot][pv%1]
  583. if(GetPlayerVehicleID(playerid) != veh(ID)) return SendClientMessage( playerid, COLOR_GREY, "You are not in a vehicle that you own.");
  584. if(IsAHelicopter(veh(ID)) || IsABike(veh(ID)) || IsABoat(veh(ID)) || IsAPlane(veh(ID))) return SendClientMessage( playerid, COLOR_GREY, "This vehicle cannot have mods.");
  585. ShowPlayerDialog(playerid, DIALOG_CLEARMOD, DIALOG_STYLE_LIST, "Mod Removal", "Spoiler\nHood\nRoof\nSide Skirt\nNitro\nExhaust\nWheel\nStereo\nHydraulic\nF. Bumper\nR. Bumper", "Select", "Cancel");
  586. #undef veh
  587. return 1;
  588. }
  589. CMD:clearallmods(playerid, params[])
  590. {
  591. if(IsPlayerInAnyVehicle(playerid))
  592. {
  593. if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  594. {
  595. new slot = GetPlayerSpawnedVehicleSlot( playerid );
  596. if( slot < 0 ) return SendClientMessage(playerid, COLOR_GREY, "You do not own any vehicles that are spawned, use /v spawn.");
  597. new veh = GetPlayerVehicleID(playerid);
  598. if( PlayerVehicles[playerid][slot][pvID] == veh )
  599. {
  600. new componentid = 0;
  601. for(new i = 0; i < 14; i++)
  602. {
  603. componentid = GetVehicleComponentInSlot(veh, i);
  604. if(componentid != 0)
  605. {
  606. RemoveVehicleComponent(veh, componentid);
  607. componentid = 0;
  608. }
  609. }
  610. if(IsValidDynamicObject(Neon[veh]))
  611. {
  612. DestroyDynamicObjectEx(Neon[veh]);
  613. Neon[veh] = 0;
  614. }
  615. if(IsValidDynamicObject(Neon2[veh]))
  616. {
  617. DestroyDynamicObjectEx(Neon2[veh]);
  618. Neon2[veh] = 0;
  619. }
  620. if(IsValidDynamicObject(Neon3[veh]))
  621. {
  622. DestroyDynamicObjectEx(Neon3[veh]);
  623. Neon3[veh] = 0;
  624. }
  625. if(IsValidDynamicObject(Neon4[veh]))
  626. {
  627. DestroyDynamicObjectEx(Neon4[veh]);
  628. Neon4[veh] = 0;
  629. }
  630. if(IsValidDynamicObject(SirenObject[veh]) ) {
  631. DestroyDynamicObjectEx(SirenObject[veh]);
  632. SirenObject[veh] = 0;
  633. }
  634. SendClientMessage(playerid, COLOR_WHITE, "Vehicle mods were cleared.");
  635. }
  636. else SendClientMessage(playerid, COLOR_GREY, "This is not your vehicle.");
  637. }
  638. else SendClientMessage(playerid, COLOR_GREY, "You must be the driver.");
  639. }
  640. else SendClientMessage(playerid, COLOR_GREY, "You are not in any vehicle.");
  641. return 1;
  642. }
  643. CMD:showcarupgrades(playerid, params[])
  644. {
  645. new vSlot,
  646. trgID,
  647. vString[128],
  648. vUpgrade[128];
  649. //Detect /showupgrade playername/ID vehicle slot.
  650. if(sscanf(params, "ud", trgID, vSlot))
  651. return SendClientMessage( playerid, COLOR_GREY, "{00BFFF}Usage:{FFFFFF} /showupgrade [playerid/name] [vehicle ID (1/2/3)]" );
  652. // Player cannot show himself the upgrades, they have /v cars
  653. if( trgID == playerid ) return SendClientMessage(playerid, COLOR_GREY, "Use /v cars for your own.");
  654. //detect if the target ID is online
  655. if(!IsPlayerConnected(trgID))
  656. return SendClientMessage(playerid, COLOR_GREY, "Unknown player.");
  657. //Detect the player is nearby to the target ID
  658. new Float:fX, Float:fY, Float:fZ;
  659. GetPlayerPos(trgID, fX, fY, fZ);
  660. if(!IsPlayerInRangeOfPoint(playerid, 5.0, fX, fY, fZ)) return SendClientMessage(playerid, COLOR_GRAD1, "You are not close enough to that player to offer him weapons.");
  661. //vSlot either it's 1 /or/ 2
  662. if( vSlot == 1 || vSlot == 2 || vSlot == 3)
  663. {
  664. #define veh(%1) PlayerVehicles[playerid][vSlot-1][pv%1]
  665. }
  666. else return SendClientMessage(playerid, -1, "Slot must be 1 or 2");
  667. //Formats for the vehicle message print.
  668. format( vString, sizeof( vString ), "%s's vehicle: %s and their upgrades", PlayerICName(playerid), GetVehicleFriendlyNameFromModel( veh(model) ) );
  669. if( veh(alarm) || veh(insurance) || veh(gps) || veh(sparekey) )
  670. {
  671. format( vUpgrade, sizeof( vUpgrade ), "( %s%s%s%s)",
  672. ( veh(gps) == 1 ) ? ( ( "GPS " ) ) : ( "" ),\
  673. ( veh(alarm) == 1 ) ? ( ( "Alarm " ) ) : ( "" ), \
  674. ( veh(insurance) == 1 ) ? ( ( "Insurance " ) ) : ( "" ),\
  675. ( veh(sparekey) == 1 ) ? ( ( "Spare key " ) ) : ( "" ) );
  676. format( vString, sizeof( vString ), "%s %s", vString, vUpgrade );
  677. SendClientMessage( trgID, COLOR_GREY, vString );
  678. }
  679. else
  680. {
  681. format( vString, sizeof( vString ), "%s (No upgrades)", vString );
  682. SendClientMessage( trgID, COLOR_GREY, vString );
  683. }
  684. #undef veh
  685. return 1;
  686. }