Beispiel #1
0
 public function Update()
 {
     if ($this->location == null) {
         return;
     }
     $this->updates++;
     /* Update player position, speed and area sector */
     GetPlayerPos($this->id, &$this->position->x, &$this->position->y, &$this->position->z);
     GetPlayerFacingAngle($this->id, &$this->position->angle);
     $this->speed = $this->last_updated_position->DistanceTo($this->position);
     $sector = $this->location->Locate($this->position);
     if ($this->sector->id != $sector->id) {
         $this->sector->RemovePlayer($this);
         $sector->AddPlayer($this);
     }
     $this->sector = $sector;
     $this->last_updated_position = clone $this->position;
     /* Save player state */
     $this->state = GetPlayerState($this->id);
     if ($this->firstSpawn) {
         return;
     }
     /* Update ping */
     $this->ping = GetPlayerPing($this->id);
     /* Check the player vehicle */
     if (IsPlayerInAnyVehicle($this->id)) {
         if ($this->vehicle === null) {
             /* Show incar textdraw */
             $this->incar_draw = Players::GetIncarDraw($this->id);
             TextDrawShowForPlayer($this->id, $this->incar_draw);
             TextDrawSetString($this->incar_draw, '...');
         }
         $this->vehicle = Vehicles::FindByID(GetPlayerVehicleID($this->id));
         if ($this->vehicle != null) {
             if ($this->state == PLAYER_STATE_DRIVER && $this->vehicle->Type() == VEHICLE_SHOP) {
                 $this->Freeze();
             }
         }
     } else {
         if ($this->incar_draw !== null) {
             /* Hide incar textdraw */
             TextDrawHideForPlayer($this->id, $this->incar_draw);
             $this->incar_draw = null;
         }
         if ($this->vehicle != null) {
             if ($this->vehicle->Type() == VEHICLE_SHOP) {
                 /* Player was freezed in a shop vehicle but left it, so allow him to move again */
                 $this->Freeze(false);
             }
         }
         $this->vehicle = null;
     }
     /* Update the incar textdraw */
     if ($this->incar_draw !== null && $this->updates & 1) {
         if ($this->speedometer == 'mph') {
             $speed = $this->speed * 4.464;
         } else {
             $speed = $this->speed * 7.2;
         }
         $string = sprintf('~y~Speed~n~~w~%d %s~n~~y~Fuel~n~~w~%.1f LT', (int) $speed, $this->speedometer, $this->vehicle->Fuel());
         TextDrawSetString($this->incar_draw, $string);
     }
     /**
      ** Update the nametag drawing
      **/
     $sectors = $this->sector->FindSectors($this->position, 12.5);
     $watchplayers = array();
     foreach ($sectors as $sector) {
         foreach ($sector->GetPlayers() as $player) {
             if ($player->id >= $this->id) {
                 break;
             }
             if ($this->position->DistanceTo($player->position) < 12.5) {
                 $watchplayers[$player->id] = $player;
             }
         }
     }
     ksort($watchplayers);
     $i = 0;
     foreach ($watchplayers as $id => $player) {
         for (; $i < $id; $i++) {
             if ($this->seeingNametags[$i] == true) {
                 $p = Players::FindByID($i);
                 if ($p) {
                     $this->CanIdentify($p, false);
                     $p->CanIdentify($this, false);
                 }
                 $this->seeingNametags[$i] = false;
             }
         }
         $i++;
         if ($this->vehicle == $player->vehicle) {
             $equalv = true;
         } else {
             $equalv = false;
         }
         if (!$player->vehicle || !$player->vehicle->HasWindows() || $this->vehicle && $equalv) {
             if ($this->seeingNametags[$id] == false) {
                 $this->CanIdentify($player, true);
             }
         } else {
             if ($this->seeingNametags[$id] == true) {
                 $this->CanIdentify($player, false);
             }
         }
         if (!$this->vehicle || !$this->vehicle->HasWindows() || $player->vehicle && $equalv) {
             if ($player->seeingNametags[$this->id] == false) {
                 $player->CanIdentify($this, true);
             }
         } else {
             if ($player->seeingNametags[$this->id] == true) {
                 $player->CanIdentify($this, false);
             }
         }
     }
     while ($i < $this->id) {
         if ($this->seeingNametags[$i] == true) {
             $player = Players::FindByID($i);
             if ($player) {
                 $this->CanIdentify($player, false);
                 $player->CanIdentify($this, false);
             }
         }
         $i++;
     }
     /**
      ** Update the hunger and injures health
      **/
     if ($this->checkhealth && !$this->dead) {
         $cur = time();
         if ($this->timedeath > 0) {
             if ($cur - $this->timedeath > 60) {
                 /* If the player was 60 seconds dieing, finish him */
                 $this->Kill();
             } else {
                 if ($cur - $this->timedeath > 5) {
                     /* After 5 seconds, other players are allowed to finish him */
                     GetPlayerHealth($this->id, &$health);
                     if ($health + 2 < $this->hunger * 100 / MAX_HUNGER_POINTS) {
                         $this->Kill();
                     }
                 } else {
                     $health = $this->hunger * 100 / MAX_HUNGER_POINTS;
                     if ($health <= 0) {
                         $this->Kill();
                     } else {
                         SetPlayerHealth($this->id, $health);
                     }
                 }
             }
         } else {
             $this->hunger--;
             $health = $this->hunger * 100 / MAX_HUNGER_POINTS;
             if ($health == 0) {
                 $this->Kill();
             } else {
                 if (!$this->lagprotection) {
                     GetPlayerHealth($this->id, &$tmphealth);
                     if ($tmphealth == 0) {
                         $this->Kill();
                     } else {
                         if (!($this->hunger % 20)) {
                             /* Update health only every 10 seconds */
                             SetPlayerHealth($this->id, $health);
                         }
                         GetPlayerArmour($this->id, &$armor);
                         if ($tmphealth + 2 < $health) {
                             SetPlayerHealth($this->id, $health);
                             $armor -= $health - $tmphealth;
                             SetPlayerArmour($this->id, $armor);
                         }
                         if ($armor < 0) {
                             $armor = 0;
                         }
                         /* The lowest possible armor points is 0 */
                         $injures = 100 - $armor;
                         if ($injures < $this->injures) {
                             /* The player has less injures than he should have */
                             SetPlayerArmour($this->id, 100 - $this->injures);
                         } else {
                             if ($injures > $this->injures) {
                                 /* The player has more injures that the last registered ones */
                                 $this->injures = $injures;
                             }
                         }
                         if ($this->injures == 100) {
                             /* The player is dead, full injures */
                             if (IsPlayerInAnyVehicle($this->id)) {
                                 $this->Kill();
                             } else {
                                 $anim = Animations::GetDeathAnim();
                                 $this->ClearAnimations();
                                 $this->Animate($anim);
                                 $this->timedeath = time();
                                 $this->Send(COLOR_YELLOW, '* You are dieing! You will be dead in one minute if you don\'t get a medic help.');
                                 $this->Send(COLOR_YELLOW, '* You can also accept your own death after 10 seconds using /die command.');
                                 SetPlayerArmour($this->id, 0);
                             }
                         }
                     }
                 }
             }
         }
     }
     /* If the player has lag protection, decrease one unit */
     if ($this->lagprotection) {
         $this->lagprotection--;
     }
     if ($this->lagprotection_guns) {
         $this->lagprotection_guns--;
     }
     /* Update the jail time */
     if ($this->jailtime != 0 && $this->updates & 1) {
         $this->jailtime--;
         if ($this->jailtime < 1) {
             /* Unjail the player */
             $this->jailtime = 1;
             $this->Unjail();
         } else {
             /* Ensure that the player is still in jail */
             $bounds = PoliceDepartment::AdminCellBounds();
             if (!$this->position->IsInCube($bounds['min'], $bounds['max'])) {
                 $this->SetLocation(PoliceDepartment::Instance());
                 $this->SetPosition(PoliceDepartment::AdminCell());
             }
             /* Send the time remaining message */
             GameTextForPlayer($this->id, "Jail time remaining: {$this->jailtime} seconds", 1000, 4);
         }
     }
     /*
      * Update animation
      */
     if ($this->animation && $this->updates & 1 && $this->vehicle == null && ($this->animation->forced || $this->animation->continue)) {
         ApplyAnimation($this->id, $this->animation->lib, $this->animation->anim, 4.0, $this->animation->loop, $this->animation->movex, $this->animation->movey, $this->animation->continue, $this->animation->time);
     }
 }
