Advertisement
Johurt

[SCR] CYV (Control your vehicles)

Nov 9th, 2014
1,051
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.56 KB | None | 0 0
  1. /*
  2.     CYV by Johurt, 2014/11/08
  3. */
  4.  
  5. new SitInV[MAX_PLAYERS] = {0, ...}, SitInS[MAX_PLAYERS] = {-1, ...}, VehSeat[MAX_VEHICLES][9];
  6.  
  7. stock j_CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay)
  8. {
  9.     new vehicleid = CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay);
  10.     for(new c; c < 9; c++) VehSeat[vehicleid][c] = INVALID_PLAYER_ID;
  11.     return vehicleid;
  12. }
  13. #define CreateVehicle j_CreateVehicle
  14.  
  15. stock j_DestroyVehicle(vehicleid)
  16. {
  17.     new vSeats = GetVehicleSeats(GetVehicleModel(vehicleid));
  18.     for(new c; c < vSeats; c++)
  19.     {
  20.         if(VehSeat[vehicleid][c] != INVALID_PLAYER_ID)
  21.             {
  22.             if(SitInV[VehSeat[vehicleid][c]] == vehicleid)
  23.                 {
  24.                     SitInV[VehSeat[vehicleid][c]] = 0;
  25.                     SitInS[VehSeat[vehicleid][c]] = -1;
  26.                 }
  27.             VehSeat[vehicleid][c] = INVALID_PLAYER_ID;
  28.         }
  29.     }
  30.     return DestroyVehicle(vehicleid);
  31. }
  32. #define DestroyVehicle j_DestroyVehicle
  33.  
  34. stock j_LinkVehicleToInterior(vehicleid, interiorid)
  35. {
  36.         LinkVehicleToInterior(vehicleid, interiorid);
  37.         new vSeats = GetVehicleSeats(GetVehicleModel(vehicleid));
  38.         for(new c; c < vSeats; c++)
  39.     {
  40.         if(VehSeat[vehicleid][c] != INVALID_PLAYER_ID) SetPlayerInterior(VehSeat[vehicleid][c], interiorid);
  41.     }
  42.     return 1;
  43. }
  44. #define LinkVehicleToInterior j_LinkVehicleToInterior
  45.  
  46. stock j_SetVehicleVirtualWorld(vehicleid, worldid)
  47. {
  48.     SetVehicleVirtualWorld(vehicleid, worldid);
  49.     new vSeats = GetVehicleSeats(GetVehicleModel(vehicleid));
  50.         for(new c; c < vSeats; c++)
  51.     {
  52.         if(VehSeat[vehicleid][c] != INVALID_PLAYER_ID) SetPlayerVirtualWorld(VehSeat[vehicleid][c], worldid);
  53.     }
  54.     return 1;
  55. }
  56. #define SetVehicleVirtualWorld j_SetVehicleVirtualWorld
  57.  
  58. public OnGameModeInit()
  59. {
  60.     new c[2];
  61.     for(c[0] = 0; c[0] < MAX_VEHICLES; c[0]++)
  62.     {
  63.         for(c[1] = 0; c[1] < 9; c[1]++) VehSeat[c[0]][c[1]] = INVALID_PLAYER_ID;
  64.     }
  65.     return 1;
  66. }
  67.  
  68. public OnPlayerConnect(playerid)
  69. {
  70.     SitInV[playerid] = 0;
  71.     SitInS[playerid] = -1;
  72.     return 1;
  73. }
  74.  
  75. public OnPlayerDisconnect(playerid, reason)
  76. {
  77.     if(SitInV[playerid] != 0)
  78.     {
  79.             VehSeat[SitInV[playerid]][SitInS[playerid]] = INVALID_PLAYER_ID;
  80.             SitInV[playerid] = 0;
  81.             SitInS[playerid] = -1;
  82.     }
  83.     return 1;
  84. }
  85.  
  86. public OnVehicleDeath(vehicleid, killerid)
  87. {
  88.     new vSeats = GetVehicleSeats(GetVehicleModel(vehicleid));
  89.     for(new c; c < vSeats; c++)
  90.     {
  91.         if(VehSeat[vehicleid][c] != INVALID_PLAYER_ID)
  92.             {
  93.             if(SitInV[VehSeat[vehicleid][c]] == vehicleid)
  94.                 {
  95.                     SitInV[VehSeat[vehicleid][c]] = 0;
  96.                     SitInS[VehSeat[vehicleid][c]] = -1;
  97.                 }
  98.             VehSeat[vehicleid][c] = INVALID_PLAYER_ID;
  99.         }
  100.     }
  101.     return 1;
  102. }
  103.  
  104. public OnPlayerStateChange(playerid, newstate, oldstate)
  105. {
  106.     if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER)
  107.     {
  108.         VehSeat[SitInV[playerid]][SitInS[playerid]] = INVALID_PLAYER_ID;
  109.             SitInV[playerid] = 0;
  110.             SitInS[playerid] = -1;
  111.     }
  112.     if(newstate == PLAYER_STATE_DRIVER  || newstate == PLAYER_STATE_PASSENGER)
  113.     {
  114.             new vehicleid = GetPlayerVehicleID(playerid), seatid = GetPlayerVehicleSeat(playerid);
  115.             while(seatid == 128) seatid = GetPlayerVehicleSeat(playerid);
  116.             SitInV[playerid] = vehicleid;
  117.             SitInS[playerid] = seatid;
  118.             VehSeat[SitInV[playerid]][SitInS[playerid]] = playerid;
  119.     }
  120.     return 1;
  121. }
  122.  
  123. stock GetVehicleDriver(vehicleid) return VehSeat[vehicleid][0];
  124.  
  125. stock IsAnyPlayerInVehicle(vehicleid)
  126. {
  127.         new vSeats = GetVehicleSeats(GetVehicleModel(vehicleid));
  128.         for(new c; c < vSeats; c++)
  129.     {
  130.         if(VehSeat[vehicleid][c] != INVALID_PLAYER_ID) return 1;
  131.     }
  132.     return 0;
  133. }
  134.  
  135. stock SendMessageToVehicle(vehicleid, color, text[])
  136. {
  137.         new vSeats = GetVehicleSeats(GetVehicleModel(vehicleid));
  138.         for(new c; c < vSeats; c++)
  139.     {
  140.         if(VehSeat[vehicleid][c] != INVALID_PLAYER_ID) SendClientMessage(VehSeat[vehicleid][c], color, text);
  141.     }
  142.     return 1;
  143. }
  144.  
  145. stock RemovePlayersFromVehicle(vehicleid, nrid = INVALID_PLAYER_ID)
  146. {
  147.     new vSeats = GetVehicleSeats(GetVehicleModel(vehicleid));
  148.     for(new c; c < vSeats; c++)
  149.     {
  150.         if(VehSeat[vehicleid][c] != INVALID_PLAYER_ID && VehSeat[vehicleid][c] != nrid) RemovePlayerFromVehicle(VehSeat[vehicleid][c]);
  151.     }
  152.     return 1;
  153. }
  154.  
  155. stock GetEmptyPassangerSeat(vehicleid)
  156. {
  157.     new vSeats = GetVehicleSeats(GetVehicleModel(vehicleid));
  158.     if(vSeats > 1)
  159.     {
  160.         for(new c = 1; c < vSeats; c++)
  161.         {
  162.             if(VehSeat[vehicleid][c] == INVALID_PLAYER_ID) return c;
  163.         }
  164.     }
  165.     return -1;
  166. }
  167.  
  168. stock GetVehicleSeats(modelid)
  169. {
  170.     switch(modelid)
  171.     {
  172.         /* 1 */
  173.         case 406, 425, 430, 432, 435, 441, 446, 448, 450, 452..454, 464, 465, 472,
  174.         473, 476, 481, 484..486, 493, 501, 509, 510, 512, 513, 519, 520, 530..532,
  175.         539, 553, 564, 568..571, 572, 577, 574, 583, 584, 591, 594, 590, 595,
  176.         606..608, 610, 611: return 1;
  177.         /* 2 */
  178.         case 401..403, 407, 408, 410..412, 414, 415, 417, 419, 422..424, 429, 433,
  179.         434, 436, 439, 442..444, 447, 451, 455..457, 460..463, 468, 469, 471, 474,
  180.         475, 477, 478, 480, 488, 489, 491, 494..496, 499, 500, 502..505, 506, 508,
  181.         511, 514, 515, 517, 518, 521, 522, 523..526, 528, 527, 533..536, 541..545,
  182.         548, 549, 552, 554, 555..558, 559, 562, 563, 565, 573, 575, 576, 578, 580,
  183.         581, 586, 588, 589, 592, 593, 599..603, 605: return 2;
  184.         /* 3 */
  185.         case 483: return 3;
  186.         /* 4 */
  187.         case 400, 404, 405, 409, 413, 416, 418, 420, 421, 426..428, 438, 440, 445,
  188.         458, 459, 466, 467, 470, 479, 482, 487, 490, 492, 497, 498, 507, 516, 529,
  189.         540, 546, 547, 550, 551, 560, 561, 566, 567, 579, 582, 585, 587, 596..598,
  190.         604, 609: return 4;
  191.         /* 9 */
  192.         case 431, 437, 449, 537, 538: return 9;
  193.     }
  194.     return 0;
  195. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement