Advertisement
ZumeZero

Include OnPlayerVehicleTime

Dec 27th, 2014
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.72 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. public OnGameModeInit()
  60. {
  61.     if(t_VehiclesSpawnTimer == -1){
  62.         t_VehiclesSpawnTimer = SetTimer("DestroyCars", 1000, true);
  63.     }
  64.     state _ALS_:hooked;
  65.     return NOP_OnGameModeInit();
  66. }
  67.  
  68. forward NOP_OnGameModeInit();
  69.  
  70. #if defined _ALS_OnGameModeInit
  71.     #undef OnGameModeInit
  72. #else
  73.     #define _ALS_OnGameModeInit
  74. #endif
  75.  
  76. public NOP_OnGameModeInit() <_ALS_:unhooked> return 1;
  77. public NOP_OnGameModeInit() <> return 1;
  78.  
  79. forward OnPlayerVehicleTime(vehicleid, playerid, time);
  80.  
  81. forward DestroyCars(); public DestroyCars(){
  82.     for(new i = 0; i <= MAX_VEHICLES; i++) if(IsValidVehicle(i) && VehicleControl[i][vSpawnTime] != -1){
  83.         if(VehicleControl[i][vUsed] == 0xFFFF){
  84.             if(VehicleControl[i][vTime] >= VehicleControl[i][vSpawnTime]){
  85.                 CallLocalFunction("OnPlayerVehicleTime", "ddd", i, ((IsPlayerConnected(VehicleControl[i][vUsed])) ? (0xFFFF) : (VehicleControl[i][vUsed])), VehicleControl[i][vTime]);
  86.             }
  87.             else{
  88.                 VehicleControl[i][vTime] ++;
  89.             }
  90.         }
  91.         else{
  92.             if(VehicleControl[i][vTime] > 1){
  93.                 VehicleControl[i][vTime] = 0;
  94.             }
  95.         }
  96.     }
  97.     return 0;
  98. }
  99.  
  100. forward GetPlayerVehicleTime(vehicleid); public GetPlayerVehicleTime(vehicleid){
  101.     if(!IsValidVehicle(vehicleid))
  102.         return 0;
  103.  
  104.     return (VehicleControl[vehicleid][vTime]);
  105. }
  106.  
  107. forward GetPlayerVehicleMaxTime(vehicleid); public GetPlayerVehicleMaxTime(vehicleid){
  108.     if(!IsValidVehicle(vehicleid))
  109.         return 0;
  110.  
  111.     return (VehicleControl[vehicleid][vSpawnTime]);
  112. }
  113.  
  114. IsVehicleOccupied(vehid){
  115.     for(new i; i <= MAX_PLAYERS; i++) {
  116.         if(IsPlayerConnected(i)) {
  117.             if(IsPlayerInVehicle(i, vehid)) return 1;
  118.         }
  119.     }
  120.     return 0;
  121. }
  122.  
  123. public OnPlayerDisconnect(playerid, reason)
  124. {
  125.     if(IsPlayerInAnyVehicle(playerid) && !IsVehicleOccupied(GetPlayerVehicleID(playerid))){
  126.         VehicleControl[GetPlayerVehicleID(playerid)][vUsed] = 0xFFFF;
  127.     }
  128.     state _ALS_:hooked;
  129.     return hokOnPlayerDisconnect(playerid, reason);
  130. }
  131.  
  132. forward hokOnPlayerDisconnect(playerid, reason);
  133.  
  134. #if defined _ALS_OnPlayerDisconnect
  135.     #undef OnPlayerDisconnect
  136. #else
  137.     #define _ALS_OnPlayerDisconnect
  138. #endif
  139.  
  140. public hokOnPlayerDisconnect() <_ALS_:unhooked> return 1;
  141. public hokOnPlayerDisconnect() <> return 1;
  142.  
  143. public OnPlayerStateChange(playerid, newstate, oldstate)
  144. {
  145.     if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER){
  146.         VehicleControl[GetPlayerVehicleID(playerid)][vTime] = 0;
  147.         VehicleControl[GetPlayerVehicleID(playerid)][vUsed] = playerid;
  148.         PlayerVehicle[playerid][vLastVehicle] = GetPlayerVehicleID(playerid);
  149.     }
  150.     else if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER && newstate == PLAYER_STATE_ONFOOT && !IsVehicleOccupied(PlayerVehicle[playerid][vLastVehicle])){
  151.         VehicleControl[GetPlayerVehicleID(playerid)][vUsed] = 0xFFFF;
  152.     }
  153.     return 1;
  154. }
  155.  
  156. forward hokOnPlayerStateChange(playerid, newstate, oldstate);
  157.  
  158. #if defined _ALS_OnPlayerStateChange
  159.     #undef OnPlayerStateChange
  160. #else
  161.     #define _ALS_OnPlayerStateChange
  162. #endif
  163.  
  164. public hokOnPlayerStateChange() <_ALS_:unhooked> return 1;
  165. public hokOnPlayerStateChange() <> return 1;
  166.  
  167. #define OnGameModeInit(%0) NOP_OnGameModeInit(%0)<_ALS_:hooked>
  168. #define OnPlayerDisconnect(%0) hokOnPlayerDisconnect(%0)<_ALS_:hooked>
  169. #define OnPlayerStateChange(%0) hokOnPlayerStateChange(%0)<_ALS_:hooked>
  170. #define CreateVehicle hokCreateVehicle
  171. #define DestroyVehicle hokDestroyVehicle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement