SA-MP Forums Archive
Detect vehicle not move after 10 seconds - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Detect vehicle not move after 10 seconds (/showthread.php?tid=446853)



Detect vehicle not move after 10 seconds - vardanega - 27.06.2013

Hello,

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

Thank you for your help


Re : Detect vehicle not move after 10 seconds - yusei - 27.06.2013

by GetPlayerSpeed

https://sampwiki.blast.hk/wiki/Useful_Fu...GetPlayerSpeed


Re: Detect vehicle not move after 10 seconds - MP2 - 27.06.2013

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).


Re: Detect vehicle not move after 10 seconds - feartonyb - 27.06.2013

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!");
             }
          }
        }
     }
}



Re : Detect vehicle not move after 10 seconds - vardanega - 27.06.2013

Thx its works !


Re: Detect vehicle not move after 10 seconds - park4bmx - 27.06.2013

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 ?


Re : Detect vehicle not move after 10 seconds - vardanega - 28.06.2013

the solution park4bmx


Re: Detect vehicle not move after 10 seconds - feartonyb - 28.06.2013

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;
          } 
        }
     }
}



Re: Detect vehicle not move after 10 seconds - park4bmx - 28.06.2013

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
        }
}