Advertisement
ZumeZero

Include OnPlayerVehicleTime PLUS

Dec 27th, 2014
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.76 KB | None | 0 0
  1. // _ZUME
  2.  
  3. #include <a_samp>
  4.  
  5. #if defined _OnPlayerVehicleTime_included
  6.     #endinput
  7. #endif
  8. #define _OnPlayerVehicleTime_included
  9.  
  10. #if !defined _ALS_
  11.     forward public _ALS_();
  12.     _ALS_()<_ALS_:unhooked>{}
  13.     _ALS_()<_ALS_:hooked>{}
  14.     _ALS_()<>{}
  15. #endif
  16.  
  17. enum VehicleInfo
  18. {
  19.     vTime,
  20.     vSpawnTime,
  21.     vUsed,
  22.     vDest,
  23. };
  24. new VehicleControl[MAX_VEHICLES][VehicleInfo];
  25.  
  26. enum PlayerVehicleE
  27. {
  28.     vLastVehicle,
  29. };
  30. new PlayerVehicle[MAX_PLAYERS][PlayerVehicleE];
  31. new t_VehiclesSpawnTimer = -1;
  32.  
  33. native IsValidVehicle(vehicleid);
  34.  
  35. forward hokCreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay);
  36. public hokCreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay)
  37. {
  38.     new
  39.         id = 0xFFFF;
  40.     id = CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, -1);
  41.  
  42.     if(id != 0xFFFF){
  43.         VehicleControl[id][vSpawnTime] = respawn_delay;
  44.         VehicleControl[id][vTime] = 0;
  45.         VehicleControl[id][vUsed] = 0xFFFF;
  46.     }
  47.     return id;
  48. }
  49.  
  50. forward hokDestroyVehicle(vehicleid);
  51. public hokDestroyVehicle(vehicleid)
  52. {
  53.     VehicleControl[vehicleid][vSpawnTime] = -1;
  54.     VehicleControl[vehicleid][vTime] = 0;
  55.     VehicleControl[vehicleid][vUsed] = 0xFFFF;
  56.     DestroyVehicle(vehicleid);
  57. }
  58.  
  59. forward ResetVehicleTime(vehicleid);
  60. public ResetVehicleTime(vehicleid)
  61. {
  62.     VehicleControl[vehicleid][vTime] = 0;
  63.     DestroyVehicle(vehicleid);
  64. }
  65.  
  66. public OnGameModeInit()
  67. {
  68.     if(t_VehiclesSpawnTimer == -1){
  69.         t_VehiclesSpawnTimer = SetTimer("DestroyCars", 1000, true);
  70.     }
  71.     state _ALS_:hooked;
  72.     return NOP_OnGameModeInit();
  73. }
  74.  
  75. forward NOP_OnGameModeInit();
  76.  
  77. #if defined _ALS_OnGameModeInit
  78.     #undef OnGameModeInit
  79. #else
  80.     #define _ALS_OnGameModeInit
  81. #endif
  82.  
  83. public NOP_OnGameModeInit() <_ALS_:unhooked> return 1;
  84. public NOP_OnGameModeInit() <> return 1;
  85.  
  86. forward OnPlayerVehicleTime(vehicleid, playerid);
  87.  
  88. forward DestroyCars(); public DestroyCars(){
  89.     for(new i = 0; i <= MAX_VEHICLES; i++) if(IsValidVehicle(i) && VehicleControl[i][vSpawnTime] != -1){
  90.         if(VehicleControl[i][vUsed] == 0xFFFF)
  91.         {
  92.             VehicleControl[i][vTime] ++;
  93.             CallLocalFunction("OnPlayerVehicleTime", "ddd", i, ((IsPlayerConnected(VehicleControl[i][vUsed])) ? (0xFFFF) : (VehicleControl[i][vUsed])));
  94.         }
  95.         else{
  96.             if(VehicleControl[i][vTime] > 1){
  97.                 VehicleControl[i][vTime] = 0;
  98.             }
  99.         }
  100.     }
  101.     return 0;
  102. }
  103.  
  104. forward GetPlayerVehicleTime(vehicleid); public GetPlayerVehicleTime(vehicleid){
  105.     if(!IsValidVehicle(vehicleid))
  106.         return 0;
  107.  
  108.     return (VehicleControl[vehicleid][vTime]);
  109. }
  110.  
  111. forward GetPlayerVehicleMaxTime(vehicleid); public GetPlayerVehicleMaxTime(vehicleid){
  112.     if(!IsValidVehicle(vehicleid))
  113.         return 0;
  114.  
  115.     return (VehicleControl[vehicleid][vSpawnTime]);
  116. }
  117.  
  118. IsVehicleOccupied(vehid){
  119.     for(new i; i <= MAX_PLAYERS; i++) {
  120.         if(IsPlayerConnected(i)) {
  121.             if(IsPlayerInVehicle(i, vehid)) return 1;
  122.         }
  123.     }
  124.     return 0;
  125. }
  126.  
  127. public OnPlayerDisconnect(playerid, reason)
  128. {
  129.     if(IsPlayerInAnyVehicle(playerid) && !IsVehicleOccupied(GetPlayerVehicleID(playerid))){
  130.         VehicleControl[GetPlayerVehicleID(playerid)][vUsed] = 0xFFFF;
  131.     }
  132.     state _ALS_:hooked;
  133.     return hokOnPlayerDisconnect(playerid, reason);
  134. }
  135.  
  136. forward hokOnPlayerDisconnect(playerid, reason);
  137.  
  138. #if defined _ALS_OnPlayerDisconnect
  139.     #undef OnPlayerDisconnect
  140. #else
  141.     #define _ALS_OnPlayerDisconnect
  142. #endif
  143.  
  144. public hokOnPlayerDisconnect() <_ALS_:unhooked> return 1;
  145. public hokOnPlayerDisconnect() <> return 1;
  146.  
  147. public OnPlayerStateChange(playerid, newstate, oldstate)
  148. {
  149.     if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER){
  150.             VehicleControl[GetPlayerVehicleID(playerid)][vTime] = 0;
  151.         VehicleControl[GetPlayerVehicleID(playerid)][vUsed] = playerid;
  152.         PlayerVehicle[playerid][vLastVehicle] = GetPlayerVehicleID(playerid);
  153.     }
  154.     else if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER && newstate == PLAYER_STATE_ONFOOT && !IsVehicleOccupied(PlayerVehicle[playerid][vLastVehicle])){
  155.         VehicleControl[GetPlayerVehicleID(playerid)][vUsed] = 0xFFFF;
  156.     }
  157.     return 1;
  158. }
  159.  
  160. forward hokOnPlayerStateChange(playerid, newstate, oldstate);
  161.  
  162. #if defined _ALS_OnPlayerStateChange
  163.     #undef OnPlayerStateChange
  164. #else
  165.     #define _ALS_OnPlayerStateChange
  166. #endif
  167.  
  168. public hokOnPlayerStateChange() <_ALS_:unhooked> return 1;
  169. public hokOnPlayerStateChange() <> return 1;
  170.  
  171. #define OnGameModeInit(%0) NOP_OnGameModeInit(%0)<_ALS_:hooked>
  172. #define OnPlayerDisconnect(%0) hokOnPlayerDisconnect(%0)<_ALS_:hooked>
  173. #define OnPlayerStateChange(%0) hokOnPlayerStateChange(%0)<_ALS_:hooked>
  174. #define CreateVehicle hokCreateVehicle
  175. #define DestroyVehicle hokDestroyVehicle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement