NPC Detect Car In Front!
#1

need help this is driving me potty basically need a stock but nothing calculates it write including angle;

I want it so it detects its angle its x y z pos then distance from vehicle in front of a min gap between vehicles enough for a player to walk through them both any ideas ??
thanks
Reply
#2

A stock to detect the car in front of you?

Start with defining a variable for the car.

Then using a timer, check if a player is in range of that car's coordinates.

If it is, get that car's facing angle.

Is that it? You won't be able to do this using a stock. It requires a timer, and much more as well.
Reply
#3

atm im using it like this but its not accurate enough if I stop 1 range away from the vehicle it stops when I go closer it starts the npc any other ideas example code below?
PHP код:
stock GetXYInfrontOfMe(Float:distanceFloat:xFloat:yFloat:z)
{
    new 
Float:angle;
    
GetMyPos(xyz);
    
GetMyFacingAngle(angle);
    
+= (distance floatsin(-angledegrees));
    
+= (distance floatcos(-angledegrees));
}
stock TrafficPause()
{
  new 
Float:XFloat:YFloat:Z;
  
GetMyPos(XYZ);
  
GetXYInfrontOfMe(0.1XYZ);
  for(new 
0MAX_PLAYERSi++)
  {
    if(
IsPlayerConnected(i) && IsPlayerStreamedIn(i))
    {
      if(
GetPlayerState(i) == PLAYER_STATE_DRIVER)
      {
          if(
IsPlayerInRangeOfPoint(i1.0XYZ))
          {
            return 
1;
          }
      }
    }
  }
  return 
0;
}
public 
ScanForTraffic()
{
  new 
ReasonToPauseNPC TrafficPause();
  if(
ReasonToPauseNPC && !StoppedForTraffic)
  {
    
SendChat("I'm pausing");
    
PauseRecordingPlayback();
    
StoppedForTraffic 1;
    return 
1;
  }
  else if(!
ReasonToPauseNPC && StoppedForTraffic)
  {
    
SendChat("I'm resuming");
    
ResumeRecordingPlayback();
    
StoppedForTraffic 0;
    return 
1;
  }
  return 
0;

Reply
#4

Ah, well, I'm not an expert at NPCs, sorry.
Reply
#5

Quote:
Originally Posted by Pillhead2007
Посмотреть сообщение
atm im using it like this but its not accurate enough if I stop 1 range away from the vehicle it stops when I go closer it starts the npc any other ideas example code below?
PHP код:
stock GetXYInfrontOfMe(Float:distanceFloat:xFloat:yFloat:z)
{
    new 
Float:angle;
    
GetMyPos(xyz);
    
GetMyFacingAngle(angle);
    
+= (distance floatsin(-angledegrees));
    
+= (distance floatcos(-angledegrees));
}
stock TrafficPause()
{
  new 
Float:XFloat:YFloat:Z;
  
GetMyPos(XYZ);
  
GetXYInfrontOfMe(0.1XYZ);
  for(new 
0MAX_PLAYERSi++)
  {
    if(
IsPlayerConnected(i) && IsPlayerStreamedIn(i))
    {
      if(
GetPlayerState(i) == PLAYER_STATE_DRIVER)
      {
          if(
IsPlayerInRangeOfPoint(i1.0XYZ))
          {
            return 
1;
          }
      }
    }
  }
  return 
0;
}
public 
ScanForTraffic()
{
  new 
ReasonToPauseNPC TrafficPause();
  if(
ReasonToPauseNPC && !StoppedForTraffic)
  {
    
SendChat("I'm pausing");
    
PauseRecordingPlayback();
    
StoppedForTraffic 1;
    return 
1;
  }
  else if(!
ReasonToPauseNPC && StoppedForTraffic)
  {
    
SendChat("I'm resuming");
    
ResumeRecordingPlayback();
    
StoppedForTraffic 0;
    return 
1;
  }
  return 
0;

Just a shot in the dark here but what if you changed the 1.0 to just 1, as in binary coding
Reply
#6

nope didn't work either
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)