Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // _ZUME
- #include <a_samp>
- #if defined _OnPlayerVehicleTime_included
- #endinput
- #endif
- #define _OnPlayerVehicleTime_included
- #if !defined _ALS_
- forward public _ALS_();
- _ALS_()<_ALS_:unhooked>{}
- _ALS_()<_ALS_:hooked>{}
- _ALS_()<>{}
- #endif
- enum VehicleInfo
- {
- vTime,
- vSpawnTime,
- vUsed,
- vDest,
- };
- new VehicleControl[MAX_VEHICLES][VehicleInfo];
- enum PlayerVehicleE
- {
- vLastVehicle,
- };
- new PlayerVehicle[MAX_PLAYERS][PlayerVehicleE];
- new t_VehiclesSpawnTimer = -1;
- native IsValidVehicle(vehicleid);
- forward hokCreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay);
- public hokCreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay)
- {
- new
- id = 0xFFFF;
- id = CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, -1);
- if(id != 0xFFFF){
- VehicleControl[id][vSpawnTime] = respawn_delay;
- VehicleControl[id][vTime] = 0;
- VehicleControl[id][vUsed] = 0xFFFF;
- }
- return id;
- }
- forward hokDestroyVehicle(vehicleid);
- public hokDestroyVehicle(vehicleid)
- {
- VehicleControl[vehicleid][vSpawnTime] = -1;
- VehicleControl[vehicleid][vTime] = 0;
- VehicleControl[vehicleid][vUsed] = 0xFFFF;
- DestroyVehicle(vehicleid);
- }
- public OnGameModeInit()
- {
- if(t_VehiclesSpawnTimer == -1){
- t_VehiclesSpawnTimer = SetTimer("DestroyCars", 1000, true);
- }
- state _ALS_:hooked;
- return NOP_OnGameModeInit();
- }
- forward NOP_OnGameModeInit();
- #if defined _ALS_OnGameModeInit
- #undef OnGameModeInit
- #else
- #define _ALS_OnGameModeInit
- #endif
- public NOP_OnGameModeInit() <_ALS_:unhooked> return 1;
- public NOP_OnGameModeInit() <> return 1;
- forward OnPlayerVehicleTime(vehicleid, playerid, time);
- forward DestroyCars(); public DestroyCars(){
- for(new i = 0; i <= MAX_VEHICLES; i++) if(IsValidVehicle(i) && VehicleControl[i][vSpawnTime] != -1){
- if(VehicleControl[i][vUsed] == 0xFFFF){
- if(VehicleControl[i][vTime] >= VehicleControl[i][vSpawnTime]){
- CallLocalFunction("OnPlayerVehicleTime", "ddd", i, ((IsPlayerConnected(VehicleControl[i][vUsed])) ? (0xFFFF) : (VehicleControl[i][vUsed])), VehicleControl[i][vTime]);
- }
- else{
- VehicleControl[i][vTime] ++;
- }
- }
- else{
- if(VehicleControl[i][vTime] > 1){
- VehicleControl[i][vTime] = 0;
- }
- }
- }
- return 0;
- }
- forward GetPlayerVehicleTime(vehicleid); public GetPlayerVehicleTime(vehicleid){
- if(!IsValidVehicle(vehicleid))
- return 0;
- return (VehicleControl[vehicleid][vTime]);
- }
- forward GetPlayerVehicleMaxTime(vehicleid); public GetPlayerVehicleMaxTime(vehicleid){
- if(!IsValidVehicle(vehicleid))
- return 0;
- return (VehicleControl[vehicleid][vSpawnTime]);
- }
- IsVehicleOccupied(vehid){
- for(new i; i <= MAX_PLAYERS; i++) {
- if(IsPlayerConnected(i)) {
- if(IsPlayerInVehicle(i, vehid)) return 1;
- }
- }
- return 0;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- if(IsPlayerInAnyVehicle(playerid) && !IsVehicleOccupied(GetPlayerVehicleID(playerid))){
- VehicleControl[GetPlayerVehicleID(playerid)][vUsed] = 0xFFFF;
- }
- state _ALS_:hooked;
- return hokOnPlayerDisconnect(playerid, reason);
- }
- forward hokOnPlayerDisconnect(playerid, reason);
- #if defined _ALS_OnPlayerDisconnect
- #undef OnPlayerDisconnect
- #else
- #define _ALS_OnPlayerDisconnect
- #endif
- public hokOnPlayerDisconnect() <_ALS_:unhooked> return 1;
- public hokOnPlayerDisconnect() <> return 1;
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER){
- VehicleControl[GetPlayerVehicleID(playerid)][vTime] = 0;
- VehicleControl[GetPlayerVehicleID(playerid)][vUsed] = playerid;
- PlayerVehicle[playerid][vLastVehicle] = GetPlayerVehicleID(playerid);
- }
- else if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER && newstate == PLAYER_STATE_ONFOOT && !IsVehicleOccupied(PlayerVehicle[playerid][vLastVehicle])){
- VehicleControl[GetPlayerVehicleID(playerid)][vUsed] = 0xFFFF;
- }
- return 1;
- }
- forward hokOnPlayerStateChange(playerid, newstate, oldstate);
- #if defined _ALS_OnPlayerStateChange
- #undef OnPlayerStateChange
- #else
- #define _ALS_OnPlayerStateChange
- #endif
- public hokOnPlayerStateChange() <_ALS_:unhooked> return 1;
- public hokOnPlayerStateChange() <> return 1;
- #define OnGameModeInit(%0) NOP_OnGameModeInit(%0)<_ALS_:hooked>
- #define OnPlayerDisconnect(%0) hokOnPlayerDisconnect(%0)<_ALS_:hooked>
- #define OnPlayerStateChange(%0) hokOnPlayerStateChange(%0)<_ALS_:hooked>
- #define CreateVehicle hokCreateVehicle
- #define DestroyVehicle hokDestroyVehicle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement