Nyft_

Save Vehicle Mods ~NYFT

May 25th, 2022 (edited)
166
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include a_samp
  2. #include dof2
  3. #include sscanf2
  4. #include pawn.cmd
  5.  
  6. static const spoiler[20][0] =
  7. {
  8.     {1000}, {1001}, {1002}, {1003}, {1014}, {1015}, {1016}, {1023}, {1058}, {1060},
  9.     {1049}, {1050}, {1138}, {1139}, {1146}, {1147}, {1158}, {1162}, {1163}, {1164}
  10. };
  11.  
  12. static const nitro[3][0] =
  13. {
  14.     {1008}, {1009}, {1010}
  15. };
  16.  
  17. static const fbumper[23][0] =
  18. {
  19.     {1117}, {1152}, {1153}, {1155}, {1157}, {1160}, {1165}, {1167}, {1169}, {1170}, {1171},
  20.     {1172}, {1173}, {1174}, {1175}, {1179}, {1181}, {1182}, {1185}, {1188}, {1189}, {1192}, {1193}
  21. };
  22.  
  23. static const rbumper[22][0] =
  24. {
  25.     {1140}, {1141}, {1148}, {1149}, {1150}, {1151}, {1154}, {1156}, {1159}, {1161}, {1166},
  26.     {1168}, {1176}, {1177}, {1178}, {1180}, {1183}, {1184}, {1186}, {1187}, {1190}, {1191}
  27. };
  28.  
  29. static const exhaust[28][0] =
  30. {
  31.     {1018}, {1019}, {1020}, {1021}, {1022}, {1028}, {1029}, {1037}, {1043}, {1044}, {1045}, {1046}, {1059}, {1064},
  32.     {1065}, {1066}, {1089}, {1092}, {1104}, {1105}, {1113}, {1114}, {1126}, {1127}, {1129}, {1132}, {1135}, {1136}
  33. };
  34.  
  35. static const bventr[2][0] =
  36. {
  37.     {1142}, {1144}
  38. };
  39.  
  40. static const bventl[2][0] =
  41. {
  42.     {1143}, {1145}
  43. };
  44. static const bscoop[4][0] =
  45. {
  46.     {1004}, {1005},  {1011}, {1012}
  47. };
  48.  
  49. static const rscoop[17][0] =
  50. {
  51.     {1006}, {1032}, {1033}, {1035}, {1038}, {1053}, {1054}, {1055},
  52.     {1061}, {1067}, {1068}, {1088}, {1091}, {1103}, {1128}, {1130}, {1131}
  53. };
  54.  
  55. static const lskirt[21][0] =
  56. {
  57.     {1007}, {1026}, {1031}, {1036}, {1039}, {1042}, {1047},
  58.     {1048}, {1056}, {1057}, {1069}, {1070}, {1090}, {1093},
  59.     {1106}, {1108}, {1118}, {1119}, {1133}, {1122}, {1134}
  60. };
  61.  
  62. static const rskirt[21][0] =
  63. {
  64.     {1017}, {1027}, {1030}, {1040}, {1041}, {1051}, {1052},
  65.     {1062}, {1063}, {1071}, {1072}, {1094}, {1095}, {1099},
  66.     {1101}, {1102}, {1107}, {1120}, {1121}, {1124}, {1137}
  67. };
  68.  
  69. static const hydraulics[1][0] =
  70. {
  71.     {1087}
  72. };
  73.  
  74. static const stereo[1][0] =
  75. {
  76.     {1086}
  77. };
  78.  
  79. static const rbbars[4][0] =
  80. {
  81.     {1109}, {1110}, {1123}, {1125}
  82. };
  83.  
  84. static const fbbars[2][0] =
  85. {
  86.     {1115}, {1116}
  87. };
  88.  
  89. static const wheels[17][0] =
  90. {
  91.     {1025}, {1073}, {1074}, {1075}, {1076}, {1077}, {1078}, {1079},
  92.     {1080}, {1081}, {1082}, {1083}, {1084}, {1085}, {1096}, {1097}, {1098}
  93. };
  94.  
  95. static const lamps[2][0] =
  96. {
  97.     {1013}, {1024}
  98. };
  99.  
  100. enum E_VEHICLE_DATA
  101. {
  102.     E_VEHICLE_COLOR[2],
  103.     E_VEHICLE_MOD[17],
  104.     E_VEHICLE_PAINTJOB
  105. };
  106.  
  107. static vehicle[MAX_VEHICLES][E_VEHICLE_DATA];
  108.  
  109. main(){}
  110.  
  111. public OnGameModeExit()
  112. {
  113.     DOF2::Exit();
  114.     return 1;
  115. }
  116.  
  117. public OnPlayerSpawn(playerid)
  118. {
  119.     SetPlayerPos(playerid, -2706.9719, 217.6189, 4.1797);
  120.     SetPlayerFacingAngle(playerid, 90.0);
  121.     GivePlayerMoney(playerid, 100000);
  122.     return 1;
  123. }
  124.  
  125. public OnVehicleSpawn(vehicleid)
  126. {
  127.     /*
  128.  
  129.         Ao visualizar um Paintjob em uma loja de modificação e não comprá-lo
  130.         vai execultar a public OnVehiclePaintjob e retornar o id 255 na variável
  131.         se caso não for comprado, somente visualizado!
  132.  
  133.     */
  134.  
  135.     for(new i; i < 17; i++)
  136.         vehicle[vehicleid][E_VEHICLE_MOD][i] = 0;
  137.  
  138.     vehicle[vehicleid][E_VEHICLE_COLOR][0] = -1;
  139.     vehicle[vehicleid][E_VEHICLE_COLOR][1] = -1;
  140.     vehicle[vehicleid][E_VEHICLE_PAINTJOB] = 255;
  141.    
  142.     LoadMods(vehicleid);
  143.     return 1;
  144. }
  145.  
  146. public OnVehicleMod(playerid, vehicleid, componentid)
  147. {
  148.     vehicle[vehicleid][E_VEHICLE_MOD][(GetComponentSlot(componentid) - 1)] = componentid;
  149.     SaveMods(vehicleid);
  150.     return 1;
  151. }
  152.  
  153. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  154. {
  155.     vehicle[vehicleid][E_VEHICLE_PAINTJOB] = paintjobid;
  156.     SaveMods(vehicleid);
  157.     return 1;
  158. }
  159.  
  160. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  161. {
  162.     vehicle[vehicleid][E_VEHICLE_COLOR][0] = color1;
  163.     vehicle[vehicleid][E_VEHICLE_COLOR][1] = color1;
  164.     SaveMods(vehicleid);
  165.     return 1;
  166. }
  167.  
  168. modFile(vehicleid)
  169. {
  170.     new file[32];
  171.     format(file, sizeof(file), "mods/vehicle%i.ini", vehicleid);
  172.     return file;
  173. }
  174.  
  175. SaveMods(vehicleid)
  176. {
  177.     if(!DOF2::FileExists(modFile(vehicleid)))
  178.         DOF2::CreateFile(modFile(vehicleid));
  179.  
  180.     new componentSlot[7];
  181.  
  182.     for(new i; i < 17; i++)
  183.     {
  184.         format(componentSlot, sizeof(componentSlot), "Mod-%i", i+1);
  185.         DOF2::SetInt(modFile(vehicleid), componentSlot, vehicle[vehicleid][E_VEHICLE_MOD][i], "Components");
  186.     }
  187.     DOF2::SetInt(modFile(vehicleid), "Color-1", vehicle[vehicleid][E_VEHICLE_COLOR][0], "Color");
  188.     DOF2::SetInt(modFile(vehicleid), "Color-2", vehicle[vehicleid][E_VEHICLE_COLOR][1], "Color");
  189.     DOF2::SetInt(modFile(vehicleid), "Paintjob", vehicle[vehicleid][E_VEHICLE_PAINTJOB], "Paintjob");
  190.     DOF2::SaveFile();
  191. }
  192.  
  193. LoadMods(vehicleid)
  194. {
  195.     if(DOF2::FileExists(modFile(vehicleid)))
  196.     {
  197.         new componentSlot[7];
  198.  
  199.         for(new i; i < 17; i++)
  200.         {
  201.             format(componentSlot, sizeof(componentSlot), "Mod-%i", i+1);
  202.             vehicle[vehicleid][E_VEHICLE_MOD][i] = DOF2::GetInt(modFile(vehicleid), componentSlot, "Components");
  203.         }
  204.         vehicle[vehicleid][E_VEHICLE_COLOR][0] = DOF2::GetInt(modFile(vehicleid), "Color-1", "Color");
  205.         vehicle[vehicleid][E_VEHICLE_COLOR][1] = DOF2::GetInt(modFile(vehicleid), "Color-2", "Color");
  206.         vehicle[vehicleid][E_VEHICLE_PAINTJOB] = DOF2::GetInt(modFile(vehicleid), "Paintjob", "Paintjob");
  207.         RefreshMods(vehicleid);
  208.     }
  209. }
  210.  
  211. RefreshMods(vehicleid)
  212. {
  213.     for(new i; i < 17; i++)
  214.         if(vehicle[vehicleid][E_VEHICLE_MOD][i] != 0)
  215.             AddVehicleComponent(vehicleid, vehicle[vehicleid][E_VEHICLE_MOD][i]);
  216.  
  217.     ChangeVehicleColor(vehicleid, vehicle[vehicleid][E_VEHICLE_COLOR][0], vehicle[vehicleid][E_VEHICLE_COLOR][1]);
  218.     if(vehicle[vehicleid][E_VEHICLE_PAINTJOB] != 0) ChangeVehiclePaintjob(vehicleid, vehicle[vehicleid][E_VEHICLE_PAINTJOB]);
  219. }
  220.  
  221. GetComponentSlot(componentid)
  222. {
  223.     for(new i; i < 20; i++)
  224.         if(componentid == spoiler[i][0])
  225.             return 1;
  226.  
  227.     for(new i; i < 3; i++)
  228.         if(componentid == nitro[i][0])
  229.             return 2;
  230.  
  231.     for(new i; i < 23; i++)
  232.         if(componentid == fbumper[i][0])
  233.             return 3;
  234.  
  235.     for(new i; i < 22; i++)
  236.         if(componentid == rbumper[i][0])
  237.             return 4;
  238.  
  239.     for(new i; i < 28; i++)
  240.         if(componentid == exhaust[i][0])
  241.             return 5;
  242.  
  243.     for(new i; i < 2; i++)
  244.         if(componentid == bventr[i][0])
  245.             return 6;
  246.  
  247.     for(new i; i < 2; i++)
  248.         if(componentid == bventl[i][0])
  249.             return 7;
  250.  
  251.     for(new i; i < 4; i++)
  252.         if(componentid == bscoop[i][0])
  253.             return 8;
  254.  
  255.     for(new i; i < 17; i++)
  256.         if(componentid == rscoop[i][0])
  257.             return 9;
  258.  
  259.     for(new i; i < 21; i++)
  260.         if(componentid == lskirt[i][0])
  261.             return 10;
  262.  
  263.     for(new i; i < 21; i++)
  264.         if(componentid == rskirt[i][0])
  265.             return 11;
  266.  
  267.     for(new i; i < 1; i++)
  268.         if(componentid == hydraulics[i][0])
  269.             return 12;
  270.  
  271.     for(new i; i < 1; i++)
  272.         if(componentid == stereo[i][0])
  273.             return 13;
  274.  
  275.     for(new i; i < 4; i++)
  276.         if(componentid == rbbars[i][0])
  277.             return 14;
  278.  
  279.     for(new i; i < 2; i++)
  280.         if(componentid == fbbars[i][0])
  281.             return 15;
  282.  
  283.     for(new i; i < 17; i++)
  284.         if(componentid == wheels[i][0])
  285.             return 16;
  286.  
  287.     for(new i; i < 2; i++)
  288.         if(componentid == lamps[i][0])
  289.             return 17;
  290.            
  291.     return 0;
  292. }
  293.  
  294. CMD:v(playerid, params[])
  295. {
  296.     new modelid, color[2];
  297.  
  298.     if(sscanf(params, "iii", modelid, color[0], color[1]))
  299.         return SendClientMessage(playerid, -1, "* /v (modelo) (cor-1) (cor-2)");
  300.  
  301.     if(!(400 <= modelid <= 611))
  302.         return SendClientMessage(playerid, -1, "* Modelo inexistente.");
  303.  
  304.     new vehicleid, Float:x, Float:y, Float:z, Float:a;
  305.     GetPlayerPos(playerid, x, y, z);
  306.     GetPlayerFacingAngle(playerid, a);
  307.  
  308.     vehicleid = CreateVehicle(modelid, x, y, z, a, color[0], color[1], -1);
  309.     PutPlayerInVehicle(playerid, vehicleid, 0);
  310.     return 1;
  311. }
RAW Paste Data Copied