Detect vehicle not move after 10 seconds
#1

Hello,

I want to know how to detect when a vehicle is not moving for more than 10 seconds.

Thank you for your help
Reply
#2

by GetPlayerSpeed

https://sampwiki.blast.hk/wiki/Useful_Fu...GetPlayerSpeed
Reply
#3

Just check if their velocity (X, Y and Z) is 0 for >= 10 seconds. No need for algorithms and formulas. Check it on a timer or OnPlayerUpdate (a timer would be better).
Reply
#4

Put on top of the script:
Code:
new InVehicleTime[MAX_PLAYERS];
Then put under OnGameModeInIt:
Code:
SetTimer("InVehicleCheck", 1000, true);
Then make a public:
Code:
forward InVehicleCheck();
public InVehicleCheck()
{
     for(new i; i < MAX_PLAYERS; i++)
     {
        if(IsPlayerInAnyVehicle(i))
        {
          new Float:Velocity[3], output[80];
	  GetVehicleVelocity(GetPlayerVehicleID(playerid), Velocity[0], Velocity[1], Velocity[2]);
          if(Velocity[0] == 0 && Velocity[1] == 0 && Velocity[2] == 0)
          {
             if(InVehicleTime[playerid] < 10)
             {
                 InVehicleTime[playerid] = InVehicleTime[playerid]+1;
             }
             else
             {
                 SendClientMessage(playerid, -1, "You are not moving with your vehicle for 10+ seconds!");
             }
          }
        }
     }
}
Reply
#5

Thx its works !
Reply
#6

that will cause problems !
it doesn't reset (1)
It will continue from the stopped time (2) (in this case the last variable num)
Don't think will work a second time (3)

And where do you get playerid in that callback as there is no such variable ?
Reply
#7

the solution park4bmx
Reply
#8

Try this:

Put on top of the script:
Code:
new InVehicleTime[MAX_PLAYERS];
Then put under OnGameModeInIt:
Code:
SetTimer("InVehicleCheck", 1000, true);
Then make a public:
Code:
forward InVehicleCheck();
public InVehicleCheck()
{
     for(new i; i < MAX_PLAYERS; i++)
     {
        if(IsPlayerInAnyVehicle(i))
        {
          new Float:Velocity[3], output[80];
	  GetVehicleVelocity(GetPlayerVehicleID(playerid), Velocity[0], Velocity[1], Velocity[2]);
          if(Velocity[0] == 0 && Velocity[1] == 0 && Velocity[2] == 0)
          {
             if(InVehicleTime[playerid] < 10)
             {
                 InVehicleTime[playerid] = InVehicleTime[playerid]+1;
             }
             else
             {
                 SendClientMessage(playerid, -1, "You are not moving with your vehicle for 10+ seconds!");
             }
          }
          else
          {
               InVehicleTime[playerid] = 0;
          } 
        }
     }
}
Reply
#9

pawn Code:
new ptimer[MAX_PLAYERS];

stock CheckPlayerPos(playerid)
{
    if(ptimer[playerid] !-1) KillTimer(ptimer[playerid])//Make sure no timers overstock
    new Float:pPos[3];GetPlayerPos(playerid, pPos[0], pPos[1],pPos[2]);
    ptimer[playerid] = SetTimerEx("InVeh", 10000, false, "ifff", playerid,pPos[0], pPos[1],pPos[2]);
    return 1;
}

forward InVeh(playerid,pPosX, pPosY,pPosZ)
public InVeh(playerid,pPosX, pPosY,pPosZ)
{
    new Float:NewpPos[3];GetPlayerPos(playerid, NewpPos[0], NewpPos[1],NewpPos[2]);
    if(NewpPos[0]==pPosX && NewpPos[1]==pPosY && NewpPos[2]==pPosZ)
        {
            //They Didnt Move
        }else{
            //They Moved
        }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)