Beispiel #2
0
 private static function MakeUpgradeDraw(Player $player)
 {
     $draw = TextDrawCreate(222.0, 125.0, '...');
     if ($draw == INVALID_TEXT_DRAW) {
         return null;
     }
     TextDrawUseBox($draw, true);
     TextDrawBoxColor($draw, 0xbb);
     TextDrawTextSize($draw, 424.0, 20.0);
     TextDrawAlignment($draw, 0);
     TextDrawBackgroundColor($draw, 0xff);
     TextDrawFont($draw, true);
     TextDrawLetterSize($draw, 0.45, 1.76);
     TextDrawColor($draw, 0x495461dd);
     TextDrawSetOutline($draw, true);
     TextDrawSetProportional($draw, true);
     $str = 'Upgrade to level~n~';
     foreach (Players::$skills as $skill) {
         if ($skill->flag == SKILL_MAXUPGRADE) {
             break;
         }
         $nextlevel = $player->GetSkill($skill->flag) + 1;
         if ($skill->maxlevel < $nextlevel) {
             $str .= '~y~ Already highest level~n~';
         } else {
             if ($player->GetLevel() < $skill->reqlevels[$nextlevel]) {
                 $str .= "~r~ Player level {$skill->reqlevels[$nextlevel]} required~n~";
             } else {
                 if ($skill->reqskill != -1 && $player->GetSkill($skill->reqskill) < $skill->reqskill_level) {
                     $reqskill = Players::GetSkillName($skill->reqskill);
                     $str .= "~r~ {$reqskill} level {$skill->reqskill_level} required~n~";
                 } else {
                     $str .= "~w~ {$nextlevel} / {$skill->maxlevel}~n~";
                 }
             }
         }
     }
     TextDrawSetString($draw, $str);
     return $draw;
 }
