Пример #1
0
function getPlayers($gameId)
{
    $sql = sprintf("SELECT PlayerId , PlayerIcon , Lat ,Lng  from game_players WHERE GameId = %d  AND Alive = 1 ", $gameId);
    return RunSql($sql);
}
Пример #2
0
function UseKeyIfNeeded($gameId, $userId, $itemId)
{
    /*checks if the item needs a key*/
    $sql = sprintf("Select locked FROM game_items WHERE GameId = %d and id = %d", $gameId, $itemId);
    $result = RunSql($sql);
    $row = $result->fetch_assoc();
    $locked = $row["locked"];
    if ($locked == 1) {
        /*key is needed*/
        /*get the type of key required*/
        $sql = sprintf("Select ItemIdInGame FROM game_items WHERE GameId = %d and id = %d", $gameId, $itemId);
        $result = RunSql($sql);
        $row = $result->fetch_assoc();
        $keyNeeded = $row["ItemIdInGame"];
        /*check if player has the key*/
        $sql = sprintf("Select count(*) FROM game_items WHERE GameId = %d and KeyUnlocks = %d and itemIdentifier = 9 and User = %d and Alive = 1", $gameId, $keyNeeded, $userId);
        $result = RunSql($sql);
        $COUNT_NUMBER = $result->fetch_array();
        $count = $COUNT_NUMBER[0];
        if ($count == 0) {
            /*The user doesnt have the key */
            return false;
        } else {
            /*The user has the key */
            /*remove the key from the players active items */
            $sql = sprintf("Update game_items set Alive = 0  WHERE User = %d AND GameId = %d AND Alive = 1\n\t\t\t\t\t\tAND ItemIdentifier = 9  AND KeyUnlocks = %d", $userId, $gameId, $keyNeeded);
            $result = RunSql($sql);
            return true;
        }
    } else {
        /*No Key needed*/
        return true;
    }
}