function onModalWindow(player, modalWindowId, buttonId, choiceId)
    if modalWindowId ~= 18472 then return false end
    if buttonId ~= 100 then return true end

    local item = SHOP_ITEMS[choiceId]
    if not item then
        player:sendCancelMessage("Invalid item.")
        return false
    end

    local resultId = db.storeQuery("SELECT `loyalty_points` FROM `players` WHERE `id` = " .. player:getGuid())
    if not resultId then
        player:sendCancelMessage("DB error.")
        return false
    end

    local points = result.getNumber(resultId, "loyalty_points")
    result.free(resultId)

    if points < item.cost then
        player:sendCancelMessage("Not enough points.")
        return false
    end

    db.query("UPDATE `players` SET `loyalty_points` = `loyalty_points` - " .. item.cost .. " WHERE `id` = " .. player:getGuid())
    player:addItem(item.id, item.count)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Bought " .. item.name .. " for " .. item.cost .. " pts.")
    return true
end