Beispiel #3
0
 public static function UpdateClock()
 {
     static $last_hour = -1;
     $time = time();
     $hour = (int) ($time / 3600 + 1) % 24;
     if ($hour != $last_hour) {
         SetWorldTime($hour);
         $last_hour = $hour;
     }
     TextDrawSetString(Core::$clock, date('H:i', $time));
     $remaining = 60 - time() % 60;
     AddTimer(array('Core', 'UpdateClock'), $remaining * 1000, 0);
 }
Beispiel #4
0
 public static function ExerciseStep(Player $player, $correct_key)
 {
     if ($correct_key) {
         Gym::$players_gained[$player->id]++;
     } else {
         if (Gym::$players_gained[$player->id] > 0) {
             Gym::$players_gained[$player->id]--;
         }
     }
     do {
         $oldkey = Gym::$players_key[$player->id];
         $key = rand(0, count(Gym::$keys) - 1);
         Gym::$players_key[$player->id] = Gym::$keys[$key];
     } while ($oldkey == Gym::$players_key[$player->id]);
     $str = '';
     if (!$correct_key) {
         $str = '~r~Wrong key!~n~';
     }
     $str .= '~w~Press ~r~' . Gym::$keystr[$key] . '~n~~w~-~n~Strength~n~gained:~g~ ' . (int) (Gym::$players_gained[$player->id] / 1);
     TextDrawSetString(Gym::$draws[$player->id], $str);
 }