Drive a car with Limit
#1

PHP код:
if ( newstate == PLAYER_STATE_DRIVER )
    {
        if ( 
PlayerInfoplayerid ] [ rVip] == )
        {
            if ( 
GetVehicleModelGetPlayerVehicleID playerid ) ) == 447 )
            {
                
RemovePlayerFromVehicle(playerid);
                
Announceplayerid"~r~~h~You need to be R.Vip to use this car!"3000);
            }
        }
 } 
Hello , this is the command lines that i have made for non R.Vips players , but i want that this vehicle to be used with limit!!
For Example if a R.Vip player enter this car and drive it and then leave it , when he try to enter that car again remove player from vehicle and then Show player this message ( SendClientMessage(playerid , COLOR_ULTRARED, "You need to wait 5 minutes before drive this car again");
Reply
#2

Create a variable to track the last time the player drove the vehicle:
pawn Код:
new lastDriveTime[MAX_PLAYERS];
And then when the player successfully enters the vehicle (for the first time), update the variable to the current time:
pawn Код:
lastDriveTime[playerid] = gettime();
Then you have to check the time that has passed to determine whether or not the player should be allowed to enter the vehicle: (5*60 -> 60 seconds * 5 = 5 minutes)
pawn Код:
new timeSinceLastDrive = gettime() - lastDriveTime[playerid];
if(timeSinceLastDrive < (5*60)) ...
So to integrate into your code, something like the following...
pawn Код:
if ( newstate == PLAYER_STATE_DRIVER )
    {
        if ( PlayerInfo[ playerid ] [ rVip] == 0 )
        {
            if ( GetVehicleModel( GetPlayerVehicleID ( playerid ) ) == 447 )
            {
                RemovePlayerFromVehicle(playerid);
                Announce( playerid, "~r~~h~You need to be R.Vip to use this car!", 3000, 4 );
            }
        }
        // Check last drive time. We have to check if lastDriveTime is equal to 0, too, because it will be if the player has joined and hasn't driven the car yet.
        new timeSinceLastDrive = gettime() - lastDriveTime[playerid];
        if(timeSinceLastDrive < (5*60) || lastDriveTime[playerid] == 0) {
                RemovePlayerFromVehicle(playerid);
                SendClientMessage(playerid , COLOR_ULTRARED, "You need to wait 5 minutes before drive this car again");
        }
 }  
// When the player has exited the vehicle, update their lastDriveTime
else if(oldstate == PLAYER_STATE_DRIVER) {
        if ( GetVehicleModel( GetPlayerVehicleID ( playerid ) ) == 447 ) {
                lastDriveTime[playerid] = gettime();
        }
}
Reply
#3

I will try it and if it will work , I will edit this Post and say it!!
But Thanks

PHP код:
public OnPlayerStateChange(playeridnewstateoldstate)
{
if ( 
newstate == PLAYER_STATE_DRIVER )
    {
        if(
AccInfo[playerid][pVip] < 7)
        {
            if ( 
GetVehicleModelGetPlayerVehicleID playerid ) ) == 447 )
            {
                
RemovePlayerFromVehicle(playerid);
                
SendClientMessage(playerid red"You need to be VIP level 7 to drive this car!");
            }
        }
        if(
AccInfo[playerid][pVip] > 7)
        {
           if ( 
GetVehicleModelGetPlayerVehicleID playerid ) ) == 447 )
        {
        
// Check last drive time. We have to check if lastDriveTime is equal to 0, too, because it will be if the player has joined and hasn't driven the car yet.
        
new timeSinceLastDrive gettime() - lastDriveTime[playerid];
        if(
timeSinceLastDrive < (5*60) || lastDriveTime[playerid] == 0) {
                
RemovePlayerFromVehicle(playerid);
                
SendClientMessage(playerid red"You need to wait 5 minutes before drive this car again!");
        }
 }
 }
 }
// When the player has exited the vehicle, update their lastDriveTime
else if(oldstate == PLAYER_STATE_DRIVER) {
        if ( 
GetVehicleModelGetPlayerVehicleID playerid ) ) == 447 ) {
                
lastDriveTime[playerid] = gettime();
        }

I do that but now when i use for the first time command /vheli and put me in that car, game removes me from the car and Show Message "You need to wait 5 minutes before drive this car again!"
I'm very n00b with this Restrictions and SetTimer commands lines!!
You can see the image down there!!
Reply
#4

Quote:
Originally Posted by CyberX
Посмотреть сообщение
I will try it and if it will work , I will edit this Post and say it!!
But Thanks
I do that but now when i use for the first time command /vheli and put me in that car, game removes me from the car and Show Message "You need to wait 5 minutes before drive this car again!"
I'm very n00b with this Restrictions and SetTimer commands lines!!
You can see the image down there!!
Oops. This line:
pawn Код:
if(timeSinceLastDrive < (5*60) || lastDriveTime[playerid] == 0) {
Should be this:
pawn Код:
if(timeSinceLastDrive < (5*60) && lastDriveTime[playerid] != 0) {
Reply
#5

Thanks now it's work
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)