Guest User

Untitled

a guest
Jan 18th, 2015
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.34 KB | None | 0 0
  1. enum eVehicleData {
  2.     v_iModel,
  3.     Float:v_fPos[4],
  4.     v_iCol[2],
  5.     MainPipeline
  6. }
  7. new
  8.     arrVehData[MAX_VEHICLES][eVehicleData],
  9.     szMiscArray[4096];
  10.  
  11. public OnGameModeInit()
  12. {
  13.     LoadVehicles();
  14. // THIS IS NOT MY ENTIRE GAMEMODEINIT
  15. }
  16. public OnGameModeExit()
  17. {
  18.     SaveVehicles();
  19.     return 1;
  20. }
  21. CMD:createveh(playerid,params[])
  22. {
  23.     new vmodel,cole,colw;
  24.     if(sscanf(params,"iii",vmodel,cole,colw))SendClientMessage(playerid,C_YELLOW,"Usage:{FFFFFF}/createveh [modelid] [col] [col]");
  25.     else if(vmodel == INVALID_VEHICLE_ID)SendClientMessage(playerid,C_YELLOW,"Invalid Player Id Entered");
  26.     else
  27.     {
  28.         new Float:iX, Float:iY, Float:iZ, Float:iA;
  29.         GetPlayerPos(playerid, iX, iY, iZ);
  30.         GetPlayerFacingAngle(playerid, iA);
  31.         CreateDVehicle(vmodel, iX, iY,iZ, iA, cole, colw);
  32.     }
  33.     return 1;
  34. }
  35.  
  36. CreateDVehicle(iModel, Float:PosX, Float:PosY, Float:PosZ, Float:Rot, iColor1, iColor2)
  37. {
  38.     new iVehID = CreateVehicle(iModel, PosX, PosY, PosZ, Rot, iColor1, iColor2, 60000);
  39.    
  40.     arrVehData[iVehID][v_iModel] = iModel;
  41.     arrVehData[iVehID][v_fPos][0] = PosX;
  42.     arrVehData[iVehID][v_fPos][1] = PosY;
  43.     arrVehData[iVehID][v_fPos][2] = PosZ;
  44.     arrVehData[iVehID][v_fPos][3] = Rot;
  45.     arrVehData[iVehID][v_iCol][0] = iColor1;
  46.     arrVehData[iVehID][v_iCol][1] = iColor2;
  47.  
  48.     SaveVehicle(iVehID);
  49. }
  50.  
  51. SaveVehicle(iVehID)
  52. {
  53.  
  54.     szMiscArray[0] = 0;
  55.  
  56.     format(szMiscArray, 4096, "UPDATE `vehicles` SET \
  57.         `Model` = '%i', \
  58.         `X` = '%f', \
  59.         `Y` = '%f', \
  60.         `Z` = '%f', \
  61.         `FAngle` = '%f', \
  62.         `Color` = '%i', \
  63.         `Col2` = '%i' WHERE `vID` = '%i'",
  64.         arrVehData[iVehID][v_iModel],
  65.         arrVehData[iVehID][v_fPos][0],
  66.         arrVehData[iVehID][v_fPos][1],
  67.         arrVehData[iVehID][v_fPos][2],
  68.         arrVehData[iVehID][v_fPos][3],
  69.         arrVehData[iVehID][v_iCol][0],
  70.         arrVehData[iVehID][v_iCol][1],
  71.         iVehID
  72.     );
  73.     mysql_function_query(MainPipeline, szMiscArray, false, "", "");
  74. }
  75.  
  76. SaveVehicles()
  77. {
  78.     for(new v = 0; v < MAX_VEHICLES; v++) SaveVehicle(v);
  79. }
  80.  
  81. LoadVehicles()
  82. {
  83.     print("[Vehicle System] Load dynamic vehicles.");
  84.     mysql_function_query(MainPipeline, "SELECT * FROM `vehicles`", false, "OnLoadVehicles", "");
  85. }
  86.  
  87. PF: OnLoadVehicles()
  88. {
  89.     new
  90.         i = 0,
  91.         iRows,
  92.         iFields;
  93.  
  94.     szMiscArray[0] = 0;
  95.  
  96.     cache_get_data(iRows, iFields, MainPipeline);
  97.     while(i < iRows)
  98.     {
  99.         cache_get_field_content(i, "Model", szMiscArray, MainPipeline); arrVehData[i][v_iModel] = strval(szMiscArray);
  100.         cache_get_field_content(i, "X", szMiscArray, MainPipeline); arrVehData[i][v_fPos][0] = floatstr(szMiscArray);
  101.         cache_get_field_content(i, "Y", szMiscArray, MainPipeline); arrVehData[i][v_fPos][1] = floatstr(szMiscArray);
  102.         cache_get_field_content(i, "Z", szMiscArray, MainPipeline); arrVehData[i][v_fPos][2] = floatstr(szMiscArray);
  103.         cache_get_field_content(i, "FAngle", szMiscArray, MainPipeline); arrVehData[i][v_fPos][3] = floatstr(szMiscArray);
  104.         cache_get_field_content(i, "Color", szMiscArray, MainPipeline); arrVehData[i][v_iCol][0] = strval(szMiscArray);
  105.         cache_get_field_content(i, "Color2", szMiscArray, MainPipeline); arrVehData[i][v_iCol][1] = strval(szMiscArray);
  106.  
  107.         CreateVehicle(arrVehData[i][v_iModel], arrVehData[i][v_fPos][0], arrVehData[i][v_fPos][1], arrVehData[i][v_fPos][2], arrVehData[i][v_fPos][3], arrVehData[i][v_iCol][0], arrVehData[i][v_iCol][1], 60000);
  108.         i++;
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment