PHP code example of matthiggins / bluezone

1. Go to this page and download the library: Download matthiggins/bluezone library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

matthiggins / bluezone example snippets


use Bluezone\Bluezone;

$bluezone = new Bluezone($apiKey);

new Bluezone(string $apiKey, ?RateLimitStore $store = null, int $requestsPerMinute = 10);

use Bluezone\Bluezone;
use Saloon\RateLimitPlugin\Stores\PredisStore;

$bluezone = new Bluezone($apiKey, new PredisStore($predis), requestsPerMinute: 100);

use Saloon\RateLimitPlugin\Exceptions\RateLimitReachedException;

try {
    $player = $bluezone->player()->search('steam', 'TGLTN');
} catch (RateLimitReachedException $e) {
    $waitSeconds = $e->getLimit()->getRemainingSeconds();
}

use Bluezone\Enums\GameMode;
use Bluezone\Enums\Shard;

$bluezone->player()->search(Shard::Steam, 'TGLTN');
$bluezone->player()->search('steam', 'TGLTN');   // identical

Shard::Steam->label();          // 'PC (Steam)'
Shard::Psn->isConsole();        // true
GameMode::SquadFpp->label();    // 'Squad FPP'
GameMode::SquadFpp->teamSize(); // 4
GameMode::battleRoyale();       // the six BR modes

// Bluezone\Responses\Status
$status = $bluezone->status()->get();
$status->isOnline();
$status->version;             // null: the live endpoint currently returns neither version nor releasedAt

// Bluezone\Responses\Seasons
$seasons = $bluezone->season()->all('steam');
$seasons->seasons;          // Collection<Season>
$seasons->currentSeason();  // ?Season

// Bluezone\Responses\Clan
$clan = $bluezone->clan()->find('steam', $clanId);

// Bluezone\Responses\Player
$player = $bluezone->player()->find('steam', $accountId);
$player = $bluezone->player()->search('steam', $playerName); // exact in-game name
$player->matches;                                            // Collection<string> of match ids

// Bluezone\Responses\PlayerCollection (up to 10 names or account ids, one request)
$players = $bluezone->player()->searchMany('steam', [$nameOne, $nameTwo]);
$players = $bluezone->player()->findMany('steam', [$accountIdOne, $accountIdTwo]);

// Collection<PubgMatch>, one request per match
$matches = $bluezone->player()->recentMatches($player, limit: 20);
$ranked = $bluezone->player()->recentRankedMatches($player);
$casual = $bluezone->player()->recentCasualMatches($player);

// Bluezone\Responses\SeasonStats / SeasonStatsCollection
$seasonStats = $bluezone->player()->seasonStats('steam', $seasonId, $accountId);
$seasonStats->forMode(GameMode::SquadFpp);   // ?GameModeStats
$seasonStats->matches['squad-fpp'];          // match ids, kebab-case keys
$manyStats = $bluezone->player()->seasonStatsMany('steam', $seasonId, 'squad-fpp', [$accountId, $otherId]);

// Bluezone\Responses\RankedSeasonStats / RankedSeasonStatsCollection
$ranked = $bluezone->player()->rankedSeasonStats('steam', $seasonId, $accountId);
$ranked->forMode('squad-fpp')?->currentTier->label();   // 'Diamond 4'
$rankedMany = $bluezone->player()->rankedSeasonStatsMany('steam', $seasonId, [$accountId, $otherId]);

// Bluezone\Responses\LifetimeStats / LifetimeStatsCollection
$lifetime = $bluezone->player()->lifetimeStats('steam', $accountId);
$lifetime->forMode('solo-fpp')?->kills;
$lifetimeMany = $bluezone->player()->lifetimeStatsMany('steam', 'squad-fpp', [$accountId, $otherId]);

// Bluezone\Responses\WeaponMastery
$weapons = $bluezone->player()->weaponMastery('steam', $accountId);
$weapons->weaponSummaries;                   // array<string itemId, WeaponSummary>
$weapons->weaponSummaries['Item_Weapon_AK47_C']->statsTotal->kills;

// Bluezone\Responses\SurvivalMastery
$survival = $bluezone->player()->survivalMastery('steam', $accountId);
$survival->stats;                            // array<string key, SurvivalStat>
$survival->stats['damageDealt']->careerBest;

// Bluezone\Responses\PubgMatch
$match = $bluezone->match()->find('steam', $matchId);
$match->rosters;                             // Collection<MatchRoster>, sorted by rank
$match->statsForPlayer($accountId);          // ?PlayerMatchStats, null when the id did not play
$match->rosterForPlayer($accountId)?->won;
$match->teammatesOf($accountId);             // Collection<PlayerMatchStats>
$match->isRanked();
$match->totalPlayers();
$match->totalBots();
$match->botPercent();

// Bluezone\Responses\Samples: a random sample of recent public matches (hundreds of ids)
$samples = $bluezone->sample()->get('steam');                           // the last 24 hours
$samples = $bluezone->sample()->get('steam', now()->subHours(6));       // from a given time, within 14 days
$samples->matchIds;                          // Collection<string>

// Bluezone\Responses\Leaderboard: the top 500, in one page, sorted by rank
$board = $bluezone->leaderboard()->get('pc-eu', $seasonId, 'squad-fpp');
$board->players;                             // Collection<LeaderboardPlayer>
$board->players->first()->tier->label();     // 'Master 1'

use Bluezone\Exceptions\MatchNotFoundException;
use Bluezone\Exceptions\PlayerNotFoundException;

try {
    $player = $bluezone->player()->search('steam', $name);
} catch (PlayerNotFoundException $e) {
    $e->shard;       // Shard
    $e->identifier;  // the name or account id that was not found
}

try {
    $match = $bluezone->match()->find('steam', $matchId);
} catch (MatchNotFoundException $e) {
    // PUBG only keeps matches for about 14 days
}

$match = $bluezone->match()->find('steam', $matchId);

// Parse the file into a Bluezone\Responses\Telemetry DTO (reads it into memory)
$telemetry = $bluezone->telemetry()->fetch($match->assetUrl);
$telemetry = $match->getTelemetry();   // same thing

$stream = $bluezone->telemetry()->download($match->assetUrl);
$out = fopen('/archive/'.$match->id.'.json.gz', 'wb');
while (! $stream->eof()) {
    fwrite($out, $stream->read(1 << 20));
}
fclose($out);

// Every event as a Bluezone\Telemetry\Events\* object
$events = $telemetry->events();

// The undecoded events, exactly as PUBG wrote them
$raw = $telemetry->raw();

// Events after the first circle
$telemetry->eventsDuringGame();

// Event types this version of Bluezone has no class for, with their counts
$telemetry->unmappedTypes();   // ['LogSomeNewThing' => 12]

$player = $telemetry->player($accountId);

$player->all();                             // every event the player appears in
$player->attackEvents();
$player->attackEventsFromVehicle();
$player->causeDamageEvents();
$player->takeDamageEvents();
$player->killEvents();
$player->killEventsFromVehicle();
$player->knockEvents();
$player->knockEventsFromVehicle();
$player->downedEvents();
$player->healEvents();
$player->itemAttachEvents();
$player->itemDetachEvents();
$player->itemDropEvents();
$player->itemEquipEvents();
$player->itemPickupEvents();
$player->itemPickupFromCarePackageEvents();
$player->itemPickupFromCustomPackageEvents();
$player->itemPickupFromLootBoxEvents();
$player->itemUnequipEvents();
$player->itemUseEvents();
$player->objectDestroyEvents();
$player->objectInteractionEvents();
$player->parachuteLandingEvents();
$player->positionEvents();
$player->useThrowableEvents();
$player->swimEvents();
$player->swimStartEvents();
$player->swimEndEvents();
$player->vaultEvents();
$player->vehicleEvents();
$player->weaponFireCountEvents();
$player->wheelDestroyEvents();

// Interactions with one other player, and per-weapon slices
$player->causeDamageToPlayer($otherAccountId);
$player->takeDamageFromPlayer($otherAccountId);
$player->killEventsForWeapon('WeapHK416_C');
$player->causeDamageEventsForWeapon('WeapHK416_C');

// Environment
$player->takeBluezoneDamageEvents();

$telemetry->match()->definition();       // MatchDefinition
$telemetry->match()->start();            // MatchStart
$telemetry->match()->end();              // MatchEnd
$telemetry->match()->phaseChanges();     // Collection<PhaseChange>
$telemetry->match()->carePackageEvents();
$telemetry->match()->stateEvents();      // Collection<GameStatePeriodic>

use Bluezone\Telemetry\Events\PlayerAttack;
use Bluezone\Telemetry\Events\PlayerPosition;

$attacks = $telemetry->events()->filter(
    fn ($event) => $event instanceof PlayerAttack && $event->attacker->accountId === $accountId
);

// Or drop the noisiest types
$interesting = $telemetry->excludeEvents([PlayerPosition::class]);

use Bluezone\Bluezone;
use Bluezone\Requests\PlayerSearchRequest;
use Saloon\Http\Faking\MockClient;
use Saloon\Http\Faking\MockResponse;

$bluezone = new Bluezone('test-key');
$bluezone->withMockClient(new MockClient([
    PlayerSearchRequest::class => MockResponse::make(['data' => [/* ... */]]),
]));

MockResponse::fixture('player');   // tests/Fixtures/player.json

PUBG_API_KEY=your-key vendor/bin/pest tests/Feature/FixtureRecordingTest.php