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); } }
public static function Handle($playerid, $cmdtext) { $player = Players::FindByID($playerid); if ($player == null) { return 0; } // Log::Append(LOG_COMMAND, "[{$player->id}] {$player->name} -> {$cmdtext}"); $params = explode(' ', substr($cmdtext, 1)); $name = strtolower($params[0]); if (!isset(CommandHandler::$commands[$name])) { return 0; } $cmd = CommandHandler::$commands[$name]; if ($cmd->authed && (!$player->account || !$player->account->Authed())) { $player->Send(COLOR_RED, '* Login before sending this command'); return 1; } $numparams = count($params) - 1; if ($numparams < $cmd->numparams) { CommandHandler::SendUsage($player, $name, $cmd); } else { if (!$cmd->Call($player, $numparams, $params)) { CommandHandler::SendUsage($player, $name, $cmd); } } return 1; }
public function OnPlayerKeyStateChange($playerid, $newkeys, $oldkeys) { if ($this->callbacks[cOnPlayerKeyStateChange] == null) { return 1; } $player = Players::FindByID($playerid); if ($player == null) { return 1; } for ($cbk = $this->callbacks[cOnPlayerKeyStateChange]; $cbk != null; $cbk = $cbk->next) { $obj = $cbk->GetObj(); $func = $cbk->GetFunc(); if ($obj) { $ret = $obj->{$func}($player, $newkeys, $oldkeys); } else { $ret = call_user_func($func, $player, $newkeys, $oldkeys); } if ($ret != CALLBACK_OK) { break; } } if ($ret & CALLBACK_DISALLOW) { return 0; } return 1; }
public static function Find($id) { if (ctype_digit($id)) { return Players::FindByID($id); } $result = null; $len = strlen($id); foreach (Players::$players as $player) { if (!strncasecmp($id, $player->name, $len)) { if ($result) { return null; } $result = $player; } } return $result; }
public static function OnPlayerConnect($playerid) { $player = Players::FindByID($playerid); if ($player == null) { return CALLBACK_BREAK; } $data = DB::GetAccount($player->name); if ($data == null) { $player->Send(COLOR_YELLOW, '[ACCOUNT REGISTRATION REQUIRED]'); $player->Send(COLOR_RED, '* Your name is not registered at ItalyMafia.'); $player->Send(COLOR_RED, '* If you want to create a new account visit'); $player->Send(COLOR_RED, '* http://panel.mafiaroleplay.net'); $player->Kick(); return CALLBACK_BREAK; } else { if ($data['banned'] != null) { if (time() < $data['ban_expiration']) { $datestr = date('r', $data['ban_expiration']); $player->Kick("* You are banned until {$datestr}: {$data['banned']}"); return CALLBACK_BREAK; } else { /* Ban expired */ $unban['id'] = $data['id']; $data['banned'] = null; $unban['banned'] = null; $data['banned_by'] = null; $unban['banned_by'] = null; $data['ban_date'] = null; $unban['ban_date'] = null; $data['ban_expiration'] = null; $unban['ban_expiration'] = null; DB::SaveAccount($unban); } } } $player->Send(COLOR_YELLOW, '* This account is registered. If it is your account then type'); $player->Send(COLOR_YELLOW, '* \'/login your_password\'. You have two minutes to login.'); $player->account = new Account($player, $data); }