Example #1
0
function dodrivenext(Player $player, $numparams, $params)
{
    $pos = $player->Position();
    $nearest = null;
    $distance = 0;
    for ($i = 0; $i < 700; $i++) {
        GetVehiclePos($i, &$x, &$y, &$z);
        if ($x == 0 && $y == 0 && $z == 0) {
            continue;
        }
        $vpos = new Position($x, $y, $z);
        $dist = $vpos->DistanceTo($pos);
        if ($nearest === null || $dist < $distance) {
            $distance = $dist;
            $nearest = $i;
        }
    }
    if ($nearest !== null) {
        PutPlayerInVehicle($player->id, $nearest, 0);
    }
    return COMMAND_OK;
}
Example #2
0
 /**
  ** AddOBject
  ** Adds a dynamic object to this location. If sight is -1, then objects are always shown.
  **
  ** Parameters:
  ** - modelid:  Model of the object
  ** - position: Position of the object
  ** - rotation: Rotation of the object
  **/
 public function AddObject($modelid, Position $position, Position $rotation = null, $sight = 0)
 {
     /* Create the object */
     if ($sight == 0) {
         $sight = $this->sight;
     }
     if ($rotation == null) {
         $rotation = new Position(0, 0, 0, 0);
     }
     $obj = new Obj($modelid, $position, $rotation, $sight);
     /* Find this object nearest objects */
     if ($sight != -1) {
         foreach ($this->objects as $o) {
             if ($position->DistanceTo($o->position) < $sight) {
                 $obj->SetNear($o);
                 $o->SetNear($obj);
             }
         }
     }
     /* This object is also near itself */
     $obj->SetNear($obj);
     /* Add the object to this location objects list */
     $this->objects[] = $obj;
     /* Add the object to its sector objects */
     $sector = $this->area->Locate($position);
     if ($sight != -1) {
         $sectors = $sector->FindSectors($position, $sight);
         foreach ($sectors as $sector) {
             $sector->AddObject($obj);
         }
     } else {
         $sector->AddObject($obj);
     }
 }
Example #3
0
 public function FindNearestObject(Position $position, &$nearest, &$distance)
 {
     foreach ($this->objects as $o) {
         $tmpdist = $position->DistanceTo($o->position);
         if ($tmpdist > $o->Sight()) {
             continue;
         }
         if ($tmpdist < $distance || $nearest == null) {
             $nearest = $o;
             $distance = $tmpdist;
         }
     }
 }